s3Publisher.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const builder_util_1 = require("builder-util");
  4. const BaseS3Publisher_1 = require("./BaseS3Publisher");
  5. class S3Publisher extends BaseS3Publisher_1.BaseS3Publisher {
  6. constructor(context, info) {
  7. super(context, info);
  8. this.info = info;
  9. this.providerName = "s3";
  10. }
  11. static async checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot) {
  12. const bucket = options.bucket;
  13. if (bucket == null) {
  14. throw new builder_util_1.InvalidConfigurationError(`Please specify "bucket" for "s3" publish provider`);
  15. }
  16. if (options.endpoint == null && bucket.includes(".") && options.region == null) {
  17. // on dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
  18. try {
  19. options.region = await (0, builder_util_1.executeAppBuilder)(["get-bucket-location", "--bucket", bucket]);
  20. }
  21. catch (e) {
  22. if (errorIfCannot) {
  23. throw e;
  24. }
  25. else {
  26. builder_util_1.log.warn(`cannot compute region for bucket (required because on dotted bucket names, we need to use a path-based endpoint URL): ${e}`);
  27. }
  28. }
  29. }
  30. if (options.channel == null && channelFromAppVersion != null) {
  31. options.channel = channelFromAppVersion;
  32. }
  33. if (options.endpoint != null && options.endpoint.endsWith("/")) {
  34. ;
  35. options.endpoint = options.endpoint.slice(0, -1);
  36. }
  37. }
  38. getBucketName() {
  39. return this.info.bucket;
  40. }
  41. configureS3Options(args) {
  42. super.configureS3Options(args);
  43. if (this.info.endpoint != null) {
  44. args.push("--endpoint", this.info.endpoint);
  45. }
  46. if (this.info.region != null) {
  47. args.push("--region", this.info.region);
  48. }
  49. if (this.info.storageClass != null) {
  50. args.push("--storageClass", this.info.storageClass);
  51. }
  52. if (this.info.encryption != null) {
  53. args.push("--encryption", this.info.encryption);
  54. }
  55. }
  56. toString() {
  57. const result = super.toString();
  58. const endpoint = this.info.endpoint;
  59. if (endpoint != null) {
  60. return result.substring(0, result.length - 1) + `, endpoint: ${endpoint})`;
  61. }
  62. return result;
  63. }
  64. }
  65. exports.default = S3Publisher;
  66. //# sourceMappingURL=s3Publisher.js.map