Skip to content

Commit

Permalink
use local-dev-lib for updateConfigWithPersonalAccessKey
Browse files Browse the repository at this point in the history
  • Loading branch information
camden11 committed Dec 7, 2023
1 parent 00c8e4b commit dc2ba97
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
13 changes: 11 additions & 2 deletions packages/cli/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const { i18n } = require('../lib/lang');
const {
updateConfigWithPersonalAccessKey,
} = require('@hubspot/cli-lib/personalAccessKey');
} = require('@hubspot/local-dev-lib/personalAccessKey');
const {
updateAccountConfig,
writeConfig,
Expand Down Expand Up @@ -40,6 +40,7 @@ const { trackAuthAction, trackCommandUsage } = require('../lib/usageTracking');
const { authenticateWithOauth } = require('../lib/oauth');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { uiFeatureHighlight } = require('../lib/ui');
const { logErrorInstance } = require('../lib/errorHandlers/standardErrors');

const i18nKey = 'cli.commands.auth';

Expand Down Expand Up @@ -97,7 +98,15 @@ exports.handler = async options => {
break;
case PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
configData = await personalAccessKeyPrompt({ env, account });
updatedConfig = await updateConfigWithPersonalAccessKey(configData);

try {
updatedConfig = await updateConfigWithPersonalAccessKey(
configData.personalAccesskey,
env
);
} catch (e) {
logErrorInstance(e);
}

if (!updatedConfig) {
break;
Expand Down
22 changes: 15 additions & 7 deletions packages/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { i18n } = require('../lib/lang');
const { logger } = require('@hubspot/cli-lib/logger');
const {
updateConfigWithPersonalAccessKey,
} = require('@hubspot/cli-lib/personalAccessKey');
} = require('@hubspot/local-dev-lib/personalAccessKey');
const { getCwd } = require('@hubspot/local-dev-lib/path');
const { trackCommandUsage, trackAuthAction } = require('../lib/usageTracking');
const { setLogLevel, addTestingOptions } = require('../lib/commonOpts');
Expand All @@ -51,14 +51,22 @@ const TRACKING_STATUS = {
};

const personalAccessKeyConfigCreationFlow = async (env, account) => {
const configData = await personalAccessKeyPrompt({ env, account });
const { personalAccessKey } = await personalAccessKeyPrompt({ env, account });
const { name } = await enterAccountNamePrompt();
const accountConfig = {
...configData,
name,
};

return updateConfigWithPersonalAccessKey(accountConfig, true);
let updatedConfig;

try {
updatedConfig = updateConfigWithPersonalAccessKey(
personalAccessKey,
env,
name,
true
);
} catch (e) {
logErrorInstance(e);
}
return updatedConfig;
};

const oauthConfigCreationFlow = async env => {
Expand Down
23 changes: 18 additions & 5 deletions packages/cli/lib/sandboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { handleExit, handleKeypress } = require('./process');
const { logger } = require('@hubspot/cli-lib/logger');
const {
updateConfigWithPersonalAccessKey,
} = require('@hubspot/cli-lib/personalAccessKey');
} = require('@hubspot/local-dev-lib/personalAccessKey');
const { EXIT_CODES } = require('./enums/exitCodes');
const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt');
const {
Expand All @@ -25,6 +25,7 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const {
personalAccessKeyPrompt,
} = require('./prompts/personalAccessKeyPrompt');
const { logErrorInstance } = require('./errorHandlers/standardErrors');

const STANDARD_SANDBOX = 'standard';
const DEVELOPER_SANDBOX = 'developer';
Expand Down Expand Up @@ -234,14 +235,26 @@ const validateSandboxUsageLimits = async (accountConfig, sandboxType, env) => {
* @returns {String} validName saved into config
*/
const saveSandboxToConfig = async (env, result, force = false) => {
let configData = { env, personalAccessKey: result.personalAccessKey };
if (!result.personalAccessKey) {
configData = await personalAccessKeyPrompt({
let personalAccessKey = result.personalAccessKey;
if (personalAccessKey) {
const configData = await personalAccessKeyPrompt({
env,
account: result.sandbox.sandboxHubId,
});
personalAccessKey = configData.personalAccessKey;
}
const updatedConfig = await updateConfigWithPersonalAccessKey(configData);

let updatedConfig;

try {
updatedConfig = await updateConfigWithPersonalAccessKey(
personalAccessKey,
env
);
} catch (e) {
logErrorInstance(e);
}

if (!updatedConfig) {
throw new Error('Failed to update config with personal access key.');
}
Expand Down

0 comments on commit dc2ba97

Please sign in to comment.