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 { configManagerRestart } from '../../../configManagerOps/FrConfigRestartOps.ts';
import { getTokens } from '../../../ops/AuthenticateOps';
import { printMessage, verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } =
frodo.utils.constants;

const deploymentTypes = [
CLOUD_DEPLOYMENT_TYPE_KEY
];
Comment thread
dallinjsevy marked this conversation as resolved.

export default function setup() {
const program = new FrodoCommand(
'frodo config-manager push restart',
[],
deploymentTypes
);
program
.description('Restart the environment.')
.addOption(
program.createOption('-s, --status', 'Check restart status only.')
)
.addOption(
program.createOption('-c, --check', 'Only restart if ESVs need loading.')
)
.addOption(
program.createOption('-w, --wait', 'Wait for restart to complete.')
)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Restarting Tenant');
const outcome = await configManagerRestart(

options.status,
options.check,
options.wait
);
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 Restart from './config-manager-push-restart';
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(Restart().name('restart'));
return program;
}
37 changes: 37 additions & 0 deletions src/configManagerOps/FrConfigRestartOps.ts.ts
Comment thread
dallinjsevy marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { frodo } from '@rockcarver/frodo-lib';
import { printError, printMessage } from '../utils/Console';
const { checkForUpdates, applyUpdates, readStatus } = frodo.cloud.startup;

/**
* Restart the environment to apply pending ESV updates.
* @param {boolean} status if true, only report the current restart status without restarting
* @param {boolean} check if true, only restart if there are ESVs that need loading
* @param {boolean} wait if true, wait for the restart to complete before returning
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function configManagerRestart(
Comment thread
dallinjsevy marked this conversation as resolved.
status?: boolean,
check?: boolean,
wait?: boolean
): Promise<boolean> {
try {
if (status) {
printMessage(await readStatus());
return true;
}
if (check) {
const updates = await checkForUpdates();
const updateCount =
(updates.secrets?.length || 0) + (updates.variables?.length || 0);
if (updateCount === 0) {
printMessage('All ESVs loaded - not restarting');
return true;
}
}
const outcome = await applyUpdates(!!wait);
return outcome;
} catch (error) {
printError(error, 'Error restarting environment');
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

[Experimental] Restart the environment.

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.

Deployment: Cloud-only

Options:
-c, --check Only restart if ESVs need loading.
-s, --status Check restart status only.
-w, --wait Wait for restart to complete.
-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 @@ -33,5 +33,8 @@ Commands:
terms-and-conditions [Experimental] Import terms and conditions.
themes [Experimental] Import themes.
ui-config [Experimental] Import UI configuration.

(Cloud-only):
restart [Experimental] Restart the environment.
"
`;
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-push-restart.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 restart --help';
const { stdout } = await exec(CMD);

test("CLI help interface for 'config-manager push restart' should be expected english", async () => {
expect(stdout).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`frodo config-manager push restart "frodo config-manager push restart -c": should check for updates and then apply them to the cloud tenant" 1`] = `""`;

exports[`frodo config-manager push restart "frodo config-manager push restart -s": should check for updates to apply to the cloud tenant" 1`] = `""`;

exports[`frodo config-manager push restart "frodo config-manager push restart -w": should restart the cloud tenant and wait until restart is complete to exit command." 1`] = `""`;

exports[`frodo config-manager push restart "frodo config-manager push restart": should restart the cloud tenant" 1`] = `""`;
89 changes: 89 additions & 0 deletions test/e2e/config-manager-push-restart.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* 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.
*/

/*
// Cloud
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push restart
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push restart -s
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push restart -c
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push restart -w
*/

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

const exec = promisify(cp.exec);

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


describe('frodo config-manager push restart', () => {
test(`"frodo config-manager push restart": should restart the cloud tenant"`, async () => {
const CMD = `frodo config-manager push restart`;
const { stdout } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
test(`"frodo config-manager push restart -s": should check for updates to apply to the cloud tenant"`, async () => {
const CMD = `frodo config-manager push restart -s`;
const { stdout } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
test(`"frodo config-manager push restart -c": should check for updates and then apply them to the cloud tenant"`, async () => {
const CMD = `frodo config-manager push restart -c`;
const { stdout } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
test(`"frodo config-manager push restart -w": should restart the cloud tenant and wait until restart is complete to exit command."`, async () => {
const CMD = `frodo config-manager push restart -w`;
const { stdout } = await exec(CMD, cloudEnv);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
});
Loading