Repository navigation
Allow merging Default Setup config with config file
#3994
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
Changes from 1 commit
c512861
cd604f8
a52a966
132634d
53a488c
6860cc1
0188f39
d1db924
18d20b7
3157774
42c0c6a
3707b44
d149f93
764f470
9a06fa6
44d6b3b
4509fb3
8476401
8be707b
7ccd988
06898d7
d2472aa
6829d6c
6973946
dc2d916
1f91ec8
98dbd66
9573f05
847e7af
7c961fa
cee0056
e4752e7
8d8f054
512bf6f
0b10dee
e26215c
26cbf9f
f630f8f
66c15f4
2773684
f181d70
7577328
3d2713f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
mergeUserConfigs with tests
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,56 @@ export interface UserConfig { | |
| "default-setup"?: DefaultSetupConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Merges supported properties from two configuration files. This is intended only for | ||
| * use with merging the `config` input provided by Default Setup with a potentially | ||
| * richer configuration file provided by a user. | ||
| * | ||
| * @param logger The logger to use. | ||
| * @param fromConfigInput The configuration from Default Setup. | ||
| * @param fromConfigFile The user-supplied configuration. | ||
| * @returns The combination of both configuration files. | ||
| */ | ||
| export function mergeUserConfigs( | ||
|
mbg marked this conversation as resolved.
Outdated
|
||
| logger: Logger, | ||
| fromConfigInput: UserConfig, | ||
| fromConfigFile: UserConfig, | ||
| ): UserConfig { | ||
| logger.debug( | ||
| "Combining configuration files from 'config' and 'config-file' inputs", | ||
| ); | ||
|
|
||
| // Combine all specified threat models from both sources. | ||
| const threatModels = new Set(fromConfigInput["threat-models"] || []); | ||
| for (const configFileThreatModel of fromConfigFile["threat-models"] || []) { | ||
| threatModels.add(configFileThreatModel); | ||
| } | ||
|
|
||
| // Warn if there is a 'default-setup' configuration key in the user-supplied configuration, | ||
| // since it is not meant to be used and we therefore ignore it here. | ||
| if (fromConfigFile["default-setup"]) { | ||
| logger.warning( | ||
| `The 'default-setup' configuration key is not supported in user-supplied configuration files and will be ignored.`, | ||
| ); | ||
| } | ||
|
|
||
| // Since we expect the `fromConfigInput` configuration to be provided by Default Setup, | ||
| // we expect a limited set of options. Therefore, we base the overall configuration on | ||
| // the one provided via the `config-file` input, which may be richer. | ||
| const result = { ...fromConfigFile }; | ||
| delete result["threat-models"]; | ||
| delete result["default-setup"]; | ||
|
|
||
| if (fromConfigInput["default-setup"]) { | ||
| result["default-setup"] = fromConfigInput["default-setup"]; | ||
| } | ||
| if (threatModels.size > 0) { | ||
| result["threat-models"] = Array.from(threatModels); | ||
| } | ||
|
|
||
| return result; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably worth logging a warning that is sent to telemetry if we find any other properties in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| /** | ||
| * Represents additional configuration data from a source other than | ||
| * a configuration file. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.