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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import realm from './cli/realm/realm';
import role from './cli/role/role';
import saml from './cli/saml/saml';
import script from './cli/script/script';
import secretstore from './cli/secretstore/secretstore';
import server from './cli/server/server';
import service from './cli/service/service';
import shell from './cli/shell/shell';
Expand Down Expand Up @@ -79,6 +80,7 @@ const { initTokenCache } = frodo.cache;
program.addCommand(role());
program.addCommand(saml());
program.addCommand(script());
program.addCommand(secretstore());
program.addCommand(server());
program.addCommand(service());
program.addCommand(shell());
Expand Down
98 changes: 98 additions & 0 deletions src/cli/secretstore/secretstore-delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import {
deleteSecretStore,
deleteSecretStores,
} from '../../ops/SecretStoreOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { DEPLOYMENT_TYPES, CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = DEPLOYMENT_TYPES;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo secretstore delete',
[],
deploymentTypes
);

program
.description('Delete secret stores.')
.addOption(
new Option(
'-i, --secretstore-id <secretstore-id>',
'Secret store id. If specified, -a and -A are ignored.'
)
)
.addOption(
new Option(
'-t, --secretstore-type <secretstore-type>',
'Secret store type id of the secret store. Only necessary if there are multiple secret stores with the same secret store id. Ignored if -i is not specified.'
)
)
.addOption(
new Option(
'-g, --global',
'Delete global secret stores. For classic deployments only.'
)
)
.addOption(
new Option('-a, --all', 'Delete all secret stores. Ignored with -i.')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (
options.secretstoreId &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(`Deleting secret store ${options.secretstoreId}...`);
const outcome = await deleteSecretStore(
options.secretstoreId,
options.secretstoreType,
options.global
);
if (!outcome) process.exitCode = 1;
} else if (
options.all &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(
`Deleting all${options.global ? ' global' : ''} secret stores...`
);
const outcome = await deleteSecretStores(options.global);
if (!outcome) process.exitCode = 1;
} else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.outputHelp();
process.exitCode = 1;
}
}
// end command logic inside action handler
);
return program;
}
76 changes: 76 additions & 0 deletions src/cli/secretstore/secretstore-describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import { describeSecretStore } from '../../ops/SecretStoreOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { DEPLOYMENT_TYPES, CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = DEPLOYMENT_TYPES;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo secretstore describe',
[],
deploymentTypes
);

program
.description('Describe secret stores.')
.addOption(
new Option('-i, --secretstore-id <secretstore-id>', 'Secret store id.')
)
.addOption(
new Option(
'-t, --secretstore-type <secretstore-type>',
'Secret store type id of the secret store. Only necessary if there are multiple secret stores with the same secret store id. Ignored if -i is not specified.'
)
)
.addOption(
new Option(
'-g, --global',
'Describe global secret stores. For classic deployments only.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (
options.secretstoreId &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(`Describing secret store ${options.secretstoreId}`);
const outcome = await describeSecretStore(
options.secretstoreId,
options.secretstoreType,
options.global
);
if (!outcome) process.exitCode = 1;
} else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.outputHelp();
process.exitCode = 1;
}
}
// end command logic inside action handler
);
return program;
}
141 changes: 141 additions & 0 deletions src/cli/secretstore/secretstore-export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import {
exportSecretStoresToFile,
exportSecretStoresToFiles,
exportSecretStoreToFile,
} from '../../ops/SecretStoreOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { DEPLOYMENT_TYPES, CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = DEPLOYMENT_TYPES;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo secretstore export',
[],
deploymentTypes
);

program
.description('Export secret stores.')
.addOption(
new Option(
'-i, --secretstore-id <secretstore-id>',
'Secret store id. If specified, -a and -A are ignored.'
)
)
.addOption(
new Option(
'-t, --secretstore-type <secretstore-type>',
'Secret store type id of the secret store. Only necessary if there are multiple secret stores with the same secret store id. Ignored if -i is not specified.'
)
)
.addOption(new Option('-f, --file <file>', 'Name of the export file.'))
.addOption(
new Option(
'-g, --global',
'Export global secret stores. For classic deployments only.'
)
)
.addOption(
new Option(
'-a, --all',
'Export all secret stores to a single file. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'Export all secret stores to separate files (*.secretstore.json) in the current directory. Ignored with -i or -a.'
)
)
.addOption(
new Option(
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (
options.secretstoreId &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(`Exporting secret store ${options.secretstoreId}...`);
const outcome = await exportSecretStoreToFile(
options.secretstoreId,
options.secretstoreType,
options.file,
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (
options.all &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(
`Exporting all${options.global ? ' global' : ''} secret stores to a single file...`
);
const outcome = await exportSecretStoresToFile(
options.file,
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A
else if (
options.allSeparate &&
(await getTokens(
false,
true,
options.global ? globalDeploymentTypes : deploymentTypes
))
) {
verboseMessage(
`Exporting all${options.global ? ' global' : ''} secret stores to separate files...`
);
const outcome = await exportSecretStoresToFiles(
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
} else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.outputHelp();
process.exitCode = 1;
}
}
// end command logic inside action handler
);
return program;
}
Loading