forked from rockcarver/frodo-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add config-manager idm-authentication commands #123
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/cli/config-manager/config-manager-pull/config-manager-pull-idm-authentication.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
|
|
||
| import { configManagerExportIdmAuthentication } from '../../../configManagerOps/FrConfigIdmAuthenticationOpts'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
| import { verboseMessage } from '../../../utils/Console'; | ||
| import { FrodoCommand } from '../../FrodoCommand'; | ||
|
|
||
| const { CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY } = | ||
| frodo.utils.constants; | ||
|
|
||
| const deploymentTypes = [ | ||
| CLOUD_DEPLOYMENT_TYPE_KEY, | ||
| FORGEOPS_DEPLOYMENT_TYPE_KEY, | ||
| ]; | ||
|
|
||
| export default function setup() { | ||
| const program = new FrodoCommand( | ||
| 'frodo config-manager pull idm-authentication', | ||
| [], | ||
| deploymentTypes | ||
| ); | ||
|
|
||
| program | ||
| .description('Export idm authentication config.') | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
| realm, | ||
| user, | ||
| password, | ||
| options, | ||
| command | ||
| ); | ||
|
|
||
| const getTokensIsSuccessful = await getTokens( | ||
| false, | ||
| true, | ||
| deploymentTypes | ||
| ); | ||
| if (!getTokensIsSuccessful) process.exit(1); | ||
| verboseMessage('Exporting idm authentication configuration.'); | ||
| const outcome = await configManagerExportIdmAuthentication(); | ||
| if (!outcome) process.exitCode = 1; | ||
| }); | ||
|
|
||
| return program; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/cli/config-manager/config-manager-push/config-manager-push-idm-authentication.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
|
|
||
| import { configManagerImportIdmAuthentication } from '../../../configManagerOps/FrConfigIdmAuthenticationOpts'; | ||
| import { getTokens } from '../../../ops/AuthenticateOps'; | ||
| import { verboseMessage } from '../../../utils/Console'; | ||
| import { FrodoCommand } from '../../FrodoCommand'; | ||
|
|
||
| const { CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY } = | ||
| frodo.utils.constants; | ||
|
|
||
| const deploymentTypes = [ | ||
| CLOUD_DEPLOYMENT_TYPE_KEY, | ||
| FORGEOPS_DEPLOYMENT_TYPE_KEY, | ||
| ]; | ||
|
|
||
| export default function setup() { | ||
| const program = new FrodoCommand( | ||
| 'frodo config-manager push idm-authentication', | ||
| [], | ||
| deploymentTypes | ||
| ); | ||
|
|
||
| program | ||
| .description('Import idm authentication.') | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
| realm, | ||
| user, | ||
| password, | ||
| options, | ||
| command | ||
| ); | ||
|
|
||
| const getTokensIsSuccessful = await getTokens( | ||
| false, | ||
| true, | ||
| deploymentTypes | ||
| ); | ||
| if (!getTokensIsSuccessful) process.exit(1); | ||
| verboseMessage('Importing idm authentication configuration.'); | ||
| const outcome = await configManagerImportIdmAuthentication(); | ||
| if (!outcome) process.exitCode = 1; | ||
| }); | ||
|
|
||
| return program; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { frodo } from '@rockcarver/frodo-lib'; | ||
| import { IdObjectSkeletonInterface } from '@rockcarver/frodo-lib/types/api/ApiTypes'; | ||
|
|
||
| import { printError } from '../utils/Console'; | ||
|
|
||
| const { readConfigEntity, updateConfigEntity } = frodo.idm.config; | ||
| const { getFilePath, saveJsonToFile, readJsonFile } = frodo.utils; | ||
|
|
||
| /** | ||
| * Export Idm authentication configuration in fr-config-manager format. | ||
| * @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise | ||
| */ | ||
| export async function configManagerExportIdmAuthentication(): Promise<boolean> { | ||
| try { | ||
| const exportData = await readConfigEntity('authentication'); | ||
| saveJsonToFile( | ||
| exportData, | ||
| getFilePath('idm-authentication-config/authentication.json', true), | ||
| false | ||
| ); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error, `Error exporting config entity selfservice.kba`); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Import Idm authentication configuration in fr-config-manager format. | ||
| * @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise | ||
| */ | ||
| export async function configManagerImportIdmAuthentication(): Promise<boolean> { | ||
| try { | ||
| const filePath = getFilePath( | ||
| 'idm-authentication-config/authentication.json' | ||
| ); | ||
| const config = readJsonFile(filePath) as IdObjectSkeletonInterface; | ||
| await updateConfigEntity(config._id, config); | ||
| return true; | ||
| } catch (error) { | ||
| printError(error); | ||
| } | ||
| return false; | ||
| } |
29 changes: 29 additions & 0 deletions
29
test/client_cli/en/__snapshots__/config-manager-pull-idm-authentication.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CLI help interface for 'config-manager pull idm-authentication' should be expected english 1`] = ` | ||
| "Usage: frodo config-manager pull idm-authentication [options] [host] [realm] [username] [password] | ||
|
|
||
| [Experimental] Export idm authentication config. | ||
|
|
||
| Arguments: | ||
| host AM base URL, e.g.: https://cdk.iam.example.com/am. To use a | ||
| connection profile, just specify a unique substring or | ||
| alias. | ||
| realm Realm. Specify realm as '/' for the root realm or 'realm' or | ||
| '/parent/child' otherwise. (default: "alpha" for Identity | ||
| Cloud tenants, "/" otherwise.) | ||
| username Username to login with. Must be an admin user with | ||
| appropriate rights to manage authentication journeys/trees. | ||
| If given without a password, and it matches the username | ||
| already stored in the connection profile for the target | ||
| host, frodo uses that profile's stored password instead of | ||
| requiring it on the command line. | ||
| password Password. | ||
|
|
||
| Options: | ||
| -h, --help Help | ||
| -hh, --help-more Help with all options. | ||
| -hhh, --help-all Help with all options, environment variables, and usage | ||
| examples. | ||
| " | ||
| `; |
61 changes: 61 additions & 0 deletions
61
test/client_cli/en/__snapshots__/config-manager-pull.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CLI help interface for 'config-manager pull' should be expected english 1`] = ` | ||
| "Usage: frodo config-manager pull [options] [command] | ||
|
|
||
| [Experimental] Export configuration optimized for CI/CD pipelines (format | ||
| compatible with fr-config-manager). | ||
|
|
||
| Options: | ||
| -h, --help Help | ||
| -hh, --help-more Help with all options. | ||
| -hhh, --help-all Help with all options, environment variables, and usage | ||
| examples. | ||
|
|
||
| Commands: | ||
| access-config [Experimental] Export access-config objects. | ||
| all [Experimental] Export all config. | ||
| all-static [Experimental] Export all static config. | ||
| audit [Experimental] Export audit objects. | ||
| authentication [Experimental] Export authentication objects. | ||
| authz-policies [Experimental] Export authorization policies from | ||
| realm. | ||
| connector-definitions [Experimental] Export aconnector definitions. | ||
| connector-mappings [Experimental] Export connector mappings. | ||
| cookie-domains [Experimental] Export cookie-domains objects. | ||
| cors [Experimental] Export CORS configuration. | ||
| csp [Experimental] Export content security policy. | ||
| custom-nodes [Experimental] Export custom nodes. | ||
| email-provider [Experimental] Export email provider configuration. | ||
| email-templates [Experimental] Export email-templates objects. | ||
| endpoints [Experimental] Export custom endpoints objects. | ||
| help display help for command | ||
| idm-authentication [Experimental] Export idm authentication config. | ||
| internal-roles [Experimental] Export internal roles. | ||
| journeys [Experimental] Export journeys. | ||
| kba [Experimental] Export kba-config objects. | ||
| locales [Experimental] Export custom locales objects. | ||
| managed-objects [Experimental] Export managed-objects. | ||
| oauth2-agents [Experimental] Export OAuth2 Agents | ||
| org-privileges [Experimental] Export organization privileges config. | ||
| password-policy [Experimental] Export password-policy objects. | ||
| raw [Experimental] Export raw configurations from the | ||
| tenant. | ||
| remote-servers [Experimental] Export remote-servers objects. | ||
| saml [Experimental] Export saml. | ||
| schedules [Experimental] Export schedules. | ||
| scripts [Experimental] Export authorization scripts. | ||
| secret-mappings [Experimental] Export secret mappings. | ||
| secrets [Experimental] Export secrets. | ||
| service-objects [Experimental] Export service objects. | ||
| services [Experimental] Export authentication services. | ||
| terms-and-conditions [Experimental] Export terms and conditions. | ||
| test [Experimental] Test connection and authentication. | ||
| themes [Experimental] Export themes. | ||
| ui-config [Experimental] Export ui-configuration objects. | ||
| variables [Experimental] Export variables objects. | ||
|
|
||
| (Cloud-only): | ||
| iga-workflows [Experimental] Export iga-workflows. | ||
| " | ||
| `; |
29 changes: 29 additions & 0 deletions
29
test/client_cli/en/__snapshots__/config-manager-push-idm-authentication.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CLI help interface for 'config-manager push idm-authentication' should be expected english 1`] = ` | ||
| "Usage: frodo config-manager push idm-authentication [options] [host] [realm] [username] [password] | ||
|
|
||
| [Experimental] Import idm authentication. | ||
|
|
||
| Arguments: | ||
| host AM base URL, e.g.: https://cdk.iam.example.com/am. To use a | ||
| connection profile, just specify a unique substring or | ||
| alias. | ||
| realm Realm. Specify realm as '/' for the root realm or 'realm' or | ||
| '/parent/child' otherwise. (default: "alpha" for Identity | ||
| Cloud tenants, "/" otherwise.) | ||
| username Username to login with. Must be an admin user with | ||
| appropriate rights to manage authentication journeys/trees. | ||
| If given without a password, and it matches the username | ||
| already stored in the connection profile for the target | ||
| host, frodo uses that profile's stored password instead of | ||
| requiring it on the command line. | ||
| password Password. | ||
|
|
||
| Options: | ||
| -h, --help Help | ||
| -hh, --help-more Help with all options. | ||
| -hhh, --help-all Help with all options, environment variables, and usage | ||
| examples. | ||
| " | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/client_cli/en/config-manager-pull-idm-authentication.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import cp from 'child_process'; | ||
| import { promisify } from 'util'; | ||
|
|
||
| const exec = promisify(cp.exec); | ||
| const CMD = 'frodo config-manager pull idm-authentication --help'; | ||
| const { stdout } = await exec(CMD); | ||
|
|
||
| test("CLI help interface for 'config-manager pull idm-authentication' should be expected english", async () => { | ||
| expect(stdout).toMatchSnapshot(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import cp from 'child_process'; | ||
| import { promisify } from 'util'; | ||
|
|
||
| const exec = promisify(cp.exec); | ||
| const CMD = 'frodo config-manager pull --help'; | ||
| const { stdout } = await exec(CMD); | ||
|
|
||
| test("CLI help interface for 'config-manager pull' should be expected english", async () => { | ||
| expect(stdout).toMatchSnapshot(); | ||
| }); |
10 changes: 10 additions & 0 deletions
10
test/client_cli/en/config-manager-push-idm-authentication.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import cp from 'child_process'; | ||
| import { promisify } from 'util'; | ||
|
|
||
| const exec = promisify(cp.exec); | ||
| const CMD = 'frodo config-manager push idm-authentication --help'; | ||
| const { stdout } = await exec(CMD); | ||
|
|
||
| test("CLI help interface for 'config-manager push idm-authentication' should be expected english", async () => { | ||
| expect(stdout).toMatchSnapshot(); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.