| 26 | const uuid = require('uuid'); |
| 27 | |
| 28 | class BucketManager { |
| 29 | constructor() { |
| 30 | this.client = new StorageTransferServiceClient(); |
| 31 | this.storage = new Storage(); |
| 32 | |
| 33 | /** |
| 34 | * The GCP Project ID. Cached after initial request |
| 35 | */ |
| 36 | this._cachedProjectId = ''; |
| 37 | |
| 38 | /** |
| 39 | * @type {Bucket[]} |
| 40 | */ |
| 41 | this.gcsBuckets = []; |
| 42 | /** |
| 43 | * @type {string[]} |
| 44 | */ |
| 45 | this.blobStorageContainers = []; |
| 46 | /** |
| 47 | * @type {string[]} |
| 48 | */ |
| 49 | this.s3Buckets = []; |
| 50 | } |
| 51 | |
| 52 | setupBlobStorageFromConnectionString(connectionString = '') { |
| 53 | this.blobStorage = |
| 54 | AzureStorageBlob.BlobServiceClient.fromConnectionString(connectionString); |
| 55 | } |
| 56 | |
| 57 | setupS3(options = {}) { |
| 58 | this.s3 = new AWS.S3({apiVersion: '2006-03-01', ...options}); |
| 59 | } |
| 60 | |
| 61 | async getProjectId() { |
| 62 | if (!this._cachedProjectId) { |
| 63 | this._cachedProjectId = await this.storage.getProjectId(); |
| 64 | } |
| 65 | |
| 66 | return this._cachedProjectId; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Generates a unique name for GCS and S3 buckets. |
| 71 | * |
| 72 | * @returns {string} Name of bucket |
| 73 | */ |
| 74 | static generateBucketName() { |
| 75 | return `nodejs-sts-samples-${uuid.v4()}`; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Configures permissions for STS to read/write to the bucket. |
| 80 | * |
| 81 | * @param {Bucket} bucket |
| 82 | * @param {number} waitForPropagation the time in milliseconds, if any, to wait |
| 83 | * for the policy to propigate (default 7 minutes). See for details: |
| 84 | * - https://cloud.google.com/iam/docs/faq#access_revoke |
| 85 | * - https://cloud.google.com/iam/docs/policies#structure |
nothing calls this directly
no outgoing calls
no test coverage detected