diff --git a/.gitignore b/.gitignore index 3a0ba02ea..50ebfd179 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ dist testResults.json +jest-test-setup.js *.cer *.p12 diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-all-static.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-all-static.ts index e97d16099..0d5014903 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-all-static.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-all-static.ts @@ -18,7 +18,6 @@ export default function setup() { [], deploymentTypes ); - // TO DO: adding a realm option to export all-static for specific realm program .description('Export all static config.') .action(async (host, realm, user, password, options, command) => { @@ -36,7 +35,7 @@ export default function setup() { return; } - const outcome = await configManagerExportAllStatic(); + const outcome = await configManagerExportAllStatic(realm); if (!outcome) process.exitCode = 1; }); diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-all.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-all.ts index ab591170c..3c58add49 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-all.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-all.ts @@ -20,7 +20,6 @@ export default function setup() { [], deploymentTypes ); - // TO DO: Adding a realm option to export all config for a specific realm program .description('Export all config.') .addOption( @@ -60,6 +59,7 @@ export default function setup() { ); const outcome = await configManagerExportAllWithConfigFolder({ configFolder: options.configFolder, + realm, }); if (!outcome) process.exitCode = 1; } diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-authentication.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-authentication.ts index ad0987b3e..cf57bf98a 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-authentication.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-authentication.ts @@ -1,5 +1,4 @@ import { frodo } from '@rockcarver/frodo-lib'; -import { Option } from 'commander'; import { configManagerExportAuthentication } from '../../../configManagerOps/FrConfigAuthenticationOps'; import { getTokens } from '../../../ops/AuthenticateOps'; @@ -23,12 +22,6 @@ export default function setup() { program .description('Export authentication objects.') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only the entity object from this realm will be exported.' - ) - ) .action(async (host, realm, user, password, options, command) => { command.handleDefaultArgsAndOpts( host, @@ -38,9 +31,6 @@ export default function setup() { options, command ); - if (options.realm) { - realm = options.realm; - } if (await getTokens(false, true, deploymentTypes)) { verboseMessage('Exporting config entity authentication'); const outcome = await configManagerExportAuthentication(realm); diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-authz-policies.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-authz-policies.ts index 639c70cf8..fd5ffe9e9 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-authz-policies.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-authz-policies.ts @@ -1,12 +1,7 @@ -import { frodo, state } from '@rockcarver/frodo-lib'; +import { frodo } from '@rockcarver/frodo-lib'; import { Option } from 'commander'; -import { - configManagerExportAuthzPoliciesAll, - configManagerExportAuthzPolicySet, - configManagerExportAuthzPolicySets, - configManagerExportAuthzPolicySetsRealm, -} from '../../../configManagerOps/FrConfigAuthzPoliciesOps'; +import { configManagerExportAuthzPolicySets } from '../../../configManagerOps/FrConfigAuthzPoliciesOps'; import { getTokens } from '../../../ops/AuthenticateOps'; import { printMessage } from '../../../utils/Console'; import { FrodoCommand } from '../../FrodoCommand'; @@ -18,8 +13,6 @@ const deploymentTypes = [ CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY, ]; -const { constants } = frodo.utils; -const { readRealms } = frodo.realm; export default function setup() { const program = new FrodoCommand( @@ -29,22 +22,10 @@ export default function setup() { program .description('Export authorization policies from realm.') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only policy sets from this realm will be exported. Ignored with -f' - ) - ) - .addOption( - new Option( - '-n, --policy-name ', - 'Get only a specific policy set with the name.' - ) - ) .addOption( new Option( '-f, --file ', - 'The AUTHZ_POLICY_SETS_CONFIG json file. ex: "/home/trivir/Documents/policy-sets.json", or "policy-sets.json"' + '*Required* The AUTHZ_POLICY_SETS_CONFIG json file. ex: "/Documents/policy-sets.json"' ) ) .addHelpText( @@ -79,88 +60,10 @@ export default function setup() { command ); - // -r/--realm flag has precedence over [realm] arguement - if (options.realm) { - realm = options.realm; - } - if (await getTokens(false, true, deploymentTypes)) { - let outcome: boolean; - - // -p/--p-set - if (options.policyName) { - printMessage( - `Exporting the policy set "${options.policyName}" in the ${state.getRealm()} realm.` - ); - - // try and find script in current realm - outcome = await configManagerExportAuthzPolicySet( - { - policySetName: options.policyName, - }, - options.file - ); - - // check other realms for the script but only if there is no config file specified - if (!outcome && !options.file) { - const checkedRealms: string[] = [state.getRealm()]; - for (const realm of await readRealms()) { - if (outcome) { - break; - } - if (!checkedRealms.includes(realm.name)) { - printMessage( - `Exporting the policy set "${options.policyName}" from the ${checkedRealms[checkedRealms.length - 1]} realm failed.` - ); - state.setRealm(realm.name); - checkedRealms.push(state.getRealm()); - printMessage( - `Looking for the policy set "${options.policyName}" in the ${state.getRealm()} realm now.` - ); - outcome = await configManagerExportAuthzPolicySet( - { - policySetName: options.policyName, - }, - null - ); - } - } - if (!outcome) { - printMessage( - `Did not find the policy set "${options.policyName}" anywhere.` - ); - } - } - } - - // -f/--file - else if (options.file) { - printMessage( - `Exporting all the policy sets in the provided config file.` - ); - outcome = await configManagerExportAuthzPolicySets(options.file); - } - - // -r/--realm - else if (realm !== constants.DEFAULT_REALM_KEY) { - printMessage( - `Exporting all the policy sets in the ${state.getRealm()} realm.` - ); - outcome = await configManagerExportAuthzPolicySetsRealm(); - } - - // export all policy sets from all realms, the default when no options are provided - else { - printMessage('Exporting all the policy sets in the host tenant.'); - outcome = await configManagerExportAuthzPoliciesAll(); - } - - if (!outcome) { - printMessage( - `Failed to export one or more authorization policy sets. ${options.verbose ? '' : 'Check --verbose for me details.'}` - ); - process.exitCode = 1; - } + printMessage(`Exporting all policy sets in the provided config file.`); + const outcome = await configManagerExportAuthzPolicySets(options.file); + if (!outcome) process.exit(1); } // unrecognized combination of options or no options diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-journeys.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-journeys.ts index bc947bec2..744103f75 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-journeys.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-journeys.ts @@ -29,12 +29,6 @@ export default function setup() { 'Journey name, It only export the journey with the name.' ) ) - .addOption( - new Option( - '-r, --realm ', - 'Specific realm to get journeys from (overrides environment)' - ) - ) .addOption(new Option('-d, --pull-dependencies', 'Pull dependencies.')) // TO DO: implementing for 'clean' // .addOption( @@ -49,9 +43,6 @@ export default function setup() { options, command ); - if (options.realm) { - realm = options.realm; - } if (await getTokens(false, true, deploymentTypes)) { verboseMessage('Exporting config entity journeys'); diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-oauth2-agents.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-oauth2-agents.ts index b31c79663..cbd53c1b9 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-oauth2-agents.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-oauth2-agents.ts @@ -1,12 +1,7 @@ -import { frodo, state } from '@rockcarver/frodo-lib'; +import { frodo } from '@rockcarver/frodo-lib'; import { Option } from 'commander'; -import { - configManagerExportAgent, - configManagerExportAgentsAll, - configManagerExportAgentsRealm, - configManagerExportConfigAgents, -} from '../../../configManagerOps/FrConfigOauth2AgentOps'; +import { configManagerExportConfigAgents } from '../../../configManagerOps/FrConfigOauth2AgentOps'; import { getTokens } from '../../../ops/AuthenticateOps'; import { printMessage } from '../../../utils/Console'; import { FrodoCommand } from '../../FrodoCommand'; @@ -18,8 +13,6 @@ const deploymentTypes = [ CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY, ]; -const { constants } = frodo.utils; -const { readRealms } = frodo.realm; export default function setup() { const program = new FrodoCommand( @@ -29,19 +22,6 @@ export default function setup() { program .description('Export OAuth2 Agents') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only the agents from this realm will be exported.' - ) - ) - .addOption( - new Option( - '-n, --agent-name ', - 'Export specific agent using agentId/agentName.' - ) - ) - .addOption( new Option( '-f, --file ', @@ -94,84 +74,12 @@ export default function setup() { command ); - // -r/--realm flag has precedence over [realm] arguement - if (options.realm) { - realm = options.realm; - } - if (await getTokens(false, true, deploymentTypes)) { - let outcome: boolean; - - // -n/--script-name - if (options.agentName) { - printMessage( - `Exporting the agent "${options.agentName}" from the ${state.getRealm()} realm.` - ); - - // try and find the agent in current realm - outcome = await configManagerExportAgent( - options.agentName, - options.file - ); - - // check other realms for the agent - if (!outcome && !options.file) { - const checkedRealms: string[] = [state.getRealm()]; - for (const realm of await readRealms()) { - if (outcome) { - break; - } - if (!checkedRealms.includes(realm.name)) { - printMessage( - `Exporting the agent "${options.agentName}" from the ${state.getRealm()} realm failed.` - ); - state.setRealm(realm.name); - checkedRealms.push(state.getRealm()); - printMessage( - `Looking for the agent "${options.agentName}" in the ${state.getRealm()} realm now.` - ); - outcome = await configManagerExportAgent( - options.agentName, - null - ); - } - } - if (!outcome) { - printMessage( - `Did not find the agent "${options.agentName}" anywhere.` - ); - } - } - } - - // -f/--file - else if (options.file) { - printMessage( - `Exporting all the agents defined in the provided config file.` - ); - outcome = await configManagerExportConfigAgents(options.file); - } - - // -r/--realm - else if (realm !== constants.DEFAULT_REALM_KEY) { - printMessage( - `Exporting all the agents from the ${state.getRealm()} realm.` - ); - outcome = await configManagerExportAgentsRealm(); - } - - // export all oauth2 agents, the default when no options are provided - else { - printMessage(`Exporting all the agents in the host tenant.`); - outcome = await configManagerExportAgentsAll(); - } - - if (!outcome) { - printMessage( - `Failed to export one or more oauth2 agents. ${options.verbose ? '' : 'Check --verbose for me details.'}` - ); - process.exitCode = 1; - } + printMessage( + `Exporting all the agents defined in the provided config file.` + ); + const outcome = await configManagerExportConfigAgents(options.file); + if (!outcome) process.exit(1); } // unrecognized combination of options or no options diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-org-privileges.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-org-privileges.ts index 9f9910c3f..9b1d8585f 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-org-privileges.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-org-privileges.ts @@ -1,11 +1,6 @@ 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 +12,6 @@ const deploymentTypes = [ CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY, ]; -const { constants } = frodo.utils; export default function setup() { const program = new FrodoCommand( @@ -28,12 +22,6 @@ export default function setup() { program .description('Export organization privileges config.') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only the entity object from this realm will be exported.' - ) - ) .action(async (host, realm, user, password, options, command) => { command.handleDefaultArgsAndOpts( host, @@ -44,26 +32,11 @@ 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) { - printMessage( - `Exporting organization privileges config from the realm: "${realm}"` - ); - outcome = - (await configManagerExportOrgPrivileges()) && - (await configManagerExportOrgPrivilegesRealm(realm)); - } else { - printMessage( - 'Exporting oranization privileges config from all realms' - ); - outcome = await configManagerExportOrgPrivilegesAllRealms(); - } + printMessage( + `Exporting organization privileges config from the realm: "${realm}"` + ); + const outcome = await configManagerExportOrgPrivileges(); if (!outcome) process.exitCode = 1; } diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-password-policy.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-password-policy.ts index 97a3c629e..51a492448 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-password-policy.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-password-policy.ts @@ -1,5 +1,4 @@ import { frodo } from '@rockcarver/frodo-lib'; -import { Option } from 'commander'; import { configManagerExportPasswordPolicy } from '../../../configManagerOps/FrConfigPasswordPolicyOps'; import { getTokens } from '../../../ops/AuthenticateOps'; @@ -23,12 +22,6 @@ export default function setup() { program .description('Export password-policy objects.') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only the entity object from this realm will be exported.' - ) - ) .action(async (host, realm, user, password, options, command) => { command.handleDefaultArgsAndOpts( host, @@ -38,9 +31,6 @@ export default function setup() { options, command ); - if (options.realm) { - realm = options.realm; - } if (await getTokens(false, true, deploymentTypes)) { verboseMessage('Exporting config entity password-policy'); const outcome = await configManagerExportPasswordPolicy(realm); diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-saml.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-saml.ts index 6c25c05cb..0cac82ef4 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-saml.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-saml.ts @@ -64,9 +64,6 @@ export default function setup() { options, command ); - if (options.realm) { - realm = options.realm; - } if (await getTokens(false, true, deploymentTypes)) { verboseMessage('Exporting config entity saml'); diff --git a/src/cli/config-manager/config-manager-pull/config-manager-pull-scripts.ts b/src/cli/config-manager/config-manager-pull/config-manager-pull-scripts.ts index 3beb7f298..dbe4989c1 100644 --- a/src/cli/config-manager/config-manager-pull/config-manager-pull-scripts.ts +++ b/src/cli/config-manager/config-manager-pull/config-manager-pull-scripts.ts @@ -1,11 +1,7 @@ -import { frodo, state } from '@rockcarver/frodo-lib'; +import { frodo } from '@rockcarver/frodo-lib'; import { Option } from 'commander'; -import { - configManagerExportScript, - configManagerExportScriptsAll, - configManagerExportScriptsRealms, -} from '../../../configManagerOps/FrConfigScriptOps'; +import { configManagerExportScripts } from '../../../configManagerOps/FrConfigScriptOps'; import { getTokens } from '../../../ops/AuthenticateOps'; import { printMessage } from '../../../utils/Console'; import { FrodoCommand } from '../../FrodoCommand'; @@ -17,8 +13,6 @@ const deploymentTypes = [ CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY, ]; -const { constants } = frodo.utils; -const { readRealms } = frodo.realm; export default function setup() { const program = new FrodoCommand( @@ -28,12 +22,6 @@ export default function setup() { program .description('Export authorization scripts.') - .addOption( - new Option( - '-r, --realm ', - 'Specifies the realm to export from. Only the scripts from this realm will be exported.' - ) - ) .addOption( new Option( '-n, --script-name