Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CustomNodes from './config-manager-pull-custom-nodes';
import EmailProvider from './config-manager-pull-email-provider';
import EmailTemplates from './config-manager-pull-email-templates';
import Endpoints from './config-manager-pull-endpoints';
import IdmAuthentication from './config-manager-pull-idm-authentication';
import IgaWorkflows from './config-manager-pull-iga-workflows';
import InternalRoles from './config-manager-pull-internal-roles';
import Journeys from './config-manager-pull-journeys';
Expand Down Expand Up @@ -58,6 +59,7 @@ export default function setup() {
program.addCommand(EmailProvider().name('email-provider'));
program.addCommand(EmailTemplates().name('email-templates'));
program.addCommand(Endpoints().name('endpoints'));
program.addCommand(IdmAuthentication().name('idm-authentication'));
program.addCommand(InternalRoles().name('internal-roles'));
program.addCommand(Journeys().name('journeys'));
program.addCommand(Kba().name('kba'));
Expand Down
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CustomNodes from './config-manager-push-custom-nodes';
import EmailProvider from './config-manager-push-email-provider';
import EmailTemplates from './config-manager-push-email-templates';
import Endpoints from './config-manager-push-endpoints';
import IdmAuthentication from './config-manager-push-idm-authentication';
import IgaWorkflows from './config-manager-push-iga-workflows';
import InternalRoles from './config-manager-push-internal-roles';
import Journeys from './config-manager-push-journeys';
Expand Down Expand Up @@ -42,6 +43,7 @@ export default function setup() {
program.addCommand(Kba().name('kba'));
program.addCommand(InternalRoles().name('internal-roles'));
program.addCommand(IgaWorkflows().name('iga-workflows'));
program.addCommand(IdmAuthentication().name('idm-authentication'));
program.addCommand(EmailTemplates().name('email-templates'));
program.addCommand(Schedules().name('schedules'));
program.addCommand(OrgPrivileges().name('org-privileges'));
Expand Down
44 changes: 44 additions & 0 deletions src/configManagerOps/FrConfigIdmAuthenticationOpts.ts
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;
}
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 test/client_cli/en/__snapshots__/config-manager-pull.test.js.snap
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.
"
`;
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.
"
`;
Comment thread
dallinjsevy marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Commands:
email-templates [Experimental] Import email template objects.
endpoints [Experimental] Import custom endpoints objects.
help display help for command
idm-authentication [Experimental] Import idm authentication.
internal-roles [Experimental] Import internal roles.
journeys [Experimental] Import journeys.
kba [Experimental] Import kba configuration.
Expand Down
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-pull-idm-authentication.test.js
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();
});
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-pull.test.js
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 test/client_cli/en/config-manager-push-idm-authentication.test.js
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();
});
Loading