From f4c0dc1e9340facb16c03af23669abf8cdca2a18 Mon Sep 17 00:00:00 2001 From: Dmytro Hrynevych <5150636+dmh@users.noreply.github.com> Date: Fri, 6 Jan 2023 13:11:12 +0200 Subject: [PATCH] [TASK] check global env variables not only .env file (#1) --- lib/hubspot/auth.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/hubspot/auth.js b/lib/hubspot/auth.js index 30af121..38eae02 100644 --- a/lib/hubspot/auth.js +++ b/lib/hubspot/auth.js @@ -72,6 +72,22 @@ async function checkAuthDataInDotEnv () { } } +/** + * @summary Check global env variables or .env file + * @description Check global env variables and run checkAuthDataInDotEnv() to check .env if no global HUBSPOT env variables are set + * @async + * @private + * @returns undefined + */ +async function checkEnv () { + if (process.env.HUBSPOT_PORTAL_ID && process.env.HUBSPOT_PERSONAL_ACCESS_KEY) { + hubSpotDefaultEnvAuthConfig = true + } else { + await addAuthDataTmplToDotEnv() + await checkAuthDataInDotEnv() + } +} + /** * @summary Show .env data setup instructions * @description Show .env data setup instructions in terminal with possibility to open a link and get personal-access-key @@ -305,7 +321,7 @@ async function loadAuthConfig (customAuthConfig) { if (customAuthConfig === 'defaultConfig') { const hubConfig = await config.getAndLoadConfigIfNeeded({ silenceErrors: false, useEnv: true }) await config.validateConfig() - await getAuthData(localEnv.parsed.HUBSPOT_PERSONAL_ACCESS_KEY) + await getAuthData(hubConfig.portals[0].personalAccessKey) return hubConfig // load HUBSPOT config based on Rusultify custom env variables @@ -333,8 +349,7 @@ async function loadAuthConfig (customAuthConfig) { */ async function getAuthConfig () { try { - await addAuthDataTmplToDotEnv() - await checkAuthDataInDotEnv() + await checkEnv() const authData = isCustomAuthConfig() return authData } catch (error) {