Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] check global env variables not only .env file #1

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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