Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/346 #347

Merged
merged 8 commits into from
Dec 23, 2023
Merged
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
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 @@ -116,7 +116,7 @@
]
},
"dependencies": {
"@rockcarver/frodo-lib": "2.0.0-56",
"@rockcarver/frodo-lib": "2.0.0-57",
"chokidar": "^3.5.3",
"cli-progress": "^3.11.2",
"cli-table3": "^0.6.3",
Expand Down
77 changes: 67 additions & 10 deletions src/cli/config/config-import.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { frodo } from '@rockcarver/frodo-lib';
import { frodo, state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import {
importEverythingFromFile,
importEverythingFromFiles,
} from '../../ops/ConfigOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const { getTokens } = frodo.login;
Expand All @@ -9,25 +14,43 @@ const program = new FrodoCommand('frodo config import');

program
.description('Import full cloud configuration.')
.addOption(new Option('-f, --file <file>', 'Name of the file to import.'))
.addOption(
new Option(
'-i, --config-id <config-id>',
'Configuration id. If specified, only one configuration is imported and the options -a and -A are ignored.'
'-a, --all',
'Import all configuration from the single file -f. Ignored with -i.'
)
)
.addOption(new Option('-f, --file <file>', 'Name of the file to import.'))
.addOption(
new Option(
'-a, --all',
'Import all configuration from a single file. Ignored with -i.'
'-A, --all-separate',
'Import all configuration from separate (.json) files in the (working) directory -D. Ignored with -i or -a.'
)
)
.addOption(
new Option('-C, --clean', 'Remove existing service(s) before importing.')
)
.addOption(
new Option('-g, --global', 'Import service(s) as global service(s).')
)
.addOption(
new Option(
'-A, --all-separate',
'Import all configuration from separate (.json) files in the working directory. Ignored with -i or -a.'
'-r, --current-realm',
'Import service(s) into the current realm.'
)
)
.addOption(
new Option(
'--re-uuid-journeys',
'Generate new UUIDs for all journey nodes during import.'
).default(false, 'off')
)
.addOption(
new Option(
'--re-uuid-scripts',
'Create new UUIDs for the scripts upon import. Use this to duplicate scripts or create a new versions of the same scripts.'
).default(false, 'off')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -39,9 +62,43 @@ program
options,
command
);
if (await getTokens()) {
// code goes here
// Require --file -f for all function
if (options.all && !options.file) {
printMessage('-f or --file required when using -a or --all', 'error');
program.help();
process.exitCode = 1;
// --all -a
} else if (options.all && (await getTokens())) {
verboseMessage('Exporting everything from a single file...');
await importEverythingFromFile(options.file, {
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.clean,
global: options.global,
realm: options.realm,
});
// 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('Importing everything from separate files...');
await importEverythingFromFiles({
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.clean,
global: options.global,
realm: options.realm,
});
// unrecognized combination of options or no options
} else {
verboseMessage('Unrecognized combination of options or no options...');
program.help();
process.exitCode = 1;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export default function setup() {
'Export full cloud configuration for all ops that currently support export..'
);

//program.command('import', 'Import full cloud configuration.');
program.command(
'import',
'Import full cloud configuration for all ops that currently support import.'
);

//program.command('delete', 'Delete full cloud configuration.');

Expand Down
23 changes: 19 additions & 4 deletions src/cli/idp/idp-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ program
'Import all the providers from separate files (*.json) in the current directory. Ignored with -t or -i or -a.'
)
)
.addOption(
new Option('--no-deps', 'Do not include any dependencies (scripts).')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -58,21 +61,31 @@ program
options.idpId
}" into realm "${state.getRealm()}"...`
);
await importSocialIdentityProviderFromFile(options.idpId, options.file);
await importSocialIdentityProviderFromFile(
options.idpId,
options.file,
{
deps: options.deps,
}
);
}
// --all -a
else if (options.all && options.file && (await getTokens())) {
verboseMessage(
`Importing all providers from a single file (${options.file})...`
);
await importSocialIdentityProvidersFromFile(options.file);
await importSocialIdentityProvidersFromFile(options.file, {
deps: options.deps,
});
}
// --all-separate -A
else if (options.allSeparate && !options.file && (await getTokens())) {
verboseMessage(
'Importing all providers from separate files in current directory...'
);
await importSocialIdentityProvidersFromFiles();
await importSocialIdentityProvidersFromFiles({
deps: options.deps,
});
}
// import first provider from file
else if (options.file && (await getTokens())) {
Expand All @@ -81,7 +94,9 @@ program
options.file
}" into realm "${state.getRealm()}"...`
);
await importFirstSocialIdentityProviderFromFile(options.file);
await importFirstSocialIdentityProviderFromFile(options.file, {
deps: options.deps,
});
}
// unrecognized combination of options or no options
else {
Expand Down
19 changes: 15 additions & 4 deletions src/cli/saml/saml-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ program
'Import all entity providers from separate files (*.saml.json) in the current directory. Ignored with -i or -a.'
)
)
.addOption(
new Option('--no-deps', 'Do not include any dependencies (scripts).')
)
.action(
// implement program logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -58,21 +61,27 @@ program
options.entityId
}" into realm "${state.getRealm()}"...`
);
await importSaml2ProviderFromFile(options.entityId, options.file);
await importSaml2ProviderFromFile(options.entityId, options.file, {
deps: options.deps,
});
}
// --all -a
else if (options.all && options.file && (await getTokens())) {
verboseMessage(
`Importing all providers from a single file (${options.file})...`
);
await importSaml2ProvidersFromFile(options.file);
await importSaml2ProvidersFromFile(options.file, {
deps: options.deps,
});
}
// --all-separate -A
else if (options.allSeparate && !options.file && (await getTokens())) {
verboseMessage(
'Importing all providers from separate files (*.saml.json) in current directory...'
);
await importSaml2ProvidersFromFiles();
await importSaml2ProvidersFromFiles({
deps: options.deps,
});
}
// import first provider from file
else if (options.file && (await getTokens())) {
Expand All @@ -81,7 +90,9 @@ program
options.file
}" into realm "${state.getRealm()}"...`
);
await importFirstSaml2ProviderFromFile(options.file);
await importFirstSaml2ProviderFromFile(options.file, {
deps: options.deps,
});
}
// unrecognized combination of options or no options
else {
Expand Down
39 changes: 30 additions & 9 deletions src/cli/service/service-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface ServiceImportOptions {
debug?: boolean;
curlirize?: boolean;
global?: boolean;
realm?: boolean;
}

program
Expand All @@ -53,7 +54,15 @@ program
'Import all services from separate files <id>.service.json.'
)
)
.addOption(new Option('-g, --global', 'Import global services.'))
.addOption(
new Option('-g, --global', 'Import service(s) as global service(s).')
)
.addOption(
new Option(
'-r, --current-realm',
'Import service(s) into the current realm.'
)
)
.action(
async (
host: string,
Expand All @@ -74,31 +83,43 @@ program

const clean = options.clean ?? false;
const globalConfig = options.global ?? false;
const realmConfig = options.realm ?? false;

// import by id
if (options.serviceId && options.file && (await getTokens())) {
verboseMessage('Importing service...');
await importServiceFromFile(
options.serviceId,
options.file,
await importServiceFromFile(options.serviceId, options.file, {
clean,
globalConfig
);
global: globalConfig,
realm: realmConfig,
});
}
// -a / --all
else if (options.all && options.file && (await getTokens())) {
verboseMessage('Importing all services from a single file...');
await importServicesFromFile(options.file, clean, globalConfig);
await importServicesFromFile(options.file, {
clean,
global: globalConfig,
realm: realmConfig,
});
}
// -A / --all-separate
else if (options.allSeparate && (await getTokens())) {
verboseMessage('Importing all services from separate files...');
await importServicesFromFiles(clean, globalConfig);
await importServicesFromFiles({
clean,
global: globalConfig,
realm: realmConfig,
});
}
// import file
else if (options.file && (await getTokens())) {
verboseMessage('Importing service...');
await importFirstServiceFromFile(options.file, clean, globalConfig);
await importFirstServiceFromFile(options.file, {
clean,
global: globalConfig,
realm: realmConfig,
});
}
// unrecognized combination of options or no options
else {
Expand Down
2 changes: 1 addition & 1 deletion src/ops/ApplicationOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export async function importApplicationsFromFiles(
try {
const data = fs.readFileSync(file, 'utf8');
const fileData: ApplicationExportInterface = JSON.parse(data);
const count = Object.keys(fileData.application).length;
const count = Object.keys(fileData.managedApplication).length;
total += count;
await _importApplications(fileData, options);
updateProgressIndicator(
Expand Down
Loading