1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00

Add additional params to listObjects

This commit is contained in:
Mel O'Hagan 2022-08-30 11:17:11 +01:00
parent 80c69e0989
commit 3c50b24106
2 changed files with 39 additions and 7 deletions

View file

@ -1,4 +1,4 @@
import { Integration, QueryType, IntegrationBase } from "@budibase/types"
import { Integration, QueryType, IntegrationBase, DatasourceFieldType } from "@budibase/types"
module S3Module {
const AWS = require("aws-sdk")
@ -46,12 +46,25 @@ module S3Module {
type: QueryType.FIELDS,
fields: {
bucket: {
type: "string",
type: DatasourceFieldType.STRING,
required: true,
},
delimiter: {
type: DatasourceFieldType.STRING,
},
marker: {
type: DatasourceFieldType.STRING,
},
maxKeys: {
type: DatasourceFieldType.NUMBER,
display: "Max Keys",
},
prefix: {
type: DatasourceFieldType.STRING,
},
},
},
},
}
}
}
class S3Integration implements IntegrationBase {
@ -69,10 +82,21 @@ module S3Module {
this.client = new AWS.S3(this.config)
}
async read(query: { bucket: string }) {
async read(query: {
bucket: string,
delimiter: string,
expectedBucketOwner: string,
marker: string,
maxKeys: number,
prefix: string,
}) {
const response = await this.client
.listObjects({
Bucket: query.bucket,
Delimiter: query.delimiter,
Marker: query.marker,
MaxKeys: query.maxKeys,
Prefix: query.prefix,
})
.promise()
return response.Contents

View file

@ -17,10 +17,18 @@ describe("S3 Integration", () => {
it("calls the read method with the correct params", async () => {
const response = await config.integration.read({
bucket: "test"
bucket: "test",
delimiter: "/",
marker: "file.txt",
maxKeys: 999,
prefix: "directory/",
})
expect(config.integration.client.listObjects).toHaveBeenCalledWith({
Bucket: "test"
Bucket: "test",
Delimiter: "/",
Marker: "file.txt",
MaxKeys: 999,
Prefix: "directory/"
})
})
})