diff --git a/.eslintrc b/.eslintrc index 5b441bbe7..425fbd2b2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -51,4 +51,4 @@ "test/**/*.test_.ts", "tsup.config.ts" ] -} +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 35bcabebf..3a0ba02ea 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,6 @@ out test/fs_tmp/* !test/fs_tmp/.gitkeep + +temp +.vscode/settings.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index f1a3701b1..639228f9f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,13 +4,21 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { "type": "node", - "request": "attach", - "name": "Attach Debugger", - "port": 2000, - "restart": true + "request": "launch", + "name": "Debug", + "runtimeExecutable": "C:\\Users\\Devin\\AppData\\Local\\fnm_multishells\\1916_1742404469042\\node.exe", + "args": ["dist/app.cjs", "config-manager", "export", "scripts", "webinar"], + "outFiles": [ + "${workspaceFolder}/dist/*.cjs", + ], + "sourceMaps": true, + "resolveSourceMapLocations": [ + "${workspaceFolder}/dist/*", + ], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal" } ] } diff --git a/package-lock.json b/package-lock.json index 6447981c0..0f0836cfb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,6 +51,7 @@ "replaceall": "^0.1.6", "resolve": "^1.22.1", "rimraf": "^6.0.1", + "sanitize-filename": "^1.6.3", "slugify": "^1.6.5", "ts-jest": "^29.1.4", "tsup": "^8.1.0", @@ -8659,6 +8660,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sanitize-filename": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", + "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", + "dev": true, + "license": "WTFPL OR ISC", + "dependencies": { + "truncate-utf8-bytes": "^1.0.0" + } + }, "node_modules/semver": { "version": "7.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", @@ -9500,6 +9511,16 @@ "tree-kill": "cli.js" } }, + "node_modules/truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==", + "dev": true, + "license": "WTFPL", + "dependencies": { + "utf8-byte-length": "^1.0.1" + } + }, "node_modules/ts-api-utils": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.3.tgz", @@ -9957,6 +9978,13 @@ "punycode": "^2.1.0" } }, + "node_modules/utf8-byte-length": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.5.tgz", + "integrity": "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA==", + "dev": true, + "license": "(WTFPL OR MIT)" + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 6f0626e61..6e87878e8 100644 --- a/package.json +++ b/package.json @@ -150,6 +150,7 @@ "replaceall": "^0.1.6", "resolve": "^1.22.1", "rimraf": "^6.0.1", + "sanitize-filename": "^1.6.3", "slugify": "^1.6.5", "ts-jest": "^29.1.4", "tsup": "^8.1.0", diff --git a/src/app.ts b/src/app.ts index 9b80e6a4e..9d6688fa2 100755 --- a/src/app.ts +++ b/src/app.ts @@ -8,6 +8,7 @@ import app from './cli/app/app'; import authn from './cli/authn/authn'; import authz from './cli/authz/authz'; import config from './cli/config/config'; +import configManager from './cli/config-manager/config-manager'; import conn from './cli/conn/conn'; import email from './cli/email/email'; import esv from './cli/esv/esv'; @@ -64,6 +65,7 @@ const { initTokenCache } = frodo.cache; program.addCommand(authz()); program.addCommand(app()); program.addCommand(config()); + program.addCommand(configManager()); program.addCommand(conn()); program.addCommand(email()); program.addCommand(esv()); diff --git a/src/cli/config-manager/config-manager-export-access-config.ts b/src/cli/config-manager/config-manager-export-access-config.ts new file mode 100644 index 000000000..fcf1b4661 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-access-config.ts @@ -0,0 +1,44 @@ +import { configManagerExportAccessConfig } from '../../configManagerOps/FrConfigAccessConfigOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export access-config', + [], + deploymentTypes + ); + + program + .description('Export access-config objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity access-config'); + const outcome = await configManagerExportAccessConfig(options.envFile); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-all-static.ts b/src/cli/config-manager/config-manager-export-all-static.ts new file mode 100644 index 000000000..305b53927 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-all-static.ts @@ -0,0 +1,46 @@ +import { configManagerExportAllStatic } from '../../configManagerOps/FrConfigAllOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export all', + [], + deploymentTypes + ); + // TO DO: adding a realm option to export all-static for specific realm + program + .description('Export audit objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage( + 'Exporting config files that fr-config-manager supports.' + ); + const outcome = await configManagerExportAllStatic(); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-all.ts b/src/cli/config-manager/config-manager-export-all.ts new file mode 100644 index 000000000..668ef2b84 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-all.ts @@ -0,0 +1,72 @@ +import { Option } from 'commander'; + +import { configManagerExportAllWithConfigFolder } from '../../configManagerOps/FrConfigAllOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export all', + [], + deploymentTypes + ); + // TO DO: Adding a realm option to export all config for a specific realm + program + .description('Export audit objects.') + .addOption( + new Option( + '-F, --config-folder ', + 'Path to the folder containing the config files.\n' + ) + ) + .addHelpText( + 'after', + 'The following entities require config files to be exported:\n' + + '- authz-policies\n' + + '- oauth2-agents\n' + + '- saml\n' + + '- service-objects\n\n' + + 'Each config file must be named after the command it applies to. For example,\n' + + 'the config file for "authz-policies" should be named "authz-policies.json".\n' + + 'Please refer to the help message of each command to see an example config file by running:\n' + + '"frodo config-manager export -h"' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if ( + options.configFolder && + (await getTokens(false, true, deploymentTypes)) + ) { + verboseMessage( + 'Exporting config files that fr-config-manager supports.' + ); + const outcome = await configManagerExportAllWithConfigFolder({ + configFolder: options.configFolder, + }); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'You must specify a folder containing the config files.\n' + + 'Please refer to the help message for more information.', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-audit.ts b/src/cli/config-manager/config-manager-export-audit.ts new file mode 100644 index 000000000..6b85bae1f --- /dev/null +++ b/src/cli/config-manager/config-manager-export-audit.ts @@ -0,0 +1,44 @@ +import { configManagerExportAudit } from '../../configManagerOps/FrConfigAuditOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export audit', + [], + deploymentTypes + ); + + program + .description('Export audit objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity audit'); + const outcome = await configManagerExportAudit(options.envFile); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-authentication.ts b/src/cli/config-manager/config-manager-export-authentication.ts new file mode 100644 index 000000000..eb2065199 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-authentication.ts @@ -0,0 +1,54 @@ +import { Option } from 'commander'; + +import { configManagerExportAuthentication } from '../../configManagerOps/FrConfigAuthenticationOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export authentication', + [], + deploymentTypes + ); + + 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, + realm, + user, + password, + options, + command + ); + if (options.realm) { + realm = options.realm; + } + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity authentication'); + const outcome = await configManagerExportAuthentication(realm); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-authz-policies.ts b/src/cli/config-manager/config-manager-export-authz-policies.ts new file mode 100644 index 000000000..3e0608acd --- /dev/null +++ b/src/cli/config-manager/config-manager-export-authz-policies.ts @@ -0,0 +1,172 @@ +import { frodo, state } from '@rockcarver/frodo-lib'; +import { Option } from 'commander'; + +import { + configManagerExportAuthzPoliciesAll, + configManagerExportAuthzPolicySet, + configManagerExportAuthzPolicySets, + configManagerExportAuthzPolicySetsRealm, +} from '../../configManagerOps/FrConfigAuthzPoliciesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; +const { constants } = frodo.utils; +const { readRealms } = frodo.realm; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export authz-policies', + deploymentTypes + ); + + 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"' + ) + ) + .addHelpText( + 'after', + 'HELP MESSAGE:\n' + + 'Make sure to create the export config file: authz-policies.json to run this command.\n' + + 'Example command: frodo config-manager export authz-policies -f authz-policies.json -D ../testDir frodo-dev\n\n' + + `Config file example:\n` + + '----------------------- Example authz policies export config for authz-policies.json file ------------------------\n' + + '{\n' + + ' "alpha": [ \n' + + ' "oauth2Scopes", \n' + + ' "EdgePolicySet",\n' + + ' "FeatureStorePolicySet",\n' + + ' "data",\n' + + ' "test-policy-set"\n' + + ' ],\n' + + ' "bravo": [\n' + + ' "oauth2Scopes",\n' + + ' "murphyTestPolicySet"\n' + + ' ]\n' + + '}\n' + + '* -------------------------------------------------------------------------------------------- \n' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + 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; + } + } + + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-connector-definitions.ts b/src/cli/config-manager/config-manager-export-connector-definitions.ts new file mode 100644 index 000000000..f5c36c957 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-connector-definitions.ts @@ -0,0 +1,65 @@ +import { Option } from 'commander'; + +import { + configManagerExportConnectorDefinition, + configManagerExportConnectorDefinitionsAll, +} from '../../configManagerOps/FrConfigConnectorDefinitionsOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export connector-definitions', + [], + deploymentTypes + ); + + program + .description('Export aconnector definitions.') + .addOption( + new Option( + '-n, --name ', + 'Get connector-definition from specified name/id, without the type prefix.' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + let outcome: boolean; + if (options.name) { + printMessage( + `Exporting connector definition for connector: "${options.name}"` + ); + outcome = await configManagerExportConnectorDefinition({ + connectorName: options.name, + }); + } else { + printMessage('Exporting all connector defitions.'); + outcome = await configManagerExportConnectorDefinitionsAll(); + } + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-connector-mappings.ts b/src/cli/config-manager/config-manager-export-connector-mappings.ts new file mode 100644 index 000000000..b7a72ee6b --- /dev/null +++ b/src/cli/config-manager/config-manager-export-connector-mappings.ts @@ -0,0 +1,44 @@ +import { configManagerExportMappings } from '../../configManagerOps/FrConfigConnectorMappingOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export connector-mappings', + [], + deploymentTypes + ); + + program + .description('Get connector mappings.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting connector mappings'); + const outcome = await configManagerExportMappings(); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-cookie-domains.ts b/src/cli/config-manager/config-manager-export-cookie-domains.ts new file mode 100644 index 000000000..02884b9e6 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-cookie-domains.ts @@ -0,0 +1,44 @@ +import { configManagerExportCookieDomains } from '../../configManagerOps/FrConfigCookieDomainsOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export cookie-domains', + [], + deploymentTypes + ); + + program + .description('Export cookie-domains objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity cookie-domains'); + const outcome = await configManagerExportCookieDomains(); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-cors.ts b/src/cli/config-manager/config-manager-export-cors.ts new file mode 100644 index 000000000..13f1f438c --- /dev/null +++ b/src/cli/config-manager/config-manager-export-cors.ts @@ -0,0 +1,44 @@ +import { configManagerExportCors } from '../../configManagerOps/FrConfigCorsOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export cors', + [], + deploymentTypes + ); + + program + .description('Export CORS configuration.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting CORS configuration'); + const outcome = await configManagerExportCors(); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-csp.ts b/src/cli/config-manager/config-manager-export-csp.ts new file mode 100644 index 000000000..e56a0c82a --- /dev/null +++ b/src/cli/config-manager/config-manager-export-csp.ts @@ -0,0 +1,69 @@ +import { Option } from 'commander'; + +import { configManagerExportCsp } from '../../configManagerOps/FrConfigCspOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export cps', + [], + deploymentTypes + ); + + program + .description('Export content security policy.') + .addOption( + new Option( + '-f, --file ', + 'The CSP_OVERRIDES json file. ex: "/home/trivir/Documents/csp-overrides.json", or "csp-overrides.json"' + ) + ) + .addHelpText( + 'after', + 'There is an option to overrides the export file.\n' + + '----------------------- Example CSP_OVERRIDES json file ---------------------------------- \n' + + '{\n' + + ' "enforced": {\n' + + ' "active": {\n' + + ' "$bool": "${CSP_ENFORCED}"\n' + + ' }\n' + + ' },\n' + + ' "report-only": {\n' + + '"active": {\n' + + '"$bool": "${CSP_REPORT_ONLY}"\n' + + '}\n' + + ' }\n' + + '}\n' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting content security policy'); + const outcome = await configManagerExportCsp(options.file); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-email-provider.ts b/src/cli/config-manager/config-manager-export-email-provider.ts new file mode 100644 index 000000000..5b6a5e3c7 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-email-provider.ts @@ -0,0 +1,44 @@ +import { configManagerExportEmailProviderConfiguration } from '../../configManagerOps/FrConfigEmailProviderOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export email-provider', + [], + deploymentTypes + ); + + program + .description('Export email provider configuration.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting email provider configuration'); + const outcome = await configManagerExportEmailProviderConfiguration(); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-email-templates.ts b/src/cli/config-manager/config-manager-export-email-templates.ts new file mode 100644 index 000000000..e2e17d159 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-email-templates.ts @@ -0,0 +1,52 @@ +import { Option } from 'commander'; + +import { configManagerExportEmailTemplates } from '../../configManagerOps/FrConfigEmailTemplatesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export email-templates', + [], + deploymentTypes + ); + + program + .description('Export email-templates objects.') + .addOption( + new Option( + '-n, --name ', + 'Email-templates name, It only export the endpoint with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity email-templates'); + const outcome = await configManagerExportEmailTemplates(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-endpoints.ts b/src/cli/config-manager/config-manager-export-endpoints.ts new file mode 100644 index 000000000..2e1b801fd --- /dev/null +++ b/src/cli/config-manager/config-manager-export-endpoints.ts @@ -0,0 +1,52 @@ +import { Option } from 'commander'; + +import { configManagerExportEndpoints } from '../../configManagerOps/FrConfigEndpointsOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export endpoints', + [], + deploymentTypes + ); + + program + .description('Export custom endpoints objects.') + .addOption( + new Option( + '-n, --name ', + 'Endpoint name, It only export the endpoint with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity endpoints'); + const outcome = await configManagerExportEndpoints(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-internal-roles.ts b/src/cli/config-manager/config-manager-export-internal-roles.ts new file mode 100644 index 000000000..c7c45d384 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-internal-roles.ts @@ -0,0 +1,53 @@ +import { Option } from 'commander'; + +import { configManagerExportInternalRoles } from '../../configManagerOps/FrConfigInternalRolesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export internal-roles', + [], + deploymentTypes + ); + + program + + .description('Export internal roles in fr-config-manager style.') + .addOption( + new Option( + '-n, --name ', + 'Internal role name, It only export the endpoint with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting internal roles'); + const outcome = await configManagerExportInternalRoles(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-journeys.ts b/src/cli/config-manager/config-manager-export-journeys.ts new file mode 100644 index 000000000..c4bb74f61 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-journeys.ts @@ -0,0 +1,70 @@ +import { Option } from 'commander'; + +import { configManagerExportJourneys } from '../../configManagerOps/FrConfigJourneysOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export journeys', + [], + deploymentTypes + ); + + program + .description('Export journeys.') + .addOption( + new Option( + '-n, --name ', + '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( + // new Option('-c, --clean', 'Clear existing configuration before pull.') + // ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + if (options.realm) { + realm = options.realm; + } + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity journeys'); + const outcome = await configManagerExportJourneys( + options.name, + realm, + options.pullDependencies + ); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-kba.ts b/src/cli/config-manager/config-manager-export-kba.ts new file mode 100644 index 000000000..8207fae9c --- /dev/null +++ b/src/cli/config-manager/config-manager-export-kba.ts @@ -0,0 +1,44 @@ +import { configManagerExportKbaConfig } from '../../configManagerOps/FrConfigKbaOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export kba', + [], + deploymentTypes + ); + + program + .description('Export kba-config objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity kba-config'); + const outcome = await configManagerExportKbaConfig(options.envFile); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-locales.ts b/src/cli/config-manager/config-manager-export-locales.ts new file mode 100644 index 000000000..8c6c90a55 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-locales.ts @@ -0,0 +1,52 @@ +import { Option } from 'commander'; + +import { configManagerExportLocales } from '../../configManagerOps/FrConfigLocalesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export locales', + [], + deploymentTypes + ); + + program + .description('Export custom locales objects.') + .addOption( + new Option( + '-n, --name ', + 'locale name, It only export the locale with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity locales'); + const outcome = await configManagerExportLocales(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-managed-objects.ts b/src/cli/config-manager/config-manager-export-managed-objects.ts new file mode 100644 index 000000000..a1fc202d4 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-managed-objects.ts @@ -0,0 +1,52 @@ +import { Option } from 'commander'; + +import { configManagerExportManagedObjects } from '../../configManagerOps/FrConfigManagedObjectsOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export managed-objects', + [], + deploymentTypes + ); + + program + .description('Export managed-objects.') + .addOption( + new Option( + '-n, --name ', + 'Endpoint name, It only export the endpoint with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity managed-objects'); + const outcome = await configManagerExportManagedObjects(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-oauth2-agents.ts b/src/cli/config-manager/config-manager-export-oauth2-agents.ts new file mode 100644 index 000000000..6dc534fcc --- /dev/null +++ b/src/cli/config-manager/config-manager-export-oauth2-agents.ts @@ -0,0 +1,183 @@ +import { frodo, state } from '@rockcarver/frodo-lib'; +import { Option } from 'commander'; + +import { + configManagerExportAgent, + configManagerExportAgentsAll, + configManagerExportAgentsRealm, + configManagerExportConfigAgents, +} from '../../configManagerOps/FrConfigOauth2AgentOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; +const { constants } = frodo.utils; +const { readRealms } = frodo.realm; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export oauth2-agents', + deploymentTypes + ); + + 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 ', + 'The OAUTH2_AGENTS_CONFIG json file. ex: "/home/trivir/Documents/oauth2-agents.json", or "oauth2-agents.json"' + ) + ) + .addHelpText( + 'after', + 'HELP MESSAGE:\n' + + 'Make sure to create the export config file: oauth2-agents.json to run this command.\n' + + 'Example command: frodo config-manager export oauth2-agents -f oauth2-agents.json -D ../testDir frodo-dev\n\n' + + `Config file example:\n` + + '------------ Example Oauth2 agents export config for oauth2-agents.json file -----------\n' + + '{\n' + + ' "alpha": {\n' + + ' "2.2_Agent": [\n' + + ' {"id": "my-policy-agent"}\n' + + ' ],\n' + + ' "RemoteConsentAgent": [\n' + + ' {"id": "test", "overrides":{"testestest": "hotdog"}}\n' + + ' ],\n' + + ' "SoftwarePublisher": [\n' + + ' {"id": "test software publisher"}\n' + + ' ],\n' + + ' "IdentityGatewayAgent": [\n' + + ' {"id": "cdsso-ig-agent"},\n' + + ' {"id": "frodo-test-ig-agent"},\n' + + ' {"id": "frodo-test-ig-agent2"},\n' + + ' {"id": "ig-agent", "overrides": {"yes": "no, not yes", "taco":"sandwich"}}\n' + + ' ],\n' + + ' "J2EEAgent": [\n' + + ' {"id": "frodo-test-java-agent"},\n' + + ' {"id": "frodo-test-java-agent2"}\n' + + ' ],\n' + + ' "WebAgent": [\n' + + ' {"id": "frodo-test-web-agent"},\n' + + ' {"id": "frodo-test-web-agent2"}\n' + + ' ]\n' + + ' }\n' + + '}\n' + + '* -------------------------------------------------------------------------------------------- \n' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + 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; + } + } + + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-org-privileges.ts b/src/cli/config-manager/config-manager-export-org-privileges.ts new file mode 100644 index 000000000..19846099b --- /dev/null +++ b/src/cli/config-manager/config-manager-export-org-privileges.ts @@ -0,0 +1,76 @@ +import { frodo } from '@rockcarver/frodo-lib'; +import { Option } from 'commander'; + +import { + configManagerExportOrgPrivileges, + configManagerExportOrgPrivilegesAllRealms, + configManagerExportOrgPrivilegesRealm, +} from '../../configManagerOps/FrConfigOrgPrivilegesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; +const { constants } = frodo.utils; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export org-privileges', + [], + deploymentTypes + ); + + 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, + realm, + user, + password, + options, + 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(); + } + + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-password-policy.ts b/src/cli/config-manager/config-manager-export-password-policy.ts new file mode 100644 index 000000000..896bde54d --- /dev/null +++ b/src/cli/config-manager/config-manager-export-password-policy.ts @@ -0,0 +1,54 @@ +import { Option } from 'commander'; + +import { configManagerExportPasswordPolicy } from '../../configManagerOps/FrConfigPasswordPolicyOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export password-policy', + [], + deploymentTypes + ); + + 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, + realm, + user, + password, + 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); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-raw.ts b/src/cli/config-manager/config-manager-export-raw.ts new file mode 100644 index 000000000..b6bd7751f --- /dev/null +++ b/src/cli/config-manager/config-manager-export-raw.ts @@ -0,0 +1,81 @@ +import { Option } from 'commander'; + +import { configManagerExportRaw } from '../../configManagerOps/FrConfigRawOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export raw', + [], + deploymentTypes + ); + + program + .description('Export raw configurations from the tenant.') + .addOption( + new Option( + '-f, --config-file ', + 'The file path of the service object config file. ' + ) + ) + .addHelpText( + 'after', + 'HELP MESSAGE:\n' + + 'Make sure to create an export config file: raw.json to run this command.\n' + + 'Example command: frodo config-manager export raw -f raw.json -D ../testDir frodo-dev\n\n' + + `Config file example:\n` + + '------------ Example Oauth2 agents export config for oauth2-agents.json file -----------\n' + + '[\n' + + ' { "path": "/openidm/config/authentication" },\n' + + ' {\n' + + ' "path": "/am/json/realms/root/realms/alpha/realm-config/webhooks/test-webhook",\n' + + ' "overrides": { "url": "${TEST_WEBHOOK_URL}" },\n' + + ' "pushApiVersion": {\n' + + ' "protocol": "2.0",\n' + + ' "resource": "1.0"\n' + + ' }\n' + + ' },\n' + + ' {"path": "/environment/release"}\n' + + '] \n' + + '* -------------------------------------------------------------------------------------------- \n' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + const outcome: boolean = await configManagerExportRaw( + options.configFile + ); + + if (!outcome) { + printMessage( + `Failed to export one or more config files. ${options.verbose ? '' : 'Check --verbose for me details.'}` + ); + process.exitCode = 1; + } + } + + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-remote-servers.ts b/src/cli/config-manager/config-manager-export-remote-servers.ts new file mode 100644 index 000000000..1a860d7b6 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-remote-servers.ts @@ -0,0 +1,44 @@ +import { configManagerExportRemoteServers } from '../../configManagerOps/FrConfigRemoteServersOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export remote-servers', + [], + deploymentTypes + ); + + program + .description('Export remote-servers objects.') + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity remote-servers'); + const outcome = await configManagerExportRemoteServers(options.envFile); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-saml.ts b/src/cli/config-manager/config-manager-export-saml.ts new file mode 100644 index 000000000..f5c3f899c --- /dev/null +++ b/src/cli/config-manager/config-manager-export-saml.ts @@ -0,0 +1,81 @@ +import { Option } from 'commander'; + +import { configManagerExportSaml } from '../../configManagerOps/FrConfigSamlOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export saml', + [], + deploymentTypes + ); + + program + .description('Export saml.') + .addOption( + new Option('-f, --file ', 'The file path of the SAML config file. ') + ) + .addHelpText( + 'after', + 'HELP MESSAGE:\n' + + 'Make sure to create the export config file: saml.json to run this command.\n' + + 'Example command: frodo config-manager export saml -f saml.json -D ../testDir frodo-dev\n\n' + + `Config file example:\n` + + '----------------------- Example SAML export config for saml.json file ------------------------\n' + + '{\n' + + ' "alpha": {\n' + + ' "samlProviders": [\n' + + ' {\n' + + ' "entityId": "urn:federation:MicrosoftOnline",\n' + + ' "fileName": "microsoftOnline"\n' + + ' },\n' + + ' {\n' + + ' "entityId": "iSPAzure",\n' + + ' "replacements": [\n' + + ' {\n' + + ' "search": "https://idc.scheuber.io/am",\n' + + ' "replacement": "${TENANT_BASE_URL}"\n' + + ' }\n' + + ' ]\n' + + ' }\n' + + ' ],\n' + + ' "circlesOfTrust": ["AzureCOT", "affiliation-test"]\n' + + ' }\n' + + '}\n' + + '* -------------------------------------------------------------------------------------------- \n' + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + if (options.realm) { + realm = options.realm; + } + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting config entity saml'); + const outcome = await configManagerExportSaml(options.file); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-schedules.ts b/src/cli/config-manager/config-manager-export-schedules.ts new file mode 100644 index 000000000..e763bf802 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-schedules.ts @@ -0,0 +1,53 @@ +import { Option } from 'commander'; + +import { configManagerExportSchedules } from '../../configManagerOps/FrConfigSchedulesOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage, verboseMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud', 'forgeops']; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export schedules', + [], + deploymentTypes + ); + + program + + .description('Export schedules in fr-config-manager style.') + .addOption( + new Option( + '-n, --name ', + 'schedule name, It only export the endpoint with the name' + ) + ) + .action(async (host, realm, user, password, options, command) => { + command.handleDefaultArgsAndOpts( + host, + realm, + user, + password, + options, + command + ); + + if (await getTokens(false, true, deploymentTypes)) { + verboseMessage('Exporting schedules'); + const outcome = await configManagerExportSchedules(options.name); + if (!outcome) process.exitCode = 1; + } + // unrecognized combination of options or no options + else { + printMessage( + 'Unrecognized combination of options or no options...', + 'error' + ); + program.help(); + process.exitCode = 1; + } + }); + + return program; +} diff --git a/src/cli/config-manager/config-manager-export-scripts.ts b/src/cli/config-manager/config-manager-export-scripts.ts new file mode 100644 index 000000000..f7374ca79 --- /dev/null +++ b/src/cli/config-manager/config-manager-export-scripts.ts @@ -0,0 +1,212 @@ +import { frodo, state } from '@rockcarver/frodo-lib'; +import { Option } from 'commander'; + +import { + configManagerExportScript, + configManagerExportScriptsAll, + configManagerExportScriptsRealms, +} from '../../configManagerOps/FrConfigScriptOps'; +import { getTokens } from '../../ops/AuthenticateOps'; +import { printMessage } from '../../utils/Console'; +import { FrodoCommand } from '../FrodoCommand'; + +const deploymentTypes = ['cloud']; +const { constants } = frodo.utils; +const { readRealms } = frodo.realm; + +export default function setup() { + const program = new FrodoCommand( + 'frodo config-manager export scripts', + deploymentTypes + ); + + 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