From 9b59b47d9e0140878fcf649643c47e2066257c27 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 17 Feb 2021 13:40:14 +0000 Subject: [PATCH] Fixing issue #1050 - two issues found, one with running automations in self host throwing an error when trying to access cloud resources (Dynamo) and secondly the worker pool does not have access to resources in the main server instance, therefore need to re-init when running an external action (get manifest, to download the package). --- packages/server/src/api/controllers/hosting.js | 1 - packages/server/src/automations/actions.js | 6 ++++++ packages/server/src/automations/index.js | 2 +- packages/server/src/utilities/usageQuota.js | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/hosting.js b/packages/server/src/api/controllers/hosting.js index 280d24d378..1d1884eb52 100644 --- a/packages/server/src/api/controllers/hosting.js +++ b/packages/server/src/api/controllers/hosting.js @@ -14,7 +14,6 @@ exports.fetchInfo = async ctx => { } exports.save = async ctx => { - console.trace("DID A SAVE!") const db = new CouchDB(BUILDER_CONFIG_DB) const { type } = ctx.request.body if (type === HostingTypes.CLOUD && ctx.request.body._rev) { diff --git a/packages/server/src/automations/actions.js b/packages/server/src/automations/actions.js index 4c282b1aea..ea88c2d1d6 100644 --- a/packages/server/src/automations/actions.js +++ b/packages/server/src/automations/actions.js @@ -53,6 +53,10 @@ module.exports.getAction = async function(actionName) { if (BUILTIN_ACTIONS[actionName] != null) { return BUILTIN_ACTIONS[actionName] } + // worker pools means that a worker may not have manifest + if (env.CLOUD && MANIFEST == null) { + MANIFEST = await module.exports.init() + } // env setup to get async packages if (!MANIFEST || !MANIFEST.packages || !MANIFEST.packages[actionName]) { return null @@ -86,8 +90,10 @@ module.exports.init = async function() { ? Object.assign(MANIFEST.packages, BUILTIN_DEFINITIONS) : BUILTIN_DEFINITIONS } catch (err) { + console.error(err) Sentry.captureException(err) } + return MANIFEST } module.exports.DEFINITIONS = BUILTIN_DEFINITIONS diff --git a/packages/server/src/automations/index.js b/packages/server/src/automations/index.js index 9332e5d449..a983495fb5 100644 --- a/packages/server/src/automations/index.js +++ b/packages/server/src/automations/index.js @@ -34,7 +34,7 @@ module.exports.init = function() { actions.init().then(() => { triggers.automationQueue.process(async job => { try { - if (env.CLOUD && job.data.automation) { + if (env.CLOUD && job.data.automation && !env.SELF_HOSTED) { job.data.automation.apiKey = await updateQuota(job.data.automation) } if (env.BUDIBASE_ENVIRONMENT === "PRODUCTION") { diff --git a/packages/server/src/utilities/usageQuota.js b/packages/server/src/utilities/usageQuota.js index 81320eaec0..d809d9e673 100644 --- a/packages/server/src/utilities/usageQuota.js +++ b/packages/server/src/utilities/usageQuota.js @@ -50,6 +50,9 @@ exports.Properties = { } exports.getAPIKey = async appId => { + if (env.SELF_HOSTED) { + return { apiKey: null } + } return apiKeyTable.get({ primary: appId }) } @@ -63,7 +66,7 @@ exports.getAPIKey = async appId => { */ exports.update = async (apiKey, property, usage) => { // don't try validate in builder - if (!env.CLOUD) { + if (!env.CLOUD || env.SELF_HOSTED) { return } try {