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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dist
testResults.json
jest-test-setup.js

*.cer
*.p12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default function setup() {
[],
deploymentTypes
);
// TO DO: adding a realm option to export all-static for specific realm
Comment thread
phalestrivir marked this conversation as resolved.
program
.description('Export all static config.')
.action(async (host, realm, user, password, options, command) => {
Expand All @@ -36,7 +35,7 @@ export default function setup() {
return;
}

const outcome = await configManagerExportAllStatic();
const outcome = await configManagerExportAllStatic(realm);
if (!outcome) process.exitCode = 1;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function setup() {
[],
deploymentTypes
);
// TO DO: Adding a realm option to export all config for a specific realm
Comment thread
brycentrivir marked this conversation as resolved.
program
.description('Export all config.')
.addOption(
Expand Down Expand Up @@ -60,6 +59,7 @@ export default function setup() {
);
const outcome = await configManagerExportAllWithConfigFolder({
configFolder: options.configFolder,
realm,
});
if (!outcome) process.exitCode = 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { configManagerExportAuthentication } from '../../../configManagerOps/FrConfigAuthenticationOps';
import { getTokens } from '../../../ops/AuthenticateOps';
Expand All @@ -23,12 +22,6 @@ export default function setup() {

program
.description('Export authentication objects.')
.addOption(
new Option(
'-r, --realm <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,
Expand All @@ -38,9 +31,6 @@ export default function setup() {
options,
command
);
if (options.realm) {
realm = options.realm;
}
if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting config entity authentication');
const outcome = await configManagerExportAuthentication(realm);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
configManagerExportAuthzPoliciesAll,
configManagerExportAuthzPolicySet,
configManagerExportAuthzPolicySets,
configManagerExportAuthzPolicySetsRealm,
} from '../../../configManagerOps/FrConfigAuthzPoliciesOps';
import { configManagerExportAuthzPolicySets } from '../../../configManagerOps/FrConfigAuthzPoliciesOps';
import { getTokens } from '../../../ops/AuthenticateOps';
import { printMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';
Expand All @@ -18,8 +13,6 @@ const deploymentTypes = [
CLOUD_DEPLOYMENT_TYPE_KEY,
FORGEOPS_DEPLOYMENT_TYPE_KEY,
];
const { constants } = frodo.utils;
const { readRealms } = frodo.realm;

export default function setup() {
const program = new FrodoCommand(
Expand All @@ -29,22 +22,10 @@ export default function setup() {

program
.description('Export authorization policies from realm.')
.addOption(
new Option(
'-r, --realm <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 <policy-set-name>',
'Get only a specific policy set with the name.'
)
)
.addOption(
new Option(
'-f, --file <file>',
'The AUTHZ_POLICY_SETS_CONFIG json file. ex: "/home/trivir/Documents/policy-sets.json", or "policy-sets.json"'
'*Required* The AUTHZ_POLICY_SETS_CONFIG json file. ex: "/Documents/policy-sets.json"'
)
)
.addHelpText(
Expand Down Expand Up @@ -79,88 +60,10 @@ export default function setup() {
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;
}
printMessage(`Exporting all policy sets in the provided config file.`);
const outcome = await configManagerExportAuthzPolicySets(options.file);
if (!outcome) process.exit(1);
}

// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export default function setup() {
'Journey name, It only export the journey with the name.'
)
)
.addOption(
new Option(
'-r, --realm <realm>',
'Specific realm to get journeys from (overrides environment)'
)
)
.addOption(new Option('-d, --pull-dependencies', 'Pull dependencies.'))
// TO DO: implementing for 'clean'
// .addOption(
Expand All @@ -49,9 +43,6 @@ export default function setup() {
options,
command
);
if (options.realm) {
realm = options.realm;
}

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting config entity journeys');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
configManagerExportAgent,
configManagerExportAgentsAll,
configManagerExportAgentsRealm,
configManagerExportConfigAgents,
} from '../../../configManagerOps/FrConfigOauth2AgentOps';
import { configManagerExportConfigAgents } from '../../../configManagerOps/FrConfigOauth2AgentOps';
import { getTokens } from '../../../ops/AuthenticateOps';
import { printMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';
Expand All @@ -18,8 +13,6 @@ const deploymentTypes = [
CLOUD_DEPLOYMENT_TYPE_KEY,
FORGEOPS_DEPLOYMENT_TYPE_KEY,
];
const { constants } = frodo.utils;
const { readRealms } = frodo.realm;

export default function setup() {
const program = new FrodoCommand(
Expand All @@ -29,19 +22,6 @@ export default function setup() {

program
.description('Export OAuth2 Agents')
.addOption(
new Option(
'-r, --realm <realm>',
'Specifies the realm to export from. Only the agents from this realm will be exported.'
)
)
.addOption(
new Option(
'-n, --agent-name <agent name>',
'Export specific agent using agentId/agentName.'
)
)

.addOption(
new Option(
'-f, --file <file>',
Expand Down Expand Up @@ -94,84 +74,12 @@ export default function setup() {
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;
}
printMessage(
`Exporting all the agents defined in the provided config file.`
);
const outcome = await configManagerExportConfigAgents(options.file);
if (!outcome) process.exit(1);
}

// unrecognized combination of options or no options
Expand Down
Loading