UNPKG

ask-cli

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

114 lines (113 loc) 3.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const client_s3_1 = require("@aws-sdk/client-s3"); const constants_1 = __importDefault(require("../../utils/constants")); const abstract_aws_client_1 = __importDefault(require("./abstract-aws-client")); /** * Class for S3 client */ class S3Client extends abstract_aws_client_1.default { /** * Constructor * @param configuration aws client config */ constructor(configuration) { super(configuration); this.client = new client_s3_1.S3Client({ credentials: this.credentials, region: this.region, }); } /** * Enables s3 bucket version * @param bucketName bucket name */ enableBucketVersioning(bucketName) { const command = new client_s3_1.PutBucketVersioningCommand({ Bucket: bucketName, VersioningConfiguration: { MFADelete: "Disabled", Status: "Enabled", }, }); return this.client.send(command); } /** * Checks whether the bucket versioning is set or not * @param bucketName bucket name */ getBucketVersioning(bucketName) { const command = new client_s3_1.GetBucketVersioningCommand({ Bucket: bucketName, }); return this.client.send(command); } /** * Creates s3 bucket * @param bucketName bucket name * @param region aws region code */ createBucket(bucketName, region) { const command = new client_s3_1.CreateBucketCommand({ Bucket: bucketName, // add LocationConstraint bukcet config if provided region not default location (us-east-1) ...(region && region !== constants_1.default.CONFIGURATION.S3.DEFAULT_LOCATION && { CreateBucketConfiguration: { LocationConstraint: region, }, }), }); return this.client.send(command); } /** * Checks if s3 bucket exists * @param bucketName bucket name */ bucketExits(bucketName) { const command = new client_s3_1.HeadBucketCommand({ Bucket: bucketName, }); return this.client .send(command) .then(() => true) .catch((err) => { var _a; if (((_a = err.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 404) return false; throw err; }); } /** * Uploads object to aws s3 bucket * @param bucket bucket name * @param key the name of uploaded content on s3 bucket * @param body the content want to upload to s3 bucket */ putObject(bucket, key, body) { const command = new client_s3_1.PutObjectCommand({ Bucket: bucket, Key: key, Body: body, }); return this.client.send(command); } /** * Waits for s3 bucket exists * @param bucketName bucket name */ waitForBucketExists(bucketName) { const params = { client: this.client, maxWaitTime: constants_1.default.CONFIGURATION.S3.MAX_WAIT_TIME, }; const input = { Bucket: bucketName, }; return (0, client_s3_1.waitUntilBucketExists)(params, input); } } exports.default = S3Client;