@itwin/object-storage-oss
Version:
Object storage implementation using OSS
122 lines • 4.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OssTransferConfigProvider = void 0;
const internal_1 = require("@itwin/object-storage-core/lib/common/internal");
const internal_2 = require("@itwin/object-storage-core/lib/server/internal");
const internal_3 = require("@itwin/object-storage-s3/lib/server/internal");
const common_1 = require("../common");
const internal_4 = require("./internal");
class OssTransferConfigProvider {
_config;
_client;
constructor(client, config) {
this._config = config;
this._client = client;
}
async getDownloadConfig(directory, expiry) {
const policy = {
Version: "1",
Statement: [
{
Effect: "Allow",
Action: ["oss:GetObject"],
Resource: [
`acs:oss:*:*:${this._config.bucket}/${(0, internal_1.buildObjectDirectoryString)(directory)}/*`,
],
},
],
};
const { Credentials } = await this._client.request("AssumeRole", {
RoleArn: this._config.roleArn,
RoleSessionName: (0, internal_2.getRandomString)(),
Policy: JSON.stringify(policy),
DurationSeconds: (0, internal_3.getExpiresInSeconds)(expiry),
}, {
method: "POST",
});
return {
authentication: {
accessKey: Credentials.AccessKeyId,
secretKey: Credentials.AccessKeySecret,
sessionToken: Credentials.SecurityToken,
},
expiration: new Date(Credentials.Expiration),
baseUrl: this._config.baseUrl,
region: this._config.region,
bucket: this._config.bucket,
storageType: common_1.Constants.storageType,
};
}
async getUploadConfig(directory, expiry) {
const policy = {
Version: "1",
Statement: [
{
Effect: "Allow",
Action: ["oss:PutObject"],
Resource: [
`acs:oss:*:*:${this._config.bucket}/${(0, internal_1.buildObjectDirectoryString)(directory)}/*`,
],
},
],
};
const { Credentials } = await this._client.request("AssumeRole", {
RoleArn: this._config.roleArn,
RoleSessionName: (0, internal_2.getRandomString)(),
Policy: JSON.stringify(policy),
DurationSeconds: (0, internal_3.getExpiresInSeconds)(expiry),
}, {
method: "POST",
});
return {
authentication: {
accessKey: Credentials.AccessKeyId,
secretKey: Credentials.AccessKeySecret,
sessionToken: Credentials.SecurityToken,
},
expiration: new Date(Credentials.Expiration),
baseUrl: this._config.baseUrl,
region: this._config.region,
bucket: this._config.bucket,
storageType: common_1.Constants.storageType,
};
}
async getDirectoryAccessConfig(directory, expiry) {
const actions = (0, internal_4.getActions)();
const policy = {
Version: "1",
Statement: [
{
Effect: "Allow",
Action: actions,
Resource: [
`acs:oss:*:*:${this._config.bucket}/${(0, internal_1.buildObjectDirectoryString)(directory)}/*`,
`acs:oss:*:*:${this._config.bucket}`,
],
},
],
};
const { Credentials } = await this._client.request("AssumeRole", {
RoleArn: this._config.roleArn,
RoleSessionName: (0, internal_2.getRandomString)(),
Policy: JSON.stringify(policy),
DurationSeconds: (0, internal_3.getExpiresInSeconds)(expiry),
}, {
method: "POST",
});
return {
authentication: {
accessKey: Credentials.AccessKeyId,
secretKey: Credentials.AccessKeySecret,
sessionToken: Credentials.SecurityToken,
},
expiration: new Date(Credentials.Expiration),
baseUrl: this._config.baseUrl,
region: this._config.region,
bucket: this._config.bucket,
storageType: common_1.Constants.storageType,
};
}
}
exports.OssTransferConfigProvider = OssTransferConfigProvider;
//# sourceMappingURL=OssTransferConfigProvider.js.map