-
Notifications
You must be signed in to change notification settings - Fork 2
Feature: Add name flag to a config-manager pull commands #118
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { Option } from 'commander'; | ||
|
|
||
| import { configManagerExportMappings } from '../../../configManagerOps/FrConfigConnectorMappingOps'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
|
|
@@ -22,6 +23,9 @@ export default function setup() { | |
|
|
||
| program | ||
| .description('Export connector mappings.') | ||
| .addOption( | ||
| new Option('-n, --name <name>', 'Export by name of connector mapping.') | ||
| ) | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
|
|
@@ -33,8 +37,14 @@ export default function setup() { | |
| ); | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting connector mappings'); | ||
| const outcome = await configManagerExportMappings(); | ||
| let outcome: boolean; | ||
| if (options.name) { | ||
| verboseMessage(`Exporting ${options.name}`); | ||
| outcome = await configManagerExportMappings(options.name); | ||
| } else { | ||
| verboseMessage('Exporting connector mappings'); | ||
| outcome = await configManagerExportMappings(); | ||
| } | ||
|
Comment on lines
+40
to
+47
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(options.name ? `Exporting ${options.name}` : 'Exporting connector mappings');
const outcome = await configManagerExportMappings(options.name); |
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ export default function setup() { | |
| 'The CSP_OVERRIDES json file. ex: "/home/trivir/Documents/csp-overrides.json", or "csp-overrides.json"' | ||
| ) | ||
| ) | ||
| .addOption(new Option('-n, --name <name>', 'Export by name of csp.')) | ||
|
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. Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075 |
||
| .addHelpText( | ||
| 'after', | ||
| 'There is an option to overrides the export file.\n' + | ||
|
|
@@ -57,8 +58,14 @@ export default function setup() { | |
| ); | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting content security policy'); | ||
| const outcome = await configManagerExportCsp(options.file); | ||
| let outcome: boolean; | ||
| if (options.name) { | ||
| verboseMessage(`Exporting ${options.name}`); | ||
| outcome = await configManagerExportCsp(options.file, options.name); | ||
| } else { | ||
| verboseMessage('Exporting content security policy'); | ||
| outcome = await configManagerExportCsp(options.file); | ||
| } | ||
|
Comment on lines
+61
to
+68
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(options.name ? `Exporting ${options.name}` : 'Exporting content security policy');
const outcome = await configManagerExportCsp(options.file, options.name); |
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,7 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { Option } from 'commander'; | ||
|
|
||
| import { | ||
| configManagerExportOrgPrivileges, | ||
| configManagerExportOrgPrivilegesAllRealms, | ||
| configManagerExportOrgPrivilegesRealm, | ||
| } from '../../../configManagerOps/FrConfigOrgPrivilegesOps'; | ||
| import { configManagerExportOrgPrivileges } from '../../../configManagerOps/FrConfigOrgPrivilegesOps'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
| import { printMessage } from '../../../utils/Console'; | ||
| import { FrodoCommand } from '../../FrodoCommand'; | ||
|
|
@@ -17,7 +13,6 @@ const deploymentTypes = [ | |
| CLOUD_DEPLOYMENT_TYPE_KEY, | ||
| FORGEOPS_DEPLOYMENT_TYPE_KEY, | ||
| ]; | ||
| const { constants } = frodo.utils; | ||
|
|
||
| export default function setup() { | ||
| const program = new FrodoCommand( | ||
|
|
@@ -29,10 +24,7 @@ export default function setup() { | |
| program | ||
| .description('Export organization privileges config.') | ||
| .addOption( | ||
| new Option( | ||
| '-r, --realm <realm>', | ||
| 'Specifies the realm to export from. Only the entity object from this realm will be exported.' | ||
| ) | ||
|
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. I think these realm flag changes should be already removed in your realm PR: #116 If you need these changes for this PR, I would rebase this PR with your realm branch and make this PR against the realm branch, that way we can keep the changes separate. |
||
| new Option('-n, --name <name>', 'Export by name of org-privilege') | ||
|
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. Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075 |
||
| ) | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
|
|
@@ -44,27 +36,17 @@ export default function setup() { | |
| command | ||
| ); | ||
|
|
||
| // -r flag has precedence | ||
| if (options.realm) { | ||
| realm = options.realm; | ||
| } | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| let outcome: boolean; | ||
| if (realm !== constants.DEFAULT_REALM_KEY) { | ||
| if (options.name) { | ||
| printMessage( | ||
| `Exporting organization privileges config from the realm: "${realm}"` | ||
| `Exporting ${options.name} organization privilege config` | ||
| ); | ||
| outcome = | ||
| (await configManagerExportOrgPrivileges()) && | ||
| (await configManagerExportOrgPrivilegesRealm(realm)); | ||
| outcome = await configManagerExportOrgPrivileges(options.name); | ||
| } else { | ||
| printMessage( | ||
| 'Exporting oranization privileges config from all realms' | ||
| ); | ||
| outcome = await configManagerExportOrgPrivilegesAllRealms(); | ||
| printMessage('Exporting all oranization privileges config'); | ||
| outcome = await configManagerExportOrgPrivileges(); | ||
| } | ||
|
Comment on lines
+41
to
66
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(`Exporting ${options.name || 'all'} organization privileges`);
const outcome = await configManagerExportOrgPrivileges(options.name);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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(`Exporting ${options.name || 'all'} organization privileges`);
const outcome = await configManagerExportOrgPrivileges(options.name); |
||
|
|
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { Option } from 'commander'; | ||
|
|
||
| import { configManagerExportSecrets } from '../../../configManagerOps/FrConfigSecretOps'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
|
|
@@ -22,6 +23,7 @@ export default function setup() { | |
|
|
||
| program | ||
| .description('Export secrets.') | ||
| .addOption(new Option('-n, --name <name>', 'Export by name of secret.')) | ||
|
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. Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075 |
||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
|
|
@@ -33,8 +35,14 @@ export default function setup() { | |
| ); | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting secrets'); | ||
| const outcome = await configManagerExportSecrets(options); | ||
| let outcome: boolean; | ||
| if (options.name) { | ||
| verboseMessage(`Exporting ${options.name}`); | ||
| outcome = await configManagerExportSecrets(options, options.name); | ||
| } else { | ||
| verboseMessage('Exporting secrets'); | ||
| outcome = await configManagerExportSecrets(options); | ||
| } | ||
|
Comment on lines
+38
to
+45
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(`Exporting ${options.name || 'secrets'}`);
const outcome = await configManagerExportSecrets(options.name);Note for this one it doesn't make sense to pass in options, only |
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { Option } from 'commander'; | ||
|
|
||
| import { configManagerExportThemes } from '../../../configManagerOps/FrConfigThemeOps'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
|
|
@@ -22,6 +23,7 @@ export default function setup() { | |
|
|
||
| program | ||
| .description('Export themes.') | ||
| .addOption(new Option('-n, --name <name>', 'Export by name of theme.')) | ||
|
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. Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075 |
||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
|
|
@@ -33,8 +35,14 @@ export default function setup() { | |
| ); | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting themes'); | ||
| const outcome = await configManagerExportThemes(); | ||
| let outcome: boolean; | ||
| if (options.name) { | ||
| verboseMessage(`Exporting ${options.name}`); | ||
| outcome = await configManagerExportThemes(options.name); | ||
| } else { | ||
| verboseMessage('Exporting themes'); | ||
| outcome = await configManagerExportThemes(); | ||
| } | ||
|
Comment on lines
+38
to
+45
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(`Exporting ${options.name || 'themes'}`);
const outcome = await configManagerExportThemes(options.name); |
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { Option } from 'commander'; | ||
|
|
||
| import { configManagerExportVariables } from '../../../configManagerOps/FrConfigVariableOps'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
|
|
@@ -17,6 +18,9 @@ export default function setup() { | |
|
|
||
| program | ||
| .description('Export variables objects.') | ||
|
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. I don't think it makes sense to say "objects", we should just say "variables" like we do with secrets. |
||
| .addOption( | ||
| new Option('-n, --name <name>', 'Export by name of variable object.') | ||
|
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. Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075, I would also remove "object" from the description |
||
| ) | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
|
|
@@ -28,8 +32,14 @@ export default function setup() { | |
| ); | ||
|
|
||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting variables'); | ||
| const outcome = await configManagerExportVariables(); | ||
| let outcome: boolean; | ||
| if (options.name) { | ||
| verboseMessage(`Exporting ${options.name}`); | ||
| outcome = await configManagerExportVariables(options.name); | ||
| } else { | ||
| verboseMessage('Exporting variables'); | ||
| outcome = await configManagerExportVariables(); | ||
| } | ||
|
Comment on lines
+35
to
+42
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. Since you are calling the same function, you don't need an if statement here. You can simplify this to: verboseMessage(`Exporting ${options.name || 'variables'}`);
const outcome = await configManagerExportVariables(options.name); |
||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| // unrecognized combination of options or no options | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,17 +10,33 @@ const { getFilePath, saveJsonToFile } = frodo.utils; | |
|
|
||
| /** | ||
| * Export the content security policy in fr-config manager format | ||
| * @param {string} file file for csp override | ||
| * @param {string} name csp name | ||
| * @returns True if file was successfully saved | ||
| */ | ||
| export async function configManagerExportCsp( | ||
| file: string = null | ||
| file: string = null, | ||
| name?: string | ||
| ): Promise<boolean> { | ||
| try { | ||
| const cspEnforced: ContentSecurityPolicy = | ||
| await env.readEnforcedContentSecurityPolicy(); | ||
| const cspReport: ContentSecurityPolicy = | ||
| await env.readReportOnlyContentSecurityPolicy(); | ||
| const csp = { enforced: cspEnforced, 'report-only': cspReport }; | ||
| let csp: Record<string, ContentSecurityPolicy>; | ||
| if (name && name !== 'enforced' && name !== 'report-only') { | ||
| throw new Error(`Unknown CSP: ${name}`); | ||
| } | ||
| if (name === 'enforced') { | ||
| csp = { | ||
| enforced: await env.readEnforcedContentSecurityPolicy(), | ||
| }; | ||
| } else if (name === 'report-only') { | ||
| csp = { | ||
| 'report-only': await env.readReportOnlyContentSecurityPolicy(), | ||
| }; | ||
| } else { | ||
| csp = { | ||
| enforced: await env.readEnforcedContentSecurityPolicy(), | ||
| 'report-only': await env.readReportOnlyContentSecurityPolicy(), | ||
| }; | ||
| } | ||
|
Comment on lines
+22
to
+39
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. You can simplify this as follows to avoid duplicate code: if (name && name !== 'enforced' && name !== 'report-only') {
throw new Error(`Unknown CSP: ${name}`);
}
let csp: Record<string, ContentSecurityPolicy> = {};
if (!name || name === 'enforced') {
csp.enforced = await env.readEnforcedContentSecurityPolicy();
}
if (!name || name === 'report-only') {
csp['report-only'] = await env.readReportOnlyContentSecurityPolicy();
} |
||
|
|
||
| if (file) { | ||
| const configFileData = JSON.parse( | ||
|
|
||
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.
Suggestion: We can make the wording more concise with
Export by name.orExport connector mapping by name.Technically "connector mapping" is not necessary as that is implied by the command, although it's fine if we keep it in there.