Skip to content

Commit

Permalink
Merge branch 'master' into br-ldl-api-deps-1
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenrodgers committed Jan 31, 2024
2 parents 1bf7a33 + 0ef5da3 commit 97c757f
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 30 deletions.
3 changes: 2 additions & 1 deletion packages/cli/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

const accountName = updatedConfig.name || validName;
const accountName =
(updatedConfig && updatedConfig.name) || validName || configData.name;

const setAsDefault = await setAsDefaultAccountPrompt(accountName);

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ en:
setupError: "Failed to setup local dev server: {{ message }}"
startError: "Failed to start local dev server: {{ message }}"
fileChangeError: "Failed to notify local dev server of file change: {{ message }}"
oauth:
logCallbacks:
init: "Updating configuration"
success: "Configuration updated"
projects:
config:
srcOutsideProjectDir: "Invalid value for 'srcDir' in {{ projectConfig }}: {{#bold}}srcDir: \"{{ srcDir }}\"{{/bold}}\n\t'srcDir' must be a relative path to a folder under the project root, such as \".\" or \"./src\""
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/lib/DevServerManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const httpClient = require('@hubspot/cli-lib/http');
const { logger } = require('@hubspot/cli-lib/logger');
const { COMPONENT_TYPES } = require('./projectStructure');
const { i18n } = require('./lang');
Expand Down Expand Up @@ -91,7 +90,6 @@ class DevServerManager {
await serverInterface.start({
accountId,
debug: this.debug,
httpClient,
projectConfig,
requestPorts,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/__tests__/validation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { getOauthManager } = require('@hubspot/cli-lib/oauth');
const { getOauthManager } = require('@hubspot/local-dev-lib/oauth');
const {
accessTokenForPersonalAccessKey,
} = require('@hubspot/local-dev-lib/personalAccessKey');
Expand All @@ -10,7 +10,7 @@ const { validateAccount } = require('../validation');
jest.mock('@hubspot/cli-lib');
jest.mock('@hubspot/local-dev-lib/config');
jest.mock('@hubspot/cli-lib/logger');
jest.mock('@hubspot/cli-lib/oauth');
jest.mock('@hubspot/local-dev-lib/oauth');
jest.mock('@hubspot/local-dev-lib/personalAccessKey');
jest.mock('../commonOpts');

Expand Down
42 changes: 26 additions & 16 deletions packages/cli/lib/oauth.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
const express = require('express');
const open = require('open');
const OAuth2Manager = require('@hubspot/cli-lib/lib/models/OAuth2Manager');
const {
default: OAuth2Manager,
} = require('@hubspot/local-dev-lib/models/OAuth2Manager');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { addOauthToAccountConfig } = require('@hubspot/cli-lib/oauth');
const { addOauthToAccountConfig } = require('@hubspot/local-dev-lib/oauth');
const { handleExit } = require('./process');
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
const { logger } = require('@hubspot/cli-lib/logger');
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
const { buildLogCallbacks } = require('./logCallbacks');

const PORT = 3000;
const redirectUri = `http://localhost:${PORT}/oauth-callback`;

const i18nKey = 'cli.lib.oauth';

const oauthLogCallbacks = buildLogCallbacks({
init: `${i18nKey}.logCallbacks.init`,
success: {
key: `${i18nKey}.logCallbacks.success`,
logger: logger.success,
},
});

const buildAuthUrl = oauthManager => {
return (
`${getHubSpotWebsiteOrigin(oauthManager.env)}/oauth/${
oauthManager.accountId
`${getHubSpotWebsiteOrigin(oauthManager.account.env)}/oauth/${
oauthManager.account.accountId
}/authorize` +
`?client_id=${encodeURIComponent(oauthManager.clientId)}` + // app's client ID
`&scope=${encodeURIComponent(oauthManager.scopes.join(' '))}` + // scopes being requested by the app
`?client_id=${encodeURIComponent(oauthManager.account.clientId)}` + // app's client ID
`&scope=${encodeURIComponent(oauthManager.account.scopes.join(' '))}` + // scopes being requested by the app
`&redirect_uri=${encodeURIComponent(redirectUri)}` // where to send the user after the consent page
);
};
Expand All @@ -44,8 +57,8 @@ const authorize = async oauthManager => {
if (req.query.code) {
const authCodeProof = {
grant_type: 'authorization_code',
client_id: oauthManager.clientId,
client_secret: oauthManager.clientSecret,
client_id: oauthManager.account.clientId,
client_secret: oauthManager.account.clientSecret,
redirect_uri: redirectUri,
code: req.query.code,
};
Expand Down Expand Up @@ -84,20 +97,17 @@ const authorize = async oauthManager => {
const setupOauth = accountConfig => {
const accountId = parseInt(accountConfig.portalId, 10);
const config = getAccountConfig(accountId) || {};
return new OAuth2Manager(
{
...accountConfig,
environment: accountConfig.env || config.env || ENVIRONMENTS.PROD,
},
logger
);
return new OAuth2Manager({
...accountConfig,
environment: accountConfig.env || config.env || ENVIRONMENTS.PROD,
});
};

const authenticateWithOauth = async configData => {
const oauthManager = setupOauth(configData);
logger.log('Authorizing');
await authorize(oauthManager);
addOauthToAccountConfig(oauthManager);
addOauthToAccountConfig(oauthManager, oauthLogCallbacks);
};

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
loadConfigFromEnvironment,
} = require('@hubspot/local-dev-lib/config');
const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path');
const { getOauthManager } = require('@hubspot/cli-lib/oauth');
const { getOauthManager } = require('@hubspot/local-dev-lib/oauth');
const {
accessTokenForPersonalAccessKey,
} = require('@hubspot/local-dev-lib/personalAccessKey');
Expand Down Expand Up @@ -118,7 +118,7 @@ async function validateAccount(options) {
logger.error(
`The OAuth2 configuration for account ${accountId} is incorrect`
);
logger.error('Run "hscms auth oauth2" to reauthenticate');
logger.error('Run "hs auth --type=oauth2" to reauthenticate');
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@hubspot/cli-lib": "^8.0.2",
"@hubspot/local-dev-lib": "^0.2.3",
"@hubspot/local-dev-lib": "^0.2.4",
"@hubspot/serverless-dev-runtime": "5.1.3-beta.0",
"@hubspot/ui-extensions-dev-server": "0.8.6",
"archiver": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-dev-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"dependencies": {
"@hubspot/cli-lib": "^8.0.2",
"@hubspot/local-dev-lib": "^0.2.2",
"@hubspot/local-dev-lib": "^0.2.4",
"body-parser": "^1.19.0",
"chalk": "^4.1.0",
"chokidar": "^3.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cms-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@hubspot/cli-lib": "^8.0.2",
"@hubspot/local-dev-lib": "^0.2.2"
"@hubspot/local-dev-lib": "^0.2.4"
},
"gitHead": "0659fd19cabc3645af431b177c11d0c1b089e0f8"
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@
table "^6.6.0"
unixify "1.0.0"

"@hubspot/local-dev-lib@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-0.2.2.tgz#bd979197849172190a0fad558b192b6a05933fd7"
integrity sha512-zKAlj5ITHzEqEW6Qwz9tZx452kZEKgFEJJxag/MYlANgs+8JF2mu7HC1yB2Zs92mR7WJ1HNgOxrrQuLNd+MdWA==
"@hubspot/local-dev-lib@^0.2.4":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-0.2.4.tgz#af80a37283d08e55fa71ecff6a9832e01e459057"
integrity sha512-J/5cuPHqn5T2/Vh/yNe5UsPRROyfuujKI0KeRn+yd+A5ZCA0ei+GQaIsXrQbEAhcSJT+39o3umdeaEZZFACVeQ==
dependencies:
address "^2.0.1"
axios "^1.3.5"
Expand Down

0 comments on commit 97c757f

Please sign in to comment.