From dbbeccda61b8cc2afc1c762421a3046e7f106b33 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 15 Jun 2022 12:42:41 +0100 Subject: [PATCH 1/5] Use s3 region from datasource config --- packages/server/src/api/controllers/static/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 2880e453ca..c66db08983 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -17,7 +17,6 @@ const { attachmentsRelativeURL } = require("../../../utilities") const { DocumentTypes } = require("../../../db/utils") const { getAppDB, getAppId } = require("@budibase/backend-core/context") const AWS = require("aws-sdk") -const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1" async function prepareUpload({ s3Key, bucket, metadata, file }) { const response = await upload({ @@ -115,6 +114,7 @@ exports.getSignedUploadURL = async function (ctx) { // Determine type of datasource and generate signed URL let signedUrl let publicUrl + const AWS_REGION = datasource?.config?.region ?? "eu-west-1" if (datasource.source === "S3") { const { bucket, key } = ctx.request.body || {} if (!bucket || !key) { From cf604fdefd4bdba7805aa516d110e87d0d0259d5 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 15 Jun 2022 13:16:30 +0100 Subject: [PATCH 2/5] Check for blank string --- packages/server/src/api/controllers/static/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index c66db08983..5b47b864fd 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -114,7 +114,10 @@ exports.getSignedUploadURL = async function (ctx) { // Determine type of datasource and generate signed URL let signedUrl let publicUrl - const AWS_REGION = datasource?.config?.region ?? "eu-west-1" + const AWS_REGION = + datasource?.config?.region?.length > 0 + ? datasource?.config?.region + : "eu-west-1" if (datasource.source === "S3") { const { bucket, key } = ctx.request.body || {} if (!bucket || !key) { From b0a3abc308b2d992fbd5d4ef59e3fe854e122f78 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 15 Jun 2022 16:27:07 +0100 Subject: [PATCH 3/5] No default aws region --- packages/server/src/api/controllers/static/index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 5b47b864fd..529686f36d 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -114,10 +114,7 @@ exports.getSignedUploadURL = async function (ctx) { // Determine type of datasource and generate signed URL let signedUrl let publicUrl - const AWS_REGION = - datasource?.config?.region?.length > 0 - ? datasource?.config?.region - : "eu-west-1" + const awsRegion = datasource?.config?.region if (datasource.source === "S3") { const { bucket, key } = ctx.request.body || {} if (!bucket || !key) { @@ -126,7 +123,7 @@ exports.getSignedUploadURL = async function (ctx) { } try { const s3 = new AWS.S3({ - region: AWS_REGION, + region: awsRegion, accessKeyId: datasource?.config?.accessKeyId, secretAccessKey: datasource?.config?.secretAccessKey, apiVersion: "2006-03-01", @@ -134,7 +131,7 @@ exports.getSignedUploadURL = async function (ctx) { }) const params = { Bucket: bucket, Key: key } signedUrl = s3.getSignedUrl("putObject", params) - publicUrl = `https://${bucket}.s3.${AWS_REGION}.amazonaws.com/${key}` + publicUrl = `https://${bucket}.s3.${awsRegion}.amazonaws.com/${key}` } catch (error) { ctx.throw(400, error) } From b118833fda4d2f108ef8f90fcb2bc66609aa41df Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 15 Jun 2022 16:29:11 +0100 Subject: [PATCH 4/5] Default to eu-west-1 --- packages/server/src/api/controllers/static/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 529686f36d..af7f05e8af 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -114,7 +114,7 @@ exports.getSignedUploadURL = async function (ctx) { // Determine type of datasource and generate signed URL let signedUrl let publicUrl - const awsRegion = datasource?.config?.region + const awsRegion = datasource?.config?.region || "eu-west-1" if (datasource.source === "S3") { const { bucket, key } = ctx.request.body || {} if (!bucket || !key) { From 8f0c045a1148d9c8ae1b7b4b773bf9e1f58e9d81 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 16 Jun 2022 10:40:42 +0100 Subject: [PATCH 5/5] Bump timeout for migration test --- packages/server/src/migrations/tests/index.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index ca30fbca06..faaefe3d61 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -23,6 +23,8 @@ const clearMigrations = async () => { } } +jest.setTimeout(10000) + describe("migrations", () => { const config = new TestConfig()