Skip to content

Commit

Permalink
[TASK] check global env variables not only .env file (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh committed Jan 6, 2023
1 parent f6a79f0 commit f4c0dc1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/hubspot/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f4c0dc1

Please sign in to comment.