Create Bucket

This commit is contained in:
Mel O'Hagan 2022-08-30 19:17:10 +01:00
parent 3443e2cd48
commit 088cf26b46
3 changed files with 49 additions and 41 deletions

View File

@ -37,6 +37,13 @@ module AwsMock {
Contents: {},
})
)
// @ts-ignore
this.createBucket = jest.fn(
response({
Contents: {},
})
)
}
aws.DynamoDB = { DocumentClient }

View File

@ -131,22 +131,10 @@ module S3Module {
"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 {
@ -165,33 +153,33 @@ module S3Module {
}
async create(query: {
bucket: string,
location: string,
grantFullControl: string,
grantRead: string,
grantReadAcp: string,
grantWrite: string,
grantWriteAcp: string,
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({
acl: string
}
}) {
let params: any = {
Bucket: query.bucket,
// ACL: query.extra?.acl,
CreateBucketConfiguration: {
LocationConstraint: query.location
},
ACL: query.extra?.acl,
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
}
if (query.location) {
params["CreateBucketConfiguration"] = {
LocationConstraint: query.location,
}
}
const response = await this.client.createBucket(params).promise()
return response
}
async read(query: {

View File

@ -41,10 +41,10 @@ describe("S3 Integration", () => {
grantReadAcp: "her",
grantWrite: "she",
grantWriteAcp: "he",
objectLockEnabledForBucket: true
}, {
acl: "private",
objectOwnership: "BucketOwnerPreferred"
objectLockEnabledForBucket: true,
extra: {
acl: "private"
}
})
expect(config.integration.client.createBucket).toHaveBeenCalledWith({
Bucket: "test",
@ -53,12 +53,25 @@ describe("S3 Integration", () => {
},
GrantFullControl: "me",
GrantRead: "him",
GrantReadAcp: "her",
GrantReadACP: "her",
GrantWrite: "she",
GrantWriteAcp: "he",
ObjectLockEnabledForBucket: true,
GrantWriteACP: "he",
ACL: "private",
ObjectOwnership: "BucketOwnerPreferred"
})
})
it("does not add undefined location constraint when calling the create method", async () => {
await config.integration.create({
bucket: "test"
})
expect(config.integration.client.createBucket).toHaveBeenCalledWith({
Bucket: "test",
GrantFullControl: undefined,
GrantRead: undefined,
GrantReadACP: undefined,
GrantWrite: undefined,
GrantWriteACP: undefined,
ACL: undefined,
})
})
})