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
@@ -1,4 +1,5 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

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

program
.description('Export connector mappings.')
.addOption(
new Option('-n, --name <name>', 'Export by name of connector mapping.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: We can make the wording more concise with Export by name. or Export connector mapping by name. Technically "connector mapping" is not necessary as that is implied by the command, although it's fine if we keep it in there.

)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
Expand All @@ -33,8 +37,14 @@ export default function setup() {
);

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting connector mappings');
const outcome = await configManagerExportMappings();
let outcome: boolean;
if (options.name) {
verboseMessage(`Exporting ${options.name}`);
outcome = await configManagerExportMappings(options.name);
} else {
verboseMessage('Exporting connector mappings');
outcome = await configManagerExportMappings();
}
Comment on lines +40 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(options.name ? `Exporting ${options.name}` : 'Exporting connector mappings');
const outcome = await configManagerExportMappings(options.name);

if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function setup() {
'The CSP_OVERRIDES json file. ex: "/home/trivir/Documents/csp-overrides.json", or "csp-overrides.json"'
)
)
.addOption(new Option('-n, --name <name>', 'Export by name of csp.'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.addHelpText(
'after',
'There is an option to overrides the export file.\n' +
Expand Down Expand Up @@ -57,8 +58,14 @@ export default function setup() {
);

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting content security policy');
const outcome = await configManagerExportCsp(options.file);
let outcome: boolean;
if (options.name) {
verboseMessage(`Exporting ${options.name}`);
outcome = await configManagerExportCsp(options.file, options.name);
} else {
verboseMessage('Exporting content security policy');
outcome = await configManagerExportCsp(options.file);
}
Comment on lines +61 to +68

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(options.name ? `Exporting ${options.name}` : 'Exporting content security policy');
const outcome = await configManagerExportCsp(options.file, options.name);

if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
configManagerExportOrgPrivileges,
configManagerExportOrgPrivilegesAllRealms,
configManagerExportOrgPrivilegesRealm,
} from '../../../configManagerOps/FrConfigOrgPrivilegesOps';
import { configManagerExportOrgPrivileges } from '../../../configManagerOps/FrConfigOrgPrivilegesOps';
import { getTokens } from '../../../ops/AuthenticateOps';
import { printMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';
Expand All @@ -17,7 +13,6 @@ const deploymentTypes = [
CLOUD_DEPLOYMENT_TYPE_KEY,
FORGEOPS_DEPLOYMENT_TYPE_KEY,
];
const { constants } = frodo.utils;

export default function setup() {
const program = new FrodoCommand(
Expand All @@ -29,10 +24,7 @@ export default function setup() {
program
.description('Export organization privileges config.')
.addOption(
new Option(
'-r, --realm <realm>',
'Specifies the realm to export from. Only the entity object from this realm will be exported.'
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think these realm flag changes should be already removed in your realm PR: #116

If you need these changes for this PR, I would rebase this PR with your realm branch and make this PR against the realm branch, that way we can keep the changes separate.

new Option('-n, --name <name>', 'Export by name of org-privilege')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
Expand All @@ -44,27 +36,17 @@ export default function setup() {
command
);

// -r flag has precedence
if (options.realm) {
realm = options.realm;
}

if (await getTokens(false, true, deploymentTypes)) {
let outcome: boolean;
if (realm !== constants.DEFAULT_REALM_KEY) {
if (options.name) {
printMessage(
`Exporting organization privileges config from the realm: "${realm}"`
`Exporting ${options.name} organization privilege config`
);
outcome =
(await configManagerExportOrgPrivileges()) &&
(await configManagerExportOrgPrivilegesRealm(realm));
outcome = await configManagerExportOrgPrivileges(options.name);
} else {
printMessage(
'Exporting oranization privileges config from all realms'
);
outcome = await configManagerExportOrgPrivilegesAllRealms();
printMessage('Exporting all oranization privileges config');
outcome = await configManagerExportOrgPrivileges();
}
Comment on lines +41 to 66

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(`Exporting ${options.name || 'all'} organization privileges`);
const outcome = await configManagerExportOrgPrivileges(options.name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(`Exporting ${options.name || 'all'} organization privileges`);
const outcome = await configManagerExportOrgPrivileges(options.name);


if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

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

program
.description('Export secrets.')
.addOption(new Option('-n, --name <name>', 'Export by name of secret.'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
Expand All @@ -33,8 +35,14 @@ export default function setup() {
);

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting secrets');
const outcome = await configManagerExportSecrets(options);
let outcome: boolean;
if (options.name) {
verboseMessage(`Exporting ${options.name}`);
outcome = await configManagerExportSecrets(options, options.name);
} else {
verboseMessage('Exporting secrets');
outcome = await configManagerExportSecrets(options);
}
Comment on lines +38 to +45

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(`Exporting ${options.name || 'secrets'}`);
const outcome = await configManagerExportSecrets(options.name);

Note for this one it doesn't make sense to pass in options, only options.name, so you should modify that function to only take the name as a parameter

if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

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

program
.description('Export themes.')
.addOption(new Option('-n, --name <name>', 'Export by name of theme.'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
Expand All @@ -33,8 +35,14 @@ export default function setup() {
);

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting themes');
const outcome = await configManagerExportThemes();
let outcome: boolean;
if (options.name) {
verboseMessage(`Exporting ${options.name}`);
outcome = await configManagerExportThemes(options.name);
} else {
verboseMessage('Exporting themes');
outcome = await configManagerExportThemes();
}
Comment on lines +38 to +45

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(`Exporting ${options.name || 'themes'}`);
const outcome = await configManagerExportThemes(options.name);

if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { configManagerExportVariables } from '../../../configManagerOps/FrConfigVariableOps';
import { getTokens } from '../../../ops/AuthenticateOps';
Expand All @@ -17,6 +18,9 @@ export default function setup() {

program
.description('Export variables objects.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think it makes sense to say "objects", we should just say "variables" like we do with secrets.

.addOption(
new Option('-n, --name <name>', 'Export by name of variable object.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Similar to https://github.com/trivir/frodo-cli/pull/118/changes#r3580098075, I would also remove "object" from the description

)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
Expand All @@ -28,8 +32,14 @@ export default function setup() {
);

if (await getTokens(false, true, deploymentTypes)) {
verboseMessage('Exporting variables');
const outcome = await configManagerExportVariables();
let outcome: boolean;
if (options.name) {
verboseMessage(`Exporting ${options.name}`);
outcome = await configManagerExportVariables(options.name);
} else {
verboseMessage('Exporting variables');
outcome = await configManagerExportVariables();
}
Comment on lines +35 to +42

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are calling the same function, you don't need an if statement here. You can simplify this to:

verboseMessage(`Exporting ${options.name || 'variables'}`);
const outcome = await configManagerExportVariables(options.name);

if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
6 changes: 3 additions & 3 deletions src/configManagerOps/FrConfigAllOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { configManagerExportKbaConfig } from './FrConfigKbaOps';
import { configManagerExportLocales } from './FrConfigLocalesOps';
import { configManagerExportManagedObjects } from './FrConfigManagedObjectsOps';
import { configManagerExportConfigAgents } from './FrConfigOauth2AgentOps';
import { configManagerExportOrgPrivilegesAllRealms } from './FrConfigOrgPrivilegesOps';
import { configManagerExportOrgPrivileges } from './FrConfigOrgPrivilegesOps';
import { configManagerExportPasswordPolicy } from './FrConfigPasswordPolicyOps';
import { configManagerExportRemoteServers } from './FrConfigRemoteServersOps';
import { configManagerExportSaml } from './FrConfigSamlOps';
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function configManagerExportAllWithConfigFolder(
);
}

await configManagerExportOrgPrivilegesAllRealms();
await configManagerExportOrgPrivileges();
await configManagerExportPasswordPolicy();
await configManagerExportRemoteServers();
await configManagerExportSchedules();
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function configManagerExportAllStatic(): Promise<boolean> {
await configManagerExportKbaConfig();
await configManagerExportLocales();
await configManagerExportManagedObjects();
await configManagerExportOrgPrivilegesAllRealms();
await configManagerExportOrgPrivileges();
await configManagerExportPasswordPolicy();

await configManagerExportRemoteServers();
Expand Down
6 changes: 5 additions & 1 deletion src/configManagerOps/FrConfigConnectorMappingOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ function processMappings(mapping, targetDir, name) {
/**
* Export all mappings to separate files in fr-config-manager format
* @param {MappingExportOptions} options export options
* @param {string} name connector mapping name
* @returns {Promise<boolean>} true if successful, false otherwise
*/
export async function configManagerExportMappings(): Promise<boolean> {
export async function configManagerExportMappings(
name?: string
): Promise<boolean> {
try {
const exportData = await readConfigEntity('sync');
const fileDir = `sync/mappings`;
for (const mapping of Object.values(exportData.mappings)) {
if (name && mapping.name != name) continue;
processMappings(mapping, `${fileDir}/${mapping.name}`, mapping.name);
}
return true;
Expand Down
28 changes: 22 additions & 6 deletions src/configManagerOps/FrConfigCspOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,33 @@ const { getFilePath, saveJsonToFile } = frodo.utils;

/**
* Export the content security policy in fr-config manager format
* @param {string} file file for csp override
* @param {string} name csp name
* @returns True if file was successfully saved
*/
export async function configManagerExportCsp(
file: string = null
file: string = null,
name?: string
): Promise<boolean> {
try {
const cspEnforced: ContentSecurityPolicy =
await env.readEnforcedContentSecurityPolicy();
const cspReport: ContentSecurityPolicy =
await env.readReportOnlyContentSecurityPolicy();
const csp = { enforced: cspEnforced, 'report-only': cspReport };
let csp: Record<string, ContentSecurityPolicy>;
if (name && name !== 'enforced' && name !== 'report-only') {
throw new Error(`Unknown CSP: ${name}`);
}
if (name === 'enforced') {
csp = {
enforced: await env.readEnforcedContentSecurityPolicy(),
};
} else if (name === 'report-only') {
csp = {
'report-only': await env.readReportOnlyContentSecurityPolicy(),
};
} else {
csp = {
enforced: await env.readEnforcedContentSecurityPolicy(),
'report-only': await env.readReportOnlyContentSecurityPolicy(),
};
}
Comment on lines +22 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can simplify this as follows to avoid duplicate code:

if (name && name !== 'enforced' && name !== 'report-only') {
  throw new Error(`Unknown CSP: ${name}`);
}
let csp: Record<string, ContentSecurityPolicy> = {};
if (!name || name === 'enforced') {
  csp.enforced =  await env.readEnforcedContentSecurityPolicy();
}
if (!name || name === 'report-only') {
  csp['report-only'] = await env.readReportOnlyContentSecurityPolicy();
}


if (file) {
const configFileData = JSON.parse(
Expand Down
Loading