diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index f24fe92f6b..67568436c3 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -48,6 +48,41 @@ module S3Module { }, }, query: { + create: { + type: QueryType.FIELDS, + fields: { + bucket: { + display: "New Bucket", + type: DatasourceFieldType.STRING, + required: true, + }, + location: { + required: true, + default: "us-east-1", + type: DatasourceFieldType.STRING, + }, + grantFullControl: { + display: "Grant full control", + type: DatasourceFieldType.STRING, + }, + grantRead: { + display: "Grant read", + type: DatasourceFieldType.STRING, + }, + grantReadAcp: { + display: "Grant read ACP", + type: DatasourceFieldType.STRING, + }, + grantWrite: { + display: "Grant write", + type: DatasourceFieldType.STRING, + }, + grantWriteAcp: { + display: "Grant write ACP", + type: DatasourceFieldType.STRING, + }, + }, + }, read: { type: QueryType.FIELDS, fields: { @@ -85,6 +120,33 @@ module S3Module { }, }, }, + extra: { + acl: { + required: false, + displayName: "ACL", + type: DatasourceFieldType.LIST, + data: { + create: [ + "private", + "public-read", + "public-read-write", + "authenticated-read", + ] + } + }, + objectOwnership: { + required: false, + displayName: "Object ownership", + type: DatasourceFieldType.LIST, + data: { + create: [ + "BucketOwnerPreferred", + "ObjectWriter", + "BucketOwnerEnforced", + ], + }, + }, + } } class S3Integration implements IntegrationBase { @@ -102,6 +164,36 @@ module S3Module { this.client = new AWS.S3(this.config) } + async create(query: { + bucket: string, + location: string, + grantFullControl: string, + grantRead: string, + grantReadAcp: string, + grantWrite: string, + grantWriteAcp: string, + extra: { + acl: string, + objectOwnership: string, + }}) { + const response = await this.client.createBucket({ + Bucket: query.bucket, + // ACL: query.extra?.acl, + CreateBucketConfiguration: { + LocationConstraint: query.location + }, + GrantFullControl: query.grantFullControl, + GrantRead: query.grantRead, + GrantReadACP: query.grantReadAcp, + GrantWrite: query.grantWrite, + GrantWriteACP: query.grantWriteAcp, + }, (err: any) => { + console.log("ERR ", err) + }) + .promise() + return response.Contents + } + async read(query: { bucket: string delimiter: string diff --git a/packages/server/src/integrations/tests/s3.spec.js b/packages/server/src/integrations/tests/s3.spec.js index a655112973..48e7221ef8 100644 --- a/packages/server/src/integrations/tests/s3.spec.js +++ b/packages/server/src/integrations/tests/s3.spec.js @@ -16,7 +16,7 @@ describe("S3 Integration", () => { }) it("calls the read method with the correct params", async () => { - const response = await config.integration.read({ + await config.integration.read({ bucket: "test", delimiter: "/", marker: "file.txt", @@ -31,4 +31,34 @@ describe("S3 Integration", () => { Prefix: "directory/" }) }) + + it("calls the create method with the correct params", async () => { + await config.integration.create({ + bucket: "test", + location: "af-south-1", + grantFullControl: "me", + grantRead: "him", + grantReadAcp: "her", + grantWrite: "she", + grantWriteAcp: "he", + objectLockEnabledForBucket: true + }, { + acl: "private", + objectOwnership: "BucketOwnerPreferred" + }) + expect(config.integration.client.createBucket).toHaveBeenCalledWith({ + Bucket: "test", + CreateBucketConfiguration: { + LocationConstraint: "af-south-1" + }, + GrantFullControl: "me", + GrantRead: "him", + GrantReadAcp: "her", + GrantWrite: "she", + GrantWriteAcp: "he", + ObjectLockEnabledForBucket: true, + ACL: "private", + ObjectOwnership: "BucketOwnerPreferred" + }) + }) }) \ No newline at end of file