Skip to content

Commit

Permalink
Merge pull request #454 from trivir/feature/new-imports-and-exports
Browse files Browse the repository at this point in the history
Add New Exports and Imports
  • Loading branch information
vscheuber authored Nov 22, 2024
2 parents b4aff69 + 441dd81 commit 7c7fb2e
Show file tree
Hide file tree
Showing 903 changed files with 890,575 additions and 592,853 deletions.
9 changes: 4 additions & 5 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 @@ -114,7 +114,7 @@
]
},
"devDependencies": {
"@rockcarver/frodo-lib": "3.0.0",
"@rockcarver/frodo-lib": "3.0.1-0",
"@types/colors": "^1.2.1",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.2.3",
Expand Down
4 changes: 4 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import log from './cli/log/log';
import mapping from './cli/mapping/mapping';
import oauth from './cli/oauth/oauth';
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 server from './cli/server/server';
import service from './cli/service/service';
import shell from './cli/shell/shell';
// enable sample command template.
Expand Down Expand Up @@ -72,8 +74,10 @@ const { initTokenCache } = frodo.cache;
program.addCommand(mapping());
program.addCommand(oauth());
program.addCommand(realm());
program.addCommand(role());
program.addCommand(saml());
program.addCommand(script());
program.addCommand(server());
program.addCommand(service());
program.addCommand(shell());
program.addCommand(theme());
Expand Down
13 changes: 12 additions & 1 deletion src/cli/agent/agent-describe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo agent describe');

program
.description('Describe agents.')
.addOption(new Option('-i, --agent-id <agent-id>', 'Agent id.'))
.addOption(new Option('-g, --global', 'Describe global agent.'))
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -20,7 +25,13 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
// code goes here
} else {
process.exitCode = 1;
Expand Down
20 changes: 18 additions & 2 deletions src/cli/agent/agent-export.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
Expand All @@ -9,6 +10,9 @@ import { getTokens } from '../../ops/AuthenticateOps';
import { verboseMessage } from '../../utils/Console.js';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo agent export');

Expand Down Expand Up @@ -39,6 +43,7 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)
.addOption(new Option('-g, --global', 'Export global agents.'))
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -50,13 +55,20 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
// export
if (options.agentId) {
verboseMessage('Exporting agent...');
const outcome = await exportAgentToFile(
options.agentId,
options.file,
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
Expand All @@ -66,14 +78,18 @@ export default function setup() {
verboseMessage('Exporting all agents to a single file...');
const outcome = await exportAgentsToFile(
options.file,
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A
else if (options.allSeparate) {
verboseMessage('Exporting all agents to separate files...');
const outcome = await exportAgentsToFiles(options.metadata);
const outcome = await exportAgentsToFiles(
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
30 changes: 24 additions & 6 deletions src/cli/agent/agent-import.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
Expand All @@ -10,6 +11,9 @@ import { getTokens } from '../../ops/AuthenticateOps';
import { verboseMessage } from '../../utils/Console.js';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo agent import');

Expand All @@ -34,6 +38,7 @@ export default function setup() {
'Import all agents from separate files (*.agent.json) in the current directory. Ignored with -i or -a.'
)
)
.addOption(new Option('-g, --global', 'Import global agents.'))
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -45,13 +50,20 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
// import
if (options.agentId) {
if (options.agentId && options.file) {
verboseMessage(`Importing agent ${options.agentId}...`);
const outcome = await importAgentFromFile(
options.agentId,
options.file
options.file,
options.global
);
if (!outcome) process.exitCode = 1;
}
Expand All @@ -60,19 +72,25 @@ export default function setup() {
verboseMessage(
`Importing all agents from a single file (${options.file})...`
);
const outcome = await importAgentsFromFile(options.file);
const outcome = await importAgentsFromFile(
options.file,
options.global
);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A
else if (options.allSeparate && !options.file) {
verboseMessage('Importing all agents from separate files...');
const outcome = await importAgentsFromFiles();
const outcome = await importAgentsFromFiles(options.global);
if (!outcome) process.exitCode = 1;
}
// import first agent in file
else if (options.file) {
verboseMessage('Importing first agent in file...');
const outcome = await importFirstAgentFromFile(options.file);
const outcome = await importFirstAgentFromFile(
options.file,
options.global
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
15 changes: 13 additions & 2 deletions src/cli/agent/agent-list.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { listAgents } from '../../ops/AgentOps.js';
import { getTokens } from '../../ops/AuthenticateOps';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo agent list');

Expand All @@ -12,6 +16,7 @@ export default function setup() {
.addOption(
new Option('-l, --long', 'Long with all fields.').default(false, 'false')
)
.addOption(new Option('-g, --global', 'List global agents.'))
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -23,8 +28,14 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
const outcome = await listAgents(options.long);
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
const outcome = await listAgents(options.long, options.global);
if (!outcome) process.exitCode = 1;
} else {
process.exitCode = 1;
Expand Down
20 changes: 18 additions & 2 deletions src/cli/authn/authn-describe.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import { describeAuthenticationSettings } from '../../ops/AuthenticationSettingsOps';
import { verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo authn describe');

program
.description('Describe authentication settings.')
.addOption(new Option('--json', 'Output in JSON format.'))
.addOption(
new Option('-g, --global', 'Describe global authentication settings.')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -22,9 +29,18 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
verboseMessage(`Describing authentication settings...`);
const outcome = await describeAuthenticationSettings(options.json);
const outcome = await describeAuthenticationSettings(
options.json,
options.global
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
16 changes: 15 additions & 1 deletion src/cli/authn/authn-export.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import { exportAuthenticationSettingsToFile } from '../../ops/AuthenticationSettingsOps';
import { verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { CLASSIC_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;
const globalDeploymentTypes = [CLASSIC_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand('frodo authn export');

Expand All @@ -17,6 +21,9 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)
.addOption(
new Option('-g, --global', 'Export global authentication settings.')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -28,10 +35,17 @@ export default function setup() {
options,
command
);
if (await getTokens()) {
if (
await getTokens(
false,
true,
options.global ? globalDeploymentTypes : undefined
)
) {
verboseMessage('Exporting authentication settings to file...');
const outcome = exportAuthenticationSettingsToFile(
options.file,
options.global,
options.metadata
);
if (!outcome) process.exitCode = 1;
Expand Down
Loading

0 comments on commit 7c7fb2e

Please sign in to comment.