From e2033898b0d7e23ce72b6ca5b84aa544a8b3445e Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 30 Aug 2022 11:17:11 +0100 Subject: [PATCH] Add additional params to listObjects --- packages/server/src/integrations/s3.ts | 34 ++++++++++++++++--- .../server/src/integrations/tests/s3.spec.js | 12 +++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index e8da696424..fabb6daa3d 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -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 diff --git a/packages/server/src/integrations/tests/s3.spec.js b/packages/server/src/integrations/tests/s3.spec.js index 7ac403dbd4..a655112973 100644 --- a/packages/server/src/integrations/tests/s3.spec.js +++ b/packages/server/src/integrations/tests/s3.spec.js @@ -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/" }) }) }) \ No newline at end of file