From ed27b71103aa55ba9b87836207b092d57934d47c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 23 Sep 2022 16:30:45 +0100 Subject: [PATCH] Adding tenancy awareness for plugin bucket. --- packages/backend-core/src/context/index.ts | 4 +++ packages/backend-core/src/environment.ts | 25 ++++++++++++++----- .../backend-core/src/objectStore/utils.js | 5 ++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/context/index.ts b/packages/backend-core/src/context/index.ts index 8e3cf8a0a2..7cc90e3c67 100644 --- a/packages/backend-core/src/context/index.ts +++ b/packages/backend-core/src/context/index.ts @@ -226,6 +226,10 @@ export const getAppId = () => { } } +export const isTenancyEnabled = () => { + return env.MULTI_TENANCY +} + /** * Opens the app database based on whatever the request * contained, dev or prod. diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts index be1e1eacfc..6e2ac94be9 100644 --- a/packages/backend-core/src/environment.ts +++ b/packages/backend-core/src/environment.ts @@ -16,6 +16,15 @@ if (!LOADED && isDev() && !isTest()) { LOADED = true } +const DefaultBucketName = { + BACKUPS: "backups", + APPS: "prod-budi-app-assets", + TEMPLATES: "templates", + GLOBAL: "global", + CLOUD: "prod-budi-tenant-uploads", + PLUGINS: "plugins", +} + const env = { isTest, isDev, @@ -45,13 +54,17 @@ const env = { POSTHOG_TOKEN: process.env.POSTHOG_TOKEN, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS, - BACKUPS_BUCKET_NAME: process.env.BACKUPS_BUCKET_NAME || "backups", - APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || "prod-budi-app-assets", - TEMPLATES_BUCKET_NAME: process.env.TEMPLATES_BUCKET_NAME || "templates", - GLOBAL_BUCKET_NAME: process.env.GLOBAL_BUCKET_NAME || "global", + BACKUPS_BUCKET_NAME: + process.env.BACKUPS_BUCKET_NAME || DefaultBucketName.BACKUPS, + APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || DefaultBucketName.APPS, + TEMPLATES_BUCKET_NAME: + process.env.TEMPLATES_BUCKET_NAME || DefaultBucketName.TEMPLATES, + GLOBAL_BUCKET_NAME: + process.env.GLOBAL_BUCKET_NAME || DefaultBucketName.GLOBAL, GLOBAL_CLOUD_BUCKET_NAME: - process.env.GLOBAL_CLOUD_BUCKET_NAME || "prod-budi-tenant-uploads", - PLUGIN_BUCKET_NAME: process.env.PLUGIN_BUCKET_NAME || "plugins", + process.env.GLOBAL_CLOUD_BUCKET_NAME || DefaultBucketName.CLOUD, + PLUGIN_BUCKET_NAME: + process.env.PLUGIN_BUCKET_NAME || DefaultBucketName.PLUGINS, USE_COUCH: process.env.USE_COUCH || true, DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE, DEFAULT_LICENSE: process.env.DEFAULT_LICENSE, diff --git a/packages/backend-core/src/objectStore/utils.js b/packages/backend-core/src/objectStore/utils.js index acc1b9904e..9cf4f5f70e 100644 --- a/packages/backend-core/src/objectStore/utils.js +++ b/packages/backend-core/src/objectStore/utils.js @@ -2,6 +2,11 @@ const { join } = require("path") const { tmpdir } = require("os") const env = require("../environment") +/**************************************************** + * NOTE: When adding a new bucket - name * + * sure that S3 usages (like budibase-infra) * + * have been updated to have a unique bucket name. * + ****************************************************/ exports.ObjectStoreBuckets = { BACKUPS: env.BACKUPS_BUCKET_NAME, APPS: env.APPS_BUCKET_NAME,