Skip to content

Commit 4268f5c

Browse files
fix: accessTokenForPersonalAccessKey when using env config (#363)
* Fix accessTokenForPersonalAccessKey when using env config * go with option 1 * fix condition and add test
1 parent 8369dd7 commit 4268f5c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config/__tests__/config.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,18 @@ describe('config/index', () => {
441441

442442
expect(() => updateConfigAccount(OAUTH_ACCOUNT)).toThrow();
443443
});
444+
445+
it('skips updating config file when using environment variables', () => {
446+
mockConfig();
447+
process.env[ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG] =
448+
'true';
449+
450+
const newAccount = { ...PAK_ACCOUNT, name: 'new-name' };
451+
452+
updateConfigAccount(newAccount);
453+
454+
expect(mockFs.writeFileSync).not.toHaveBeenCalled();
455+
});
444456
});
445457

446458
describe('setConfigAccountAsDefault()', () => {

config/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
GLOBAL_CONFIG_PATH,
88
HUBSPOT_CONFIG_OPERATIONS,
99
MIN_HTTP_TIMEOUT,
10+
ENVIRONMENT_VARIABLES,
1011
} from '../constants/config';
1112
import { HubSpotConfigAccount } from '../types/Accounts';
1213
import {
@@ -390,6 +391,10 @@ export function addConfigAccount(accountToAdd: HubSpotConfigAccount): void {
390391
export function updateConfigAccount(
391392
updatedAccount: HubSpotConfigAccount
392393
): void {
394+
// Skip updating the config file if we're using environment variables
395+
if (process.env[ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG]) {
396+
return;
397+
}
393398
if (!validateConfigAccount(updatedAccount)) {
394399
throw new HubSpotConfigError(
395400
i18n('config.updateConfigAccount.invalidAccount', {

0 commit comments

Comments
 (0)