-
Notifications
You must be signed in to change notification settings - Fork 5
Config Revamp #231
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
base: main
Are you sure you want to change the base?
Config Revamp #231
Conversation
|
||
Returns config data for a specific account, given the account's ID or name. | ||
|
||
## Example config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the existing content of the readme to reflect the changes I made, but it may make sense to rethink it completely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good call. That could always be done as a follow up
@@ -1,268 +1,406 @@ | |||
import * as config_DEPRECATED from './config_DEPRECATED'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is more or less net new, but because it has the same name as the old one, GH is showing a diff.
} | ||
return config_DEPRECATED.deleteEmptyConfigFile(); | ||
export function getConfigFilePath(): string { | ||
const { configFilePathFromEnvironment } = getConfigPathEnvironmentVariables(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getConfigFilePath
checks for a HUBSPOT_CONFIG_PATH
environment variable if the user is using a custom path - this variable will need to be set by the CLI if the user passes in the --config
flag
if (CLIConfiguration.isActive()) { | ||
return CLIConfiguration.config; | ||
export function getConfig(): HubSpotConfig { | ||
const { useEnvironmentConfig } = getConfigPathEnvironmentVariables(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with environment config - a user passes in the --use-env
flag to the CLI, the CLI should set the USE_ENVIRONMENT_CONFIG
env variable to tell LDL to use environment variables. These new environment variables let us avoid needing to have configPath and useEnv arguments for every function that accesses the config
} else { | ||
config_DEPRECATED.updateHttpTimeout(timeout); | ||
export function updateConfigAccount( | ||
updatedAccount: HubSpotConfigAccount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function now accepts a full updated account rather than just fields to update. This makes it easier to use TS to confirm that updates are valid (for example, TS would have no way to know the auth type of the account you're trying to update, and therefore would allow updating accounts to have invalid auth)
export function updateConfigAccount( | ||
updatedAccount: HubSpotConfigAccount | ||
): void { | ||
if (!isConfigAccountValid(updatedAccount)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still manually check validity just in case though!
constants/config.ts
Outdated
HTTP_USE_LOCALHOST: 'HTTP_USE_LOCALHOST', | ||
ALLOW_USAGE_TRACKING: 'ALLOW_USAGE_TRACKING', | ||
DEFAULT_CMS_PUBLISH_MODE: 'DEFUALT_CMS_PUBLISH_MODE', | ||
USE_ENVIRONMENT_CONFIG: 'USE_ENVIRONMENT_CONFIG', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight nit, but does it make sense for USE_ENVIRONMENT_CONFIG
to include "hubspot" in the name somewhere? It doesn't matter a ton if the CLI is setting it, but I imagine people can also manually set this if they want to.
config/utils.ts
Outdated
|
||
export function getConfigAccountIndexById( | ||
accounts: Array<HubSpotConfigAccount>, | ||
id: string | number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for accountId to be anything except for a number in this new format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, this should just be number
config/utils.ts
Outdated
|
||
return { | ||
identifier: isId ? identifierAsNumber : accountIdentifier, | ||
identifierType: isId ? 'accountId' : 'name', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but could it potentially prevent some future pain by making these identifiers constants?
config/__tests__/utils.test.ts
Outdated
describe('writeConfigFile()', () => { | ||
it('writes formatted config to file', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
mockFs.ensureFileSync.mockImplementation(() => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but you could get rid of the ignores if you make these return undefined instead
} from '../constants/config'; | ||
import { i18n } from '../utils/lang'; | ||
import { FileSystemError } from '../models/FileSystemError'; | ||
import { getAllConfigAccounts } from './index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to move this stuff to its own file because it doesn't directly interact with the config file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new approach a lot!
Code lgtm 👌 we should chat about what the rollout strategy looks like |
...configOptions, | ||
portalId: accountIdentifier, | ||
}); | ||
export function getConfigAccountIfExists( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was reviewing one of your PR's in the CLI, and this util tripped me up a little. This is effectively the same functionality as getConfigAccountByInferredIdentifier
. But the naming of this util doesn't make it clear that we're inferring the identifier.`
Dynamic config migrations
Description and Context
This PR rebuilds the
config
module from the ground up. The newconfig
module has a variety of improvements over the old one:config/config
andconfig/CLIConfiguration
into a single file.account
fields and deprecatedportal
fields, but converts them into a standardized format (no need to check portalId vs accountId anymore)HubSpotConfig
andHubSpotConfigAccount
types are guaranteed to exist. No more checking fornull
andundefined
everywhere!twothree config files (added one for defaultAccountOverride stuff), down from five.config/index
contains all exported functionality, andconfig/utils
contains all non-exported helper functionsNote: the majority of new functionality is in
config/index
andconfig/utils
, both of which are hidden by defaultTODO
I haven't yet merged in the account override work since it appears to still be in flux. Will be working with @kemmerle on that.Default account override functionality addedOAuth2Manager
andlogger
. We will need to take care of those too, but I figured this PR is big enough as isWho to Notify
@joe-yeager @brandenrodgers @kemmerle