Skip to content
Open
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,52 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { configManagerImportRaw } from '../../../configManagerOps/FrConfigRawOps';
import { getTokens } from '../../../ops/AuthenticateOps';
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 raw',
[],
deploymentTypes
);

program
.description('Import raw configurations to the tenant.')
Comment thread
dallinjsevy marked this conversation as resolved.
.addOption(
new Option(
'-p, --config-path <path>',
'The path of the service object config file. '
)
)
Comment thread
dallinjsevy marked this conversation as resolved.
Comment thread
dallinjsevy marked this conversation as resolved.

.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 configManagerImportRaw(options.path);

if (!outcome) {
process.exitCode = 1;
}
}
});

return program;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Locales from './config-manager-push-locales';
import ManagedObjects from './config-manager-push-managed-objects';
import OrgPrivileges from './config-manager-push-org-privileges';
import PasswordPolicy from './config-manager-push-password-policy';
import Raw from './config-manager-push-raw';
import Schedules from './config-manager-push-schedules';
import ServiceObjects from './config-manager-push-service-objects';
import TermsAndConditions from './config-manager-push-terms-and-conditions';
Expand Down Expand Up @@ -43,6 +44,6 @@ export default function setup() {
program.addCommand(UiConfig().name('ui-config'));
program.addCommand(Authentication().name('authentication'));
program.addCommand(ConnectorDefinitions().name('connector-definitions'));

program.addCommand(Raw().name('raw'));
return program;
}
74 changes: 73 additions & 1 deletion src/configManagerOps/FrConfigRawOps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { frodo } from '@rockcarver/frodo-lib';
import { IdObjectSkeletonInterface } from '@rockcarver/frodo-lib/types/api/ApiTypes';
import fs from 'fs';
import { readFile } from 'fs/promises';

import { printError, verboseMessage } from '../utils/Console';

const { getFilePath, saveJsonToFile } = frodo.utils;
const { exportRawConfig } = frodo.rawConfig;
const { exportRawConfig, importRawConfig } = frodo.rawConfig;

/**
* Export every item from the list in the provided json file
Expand Down Expand Up @@ -33,3 +34,74 @@ export async function configManagerExportRaw(file: string): Promise<boolean> {
return false;
}
}

/**
* Import all raw configuration exported in fr-config-manager format
* @param path optional flag to provide path to service config file
* @returns {Promise<boolean>} true if each file was successfully imported
*/
export async function configManagerImportRaw(path?: string): Promise<boolean> {
try {
const rawDir = getFilePath('raw/');
if (path) {
const filePath = getFilePath(`raw/${path}.json`);
const rawPath = path;
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
if (data.result && Array.isArray(data.result)) {
for (const item of data.result) {
const itemPath = `${rawPath}/${item._id}`;
delete item._rev;
delete item._type;
await importRawConfig({ path: itemPath }, item);
}
} else {
delete data._rev;
delete data._type;
await importRawConfig({ path: rawPath }, data);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is rawPath the correct value for path? It seems importRawConfig expects path to be the URL path to the resource rather than the path to the config file.

}
} else {
const files = getJsonFiles(rawDir);
for (const filePath of files) {
const rawPath = filePath
.replace(rawDir, '')
.replace(/^\//, '')
.replace(/\.json$/, '');
const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
if (data.result && Array.isArray(data.result)) {
for (const item of data.result) {
const itemPath = `${rawPath}/${item._id}`;
delete item._rev;
delete item._type;
await importRawConfig({ path: itemPath }, item);
}
} else {
delete data._rev;
delete data._type;
await importRawConfig({ path: rawPath }, data);
}
}
}
return true;
} catch (error) {
printError(error);
return false;
}
}

/**
* Recursively walks a directory tree and returns the full paths of all .json files found.
* @param dir root directory to search
* @returns full paths of all .json files found
*/
function getJsonFiles(dir: string): string[] {
const results: string[] = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = `${dir}/${entry.name}`;
if (entry.isDirectory()) {
results.push(...getJsonFiles(full));
} else if (entry.name.endsWith('.json')) {
results.push(full);
}
}
return results;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI help interface for 'config-manager push raw' should be expected english 1`] = `
"Usage: frodo config-manager push raw [options] [host] [realm] [username] [password]

[Experimental] Import raw configurations to the tenant.

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.
password Password.

Options:
-p, --config-path <path> The path of the service object config file.
-h, --help Help
-hh, --help-more Help with all options.
-hhh, --help-all Help with all options, environment variables, and
usage examples.
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Commands:
managed-objects [Experimental] Import managed objects.
org-privileges [Experimental] Import organization privileges config.
password-policy [Experimental] Import password-policy objects.
raw [Experimental] Import raw configurations to the tenant.
schedules [Experimental] Import schedules.
service-objects [Experimental] Import service objects.
terms-and-conditions [Experimental] Import terms and conditions.
Expand Down
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-push-raw.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 raw --help';
const { stdout } = await exec(CMD);

test("CLI help interface for 'config-manager push raw' should be expected english", async () => {
expect(stdout).toMatchSnapshot();
});
29 changes: 29 additions & 0 deletions test/e2e/__snapshots__/config-manager-push-raw.e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`frodo config-manager push raw "frodo config-manager push raw -D test/e2e/exports/fr-config-manager/cloud: should import raw configuration into cloud" 1`] = `""`;

exports[`frodo config-manager push raw "frodo config-manager push raw -D test/e2e/exports/fr-config-manager/cloud: should import raw configuration into cloud" 2`] = `
"Experimental feature in use: 'frodo config-manager push raw'. This feature may change without notice.
"
`;

exports[`frodo config-manager push raw "frodo config-manager push raw -D test/e2e/exports/fr-config-manager/forgeops -m forgeops": should import raw configuration into forgeops" 1`] = `""`;

exports[`frodo config-manager push raw "frodo config-manager push raw -D test/e2e/exports/fr-config-manager/forgeops -m forgeops": should import raw configuration into forgeops" 2`] = `
"Experimental feature in use: 'frodo config-manager push raw'. This feature may change without notice.
"
`;

exports[`frodo config-manager push raw "frodo config-manager push raw -p test/e2e/exports/fr-config-manager/cloud/raw/environment -D test/e2e/exports/fr-config-manager/cloud: should import raw configuration into cloud" 1`] = `""`;

exports[`frodo config-manager push raw "frodo config-manager push raw -p test/e2e/exports/fr-config-manager/cloud/raw/environment -D test/e2e/exports/fr-config-manager/cloud: should import raw configuration into cloud" 2`] = `
"Experimental feature in use: 'frodo config-manager push raw'. This feature may change without notice.
"
`;

exports[`frodo config-manager push raw "frodo config-manager push raw -p test/e2e/exports/fr-config-manager/forgeops/raw/openidm/config -m forgeops": should import raw configuration into forgeops" 1`] = `""`;

exports[`frodo config-manager push raw "frodo config-manager push raw -p test/e2e/exports/fr-config-manager/forgeops/raw/openidm/config -m forgeops": should import raw configuration into forgeops" 2`] = `
"Experimental feature in use: 'frodo config-manager push raw'. This feature may change without notice.
"
`;
107 changes: 107 additions & 0 deletions test/e2e/config-manager-push-raw.e2e.test.js
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks off for this file, I would format it to look more like the other tests if possible or run lint on it (usually lint skips these files, so as long as it looks most normal we're good).

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Follow this process to write e2e tests for the CLI project:
*
* 1. Test if all the necessary mocks for your tests already exist.
* In mock mode, run the command you want to test with the same arguments
* and parameters exactly as you want to test it, for example:
*
* $ FRODO_MOCK=1 frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t!
*
* If your command completes without errors and with the expected results,
* all the required mocks already exist and you are good to write your
* test and skip to step #4.
*
* If, however, your command fails and you see errors like the one below,
* you know you need to record the mock responses first:
*
* [Polly] [adapter:node-http] Recording for the following request is not found and `recordIfMissing` is `false`.
*
* 2. Record mock responses for your exact command.
* In mock record mode, run the command you want to test with the same arguments
* and parameters exactly as you want to test it, for example:
*
* $ FRODO_MOCK=record frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t!
*
* Wait until you see all the Polly instances (mock recording adapters) have
* shutdown before you try to run step #1 again.
* Messages like these indicate mock recording adapters shutting down:
*
* Polly instance 'conn/4' stopping in 3s...
* Polly instance 'conn/4' stopping in 2s...
* Polly instance 'conn/save/3' stopping in 3s...
* Polly instance 'conn/4' stopping in 1s...
* Polly instance 'conn/save/3' stopping in 2s...
* Polly instance 'conn/4' stopped.
* Polly instance 'conn/save/3' stopping in 1s...
* Polly instance 'conn/save/3' stopped.
*
* 3. Validate your freshly recorded mock responses are complete and working.
* Re-run the exact command you want to test in mock mode (see step #1).
*
* 4. Write your test.
* Make sure to use the exact command including number of arguments and params.
*
* 5. Commit both your test and your new recordings to the repository.
* Your tests are likely going to reside outside the frodo-lib project but
* the recordings must be committed to the frodo-lib project.
*/

/*
// ForgeOps
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://nightly.gcp.forgeops.com/am frodo config-manager push raw -D test/e2e/exports/fr-config-manager/forgeops -m forgeops
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://nightly.gcp.forgeops.com/am frodo config-manager push raw -p test/e2e/exports/fr-config-manager/forgeops/raw/openidm/config -D test/e2e/exports/fr-config-manager/forgeops -m forgeops

// Cloud
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push raw -D test/e2e/exports/fr-config-manager/cloud
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push raw -p test/e2e/exports/fr-config-manager/cloud/raw/environment -D test/e2e/exports/fr-config-manager/cloud

*/
Comment thread
dallinjsevy marked this conversation as resolved.

import cp from 'child_process';
import { promisify } from 'util';
import { getEnv, removeAnsiEscapeCodes } from './utils/TestUtils';
import { forgeops_connection as fc } from './utils/TestConfig';
import { connection as c } from './utils/TestConfig';


const exec = promisify(cp.exec);

process.env['FRODO_MOCK'] = '1';
const forgeopsEnv = getEnv(fc);
const cloudEnv = getEnv(c)

const forgeopsDirectory = "test/e2e/exports/fr-config-manager/forgeops";
const cloudDirectory = "test/e2e/exports/fr-config-manager/cloud"

describe('frodo config-manager push raw ', () => {

//Forgeops

test(`"frodo config-manager push raw -D ${forgeopsDirectory} -m forgeops": should import raw configuration into forgeops"`, async () => {
const CMD = `frodo config-manager push raw -D ${forgeopsDirectory} -m forgeops`;
const { stdout, stderr } = await exec(CMD, forgeopsEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot()
});
test(`"frodo config-manager push raw -p test/e2e/exports/fr-config-manager/forgeops/raw/openidm/config -m forgeops": should import raw configuration into forgeops"`, async () => {
const CMD = `frodo config-manager push raw -p test/e2e/exports/fr-config-manager/forgeops/raw/openidm/config -D ${forgeopsDirectory} -m forgeops`;
const { stdout, stderr } = await exec(CMD, forgeopsEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot()
});

//Cloud

test(`"frodo config-manager push raw -D ${cloudDirectory}: should import raw configuration into cloud"`, async () => {
const CMD = `frodo config-manager push raw -D ${cloudDirectory} `;
const { stdout, stderr } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot()
});
test(`"frodo config-manager push raw -p test/e2e/exports/fr-config-manager/cloud/raw/environment -D ${cloudDirectory}: should import raw configuration into cloud"`, async () => {
const CMD = `frodo config-manager push raw -p test/e2e/exports/fr-config-manager/cloud/raw/environment -D ${cloudDirectory}`;
const { stdout, stderr } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot()
});
});
Comment thread
dallinjsevy marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_id": "",
"_rev": "1077208638",
"_type": {
"_id": "SocialIdentityProviders",
"collection": false,
"name": "Social Identity Provider Service"
},
"enabled": true
}
Comment thread
dallinjsevy marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"pagedResultsCookie": null,
"remainingPagedResults": -1,
"result": [
{
"_id": "esv-frodo-test-variable-1",
"description": "description1",
"expressionType": "string",
"loaded": true,
"valueBase64": "dmFsdWUx"
},
{
"_id": "esv-frodo-test-variable-2",
"description": "description2",
"expressionType": "int",
"loaded": true,
"valueBase64": "NDI="
},
{
"_id": "esv-test-variable",
"description": "test",
"expressionType": "string",
"loaded": true,
"valueBase64": "dGVzdA=="
}
],
"resultCount": 3,
"totalPagedResults": -1,
"totalPagedResultsPolicy": "NONE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_id": "cluster",
"enabled": true,
"instanceCheckInInterval": 5000,
"instanceCheckInOffset": 0,
"instanceId": "&{openidm.node.id}",
"instanceRecoveryTimeout": 30000,
"instanceTimeout": 30000
}
Loading