UNPKG

3.1 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8function _bluebirdLst() {
9 const data = require("bluebird-lst");
10
11 _bluebirdLst = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _s() {
19 const data = _interopRequireDefault(require("aws-sdk/clients/s3"));
20
21 _s = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _builderUtil() {
29 const data = require("builder-util");
30
31 _builderUtil = function () {
32 return data;
33 };
34
35 return data;
36}
37
38function _BaseS3Publisher() {
39 const data = require("./BaseS3Publisher");
40
41 _BaseS3Publisher = function () {
42 return data;
43 };
44
45 return data;
46}
47
48function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
50class S3Publisher extends _BaseS3Publisher().BaseS3Publisher {
51 constructor(context, info) {
52 super(context, info);
53 this.info = info;
54 this.providerName = "S3";
55 }
56
57 static checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot) {
58 return (0, _bluebirdLst().coroutine)(function* () {
59 const bucket = options.bucket;
60
61 if (bucket == null) {
62 throw new (_builderUtil().InvalidConfigurationError)(`Please specify "bucket" for "s3" publish provider`);
63 }
64
65 if (options.endpoint == null && bucket.includes(".") && options.region == null) {
66 // on dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
67 const s3 = new (_s().default)({
68 signatureVersion: "v4"
69 });
70
71 try {
72 options.region = (yield s3.getBucketLocation({
73 Bucket: bucket
74 }).promise()).LocationConstraint;
75 } catch (e) {
76 if (errorIfCannot) {
77 throw e;
78 } else {
79 _builderUtil().log.warn(`cannot compute region for bucket (required because on dotted bucket names, we need to use a path-based endpoint URL): ${e}`);
80 }
81 }
82 }
83
84 if (options.channel == null && channelFromAppVersion != null) {
85 options.channel = channelFromAppVersion;
86 }
87 })();
88 }
89
90 createClientConfiguration() {
91 const configuration = super.createClientConfiguration();
92 const endpoint = this.info.endpoint;
93
94 if (endpoint != null) {
95 configuration.endpoint = endpoint;
96 configuration.s3ForcePathStyle = true;
97 }
98
99 return configuration;
100 }
101
102 getBucketName() {
103 return this.info.bucket;
104 }
105
106 configureS3Options(s3Options) {
107 super.configureS3Options(s3Options);
108
109 if (this.info.storageClass != null) {
110 s3Options.StorageClass = this.info.storageClass;
111 }
112
113 if (this.info.encryption != null) {
114 s3Options.ServerSideEncryption = this.info.encryption;
115 }
116 }
117
118 toString() {
119 const result = super.toString();
120 const endpoint = this.info.endpoint;
121
122 if (endpoint != null) {
123 return result.substring(0, result.length - 1) + `, endpoint: ${endpoint})`;
124 }
125
126 return result;
127 }
128
129} exports.default = S3Publisher;
130//# sourceMappingURL=s3Publisher.js.map
\No newline at end of file