Skip to content

Commit

Permalink
Merge pull request #328 from rockcarver/pr/325
Browse files Browse the repository at this point in the history
Pr/325
  • Loading branch information
vscheuber authored Nov 26, 2023
2 parents 94f212d + 2e71588 commit 317cb22
Show file tree
Hide file tree
Showing 162 changed files with 532,319 additions and 9,276 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
]
},
"dependencies": {
"@rockcarver/frodo-lib": "2.0.0-49",
"@rockcarver/frodo-lib": "2.0.0-51",
"chokidar": "^3.5.3",
"cli-progress": "^3.11.2",
"cli-table3": "^0.6.3",
Expand Down
10 changes: 10 additions & 0 deletions src/cli/FrodoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs';

import * as globalConfig from '../storage/StaticStorage';
import {
cleanupProgressIndicators,
createProgressIndicator,
curlirizeMessage,
debugMessage,
Expand Down Expand Up @@ -191,6 +192,15 @@ export class FrodoStubCommand extends Command {
state.setCreateProgressHandler(createProgressIndicator);
state.setUpdateProgressHandler(updateProgressIndicator);
state.setStopProgressHandler(stopProgressIndicator);

// shutdown handlers
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.hook('postAction', (thisCommand, actionCommand) => {
debugMessage(
`postAction: this command: ${thisCommand.name()}, action command: ${actionCommand.name()}`
);
cleanupProgressIndicators();
});
}
}

Expand Down
88 changes: 88 additions & 0 deletions src/cli/admin/admin-export-full-cloud-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
exportEverythingToFile,
exportEverythingToFiles,
} from '../../ops/AdminOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { getTokens } = frodo.login;

const program = new FrodoCommand('frodo admin export-full-cloud-config');

program
.description(
'Export full cloud configuration for all ops that currently support export.'
)
.addOption(new Option('-f, --file <file>', 'Name of the export file.'))
.addOption(new Option('-a, --all', 'Export everything to a single file.'))
.addOption(
new Option(
'-A, --all-separate',
'Export everything to separate files in the -D directory. Ignored with -a.'
)
)
.addOption(
new Option(
'--use-string-arrays',
'Where applicable, use string arrays to store multi-line text (e.g. scripts).'
).default(false, 'off')
)
.addOption(
new Option(
'--no-decode',
'Do not include decoded variable value in variable export'
).default(false, 'false')
)
.addOption(
new Option(
'-x, --extract',
'Extract scripts from the exported file, and save it to a separate file. Ignored with -a.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
// --all -a
if (options.all && (await getTokens())) {
verboseMessage('Exporting everything to a single file...');
await exportEverythingToFile(options.file, {
useStringArrays: options.useStringArrays,
noDecode: options.decode,
});
// require --directory -D for all-separate function
} else if (options.allSeparate && !state.getDirectory()) {
printMessage(
'-D or --directory required when using -A or --all-separate',
'error'
);
program.help();
process.exitCode = 1;
// --all-separate -A
} else if (options.allSeparate && (await getTokens())) {
verboseMessage('Exporting everything to separate files...');
await exportEverythingToFiles(options.extract, {
useStringArrays: options.useStringArrays,
noDecode: options.decode,
});
// unrecognized combination of options or no options
} else {
verboseMessage('Unrecognized combination of options or no options...');
program.help();
process.exitCode = 1;
}
}
// end command logic inside action handler
);

program.parse();
5 changes: 5 additions & 0 deletions src/cli/admin/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default function setup() {
'List oauth2 clients with admin privileges.'
);

program.command(
'export-full-cloud-config',
'Export full cloud configuration for all ops that currently support export.'
);

program.command(
'grant-oauth2-client-admin-privileges',
'Grant an oauth2 client admin privileges.'
Expand Down
14 changes: 9 additions & 5 deletions src/cli/authz/authz-policy-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ program
// export
if (options.policyId && (await getTokens())) {
verboseMessage('Exporting authorization policy to file...');
const outcome = exportPolicyToFile(options.policyId, options.file, {
deps: options.deps,
prereqs: options.prereqs,
useStringArrays: true,
});
const outcome = await exportPolicyToFile(
options.policyId,
options.file,
{
deps: options.deps,
prereqs: options.prereqs,
useStringArrays: true,
}
);
if (!outcome) process.exitCode = 1;
}
// -a/--all by policy set
Expand Down
14 changes: 9 additions & 5 deletions src/cli/authz/authz-policy-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ program
// import
if (options.policyId && (await getTokens())) {
verboseMessage('Importing authorization policy from file...');
const outcome = importPolicyFromFile(options.policyId, options.file, {
deps: options.deps,
prereqs: options.prereqs,
policySetName: options.setId,
});
const outcome = await importPolicyFromFile(
options.policyId,
options.file,
{
deps: options.deps,
prereqs: options.prereqs,
policySetName: options.setId,
}
);
if (!outcome) process.exitCode = 1;
}
// -a/--all
Expand Down
7 changes: 5 additions & 2 deletions src/cli/authz/authz-policy-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ program
verboseMessage(
`Listing authorization policies in policy set ${options.setId}...`
);
const outcome = listPoliciesByPolicySet(options.setId, options.long);
const outcome = await listPoliciesByPolicySet(
options.setId,
options.long
);
if (!outcome) process.exitCode = 1;
}
// all policies
else if (await getTokens()) {
verboseMessage(`Listing authorization policies...`);
const outcome = listPolicies(options.long);
const outcome = await listPolicies(options.long);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
4 changes: 2 additions & 2 deletions src/cli/authz/authz-set-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ program
// delete by id
if (options.setId && (await getTokens())) {
verboseMessage('Deleting authorization policy set...');
const outcome = deletePolicySetById(options.setId);
const outcome = await deletePolicySetById(options.setId);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (options.all && (await getTokens())) {
verboseMessage('Deleting all authorization policy sets...');
const outcome = deletePolicySets();
const outcome = await deletePolicySets();
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
14 changes: 9 additions & 5 deletions src/cli/authz/authz-set-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ program
// export
if (options.setId && (await getTokens())) {
verboseMessage('Exporting authorization policy set to file...');
const outcome = exportPolicySetToFile(options.setId, options.file, {
useStringArrays: true,
deps: options.deps,
prereqs: options.prereqs,
});
const outcome = await exportPolicySetToFile(
options.setId,
options.file,
{
useStringArrays: true,
deps: options.deps,
prereqs: options.prereqs,
}
);
if (!outcome) process.exitCode = 1;
}
// -a/--all
Expand Down
12 changes: 8 additions & 4 deletions src/cli/authz/authz-set-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ program
// import
if (options.setId && (await getTokens())) {
verboseMessage('Importing authorization policy set from file...');
const outcome = importPolicySetFromFile(options.setId, options.file, {
deps: options.deps,
prereqs: options.prereqs,
});
const outcome = await importPolicySetFromFile(
options.setId,
options.file,
{
deps: options.deps,
prereqs: options.prereqs,
}
);
if (!outcome) process.exitCode = 1;
}
// -a/--all
Expand Down
2 changes: 1 addition & 1 deletion src/cli/authz/authz-set-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ program.description('List authorization policy sets.').action(
);
if (await getTokens()) {
verboseMessage('Listing authorization policy sets...');
const outcome = listPolicySets();
const outcome = await listPolicySets();
if (!outcome) process.exitCode = 1;
} else {
process.exitCode = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/authz/authz-type-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ program
// delete by uuid
if (options.typeId && (await getTokens())) {
verboseMessage('Deleting authorization resource type...');
const outcome = deleteResourceTypeById(options.typeId);
const outcome = await deleteResourceTypeById(options.typeId);
if (!outcome) process.exitCode = 1;
}
// delete by name
else if (options.typeName && (await getTokens())) {
verboseMessage('Deleting authorization resource type...');
const outcome = deleteResourceTypeUsingName(options.typeName);
const outcome = await deleteResourceTypeUsingName(options.typeName);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (options.all && (await getTokens())) {
verboseMessage('Deleting all authorization resource types...');
const outcome = deleteResourceTypes();
const outcome = await deleteResourceTypes();
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
7 changes: 5 additions & 2 deletions src/cli/authz/authz-type-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ program
// export by uuid
if (options.typeId && (await getTokens())) {
verboseMessage('Exporting authorization resource type to file...');
const outcome = exportResourceTypeToFile(options.typeId, options.file);
const outcome = await exportResourceTypeToFile(
options.typeId,
options.file
);
if (!outcome) process.exitCode = 1;
}
// export by name
else if (options.typeName && (await getTokens())) {
verboseMessage('Exporting authorization resource type to file...');
const outcome = exportResourceTypeByNameToFile(
const outcome = await exportResourceTypeByNameToFile(
options.typeName,
options.file
);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/authz/authz-type-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ program
verboseMessage(
'Importing authorization resource type by uuid from file...'
);
const outcome = importResourceTypeFromFile(
const outcome = await importResourceTypeFromFile(
options.typeId,
options.file
);
Expand All @@ -69,7 +69,7 @@ program
verboseMessage(
'Importing authorization resource type by name from file...'
);
const outcome = importResourceTypeByNameFromFile(
const outcome = await importResourceTypeByNameFromFile(
options.typeName,
options.file
);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/authz/authz-type-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ program
);
if (await getTokens()) {
verboseMessage('Listing resource types...');
const outcome = listResourceTypes(options.long);
const outcome = await listResourceTypes(options.long);
if (!outcome) process.exitCode = 1;
} else {
process.exitCode = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/email/email-template-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ program
options.templateId
}" from realm "${state.getRealm()}"...`
);
exportEmailTemplateToFile(options.templateId, options.file);
await exportEmailTemplateToFile(options.templateId, options.file);
}
// --all -a
else if (options.all && (await getTokens())) {
verboseMessage('Exporting all email templates to a single file...');
exportEmailTemplatesToFile(options.file);
await exportEmailTemplatesToFile(options.file);
}
// --all-separate -A
else if (options.allSeparate && (await getTokens())) {
verboseMessage('Exporting all email templates to separate files...');
exportEmailTemplatesToFiles();
await exportEmailTemplatesToFiles();
}
// unrecognized combination of options or no options
else {
Expand Down
Loading

0 comments on commit 317cb22

Please sign in to comment.