-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mapping command and sub-commands. Add ability to separate sync.js…
…on mappings in idm/config exports. Update file extraction. Update tests.
- Loading branch information
1 parent
a2e7558
commit 7e0cf9c
Showing
176 changed files
with
297,125 additions
and
425,851 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Option } from 'commander'; | ||
|
||
import { getTokens } from '../../ops/AuthenticateOps'; | ||
import { deleteMapping, deleteMappings } from '../../ops/MappingOps'; | ||
import { printMessage, verboseMessage } from '../../utils/Console'; | ||
import { FrodoCommand } from '../FrodoCommand'; | ||
|
||
export default function setup() { | ||
const program = new FrodoCommand('frodo mapping delete'); | ||
|
||
program | ||
.description('Delete IDM mappings.') | ||
.addOption( | ||
new Option( | ||
'-i, --mapping-id <mapping-id>', | ||
'Mapping id. If specified, -a is ignored.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-c, --connector-id <connector-id>', | ||
'Connector id. If specified, limits mappings to that particular connector; Ignored with -i.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-t, --managed-object-type <managed-object-type>', | ||
'Managed object type. If specified, limits mappings to that particular managed object type. Ignored with -i.' | ||
) | ||
) | ||
.addOption(new Option('-a, --all', 'Delete all mappings. 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 | ||
); | ||
// delete by id/name | ||
if (options.mappingId && (await getTokens())) { | ||
verboseMessage(`Deleting mapping ${options.mappingId}...`); | ||
const outcome = await deleteMapping(options.mappingId); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// --all -a | ||
else if (options.all && (await getTokens())) { | ||
verboseMessage(`Deleting all mappings...`); | ||
const outcome = await deleteMappings( | ||
options.connectorId, | ||
options.managedObjectType | ||
); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// unrecognized combination of options or no options | ||
else { | ||
printMessage( | ||
'Unrecognized combination of options or no options...', | ||
'error' | ||
); | ||
program.help(); | ||
process.exitCode = 1; | ||
} | ||
} | ||
// end command logic inside action handler | ||
); | ||
|
||
return program; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Option } from 'commander'; | ||
|
||
import { getTokens } from '../../ops/AuthenticateOps'; | ||
import { | ||
exportMappingsToFile, | ||
exportMappingsToFiles, | ||
exportMappingToFile, | ||
} from '../../ops/MappingOps'; | ||
import { printMessage, verboseMessage } from '../../utils/Console'; | ||
import { FrodoCommand } from '../FrodoCommand'; | ||
|
||
export default function setup() { | ||
const program = new FrodoCommand('frodo mapping export'); | ||
|
||
program | ||
.description('Export IDM mappings.') | ||
.addOption( | ||
new Option( | ||
'-i, --mapping-id <mapping-id>', | ||
'Mapping id. If specified, -a is ignored.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-c, --connector-id <connector-id>', | ||
'Connector id. If specified, limits mappings to that particular connector; Ignored with -i.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-t, --managed-object-type <managed-object-type>', | ||
'Managed object type. If specified, limits mappings to that particular managed object type. Ignored with -i.' | ||
) | ||
) | ||
.addOption(new Option('-f, --file <file>', 'Export file. Ignored with -A.')) | ||
.addOption(new Option('-a, --all', 'Export all mappings. Ignored with -i.')) | ||
.addOption( | ||
new Option( | ||
'-A, --all-separate', | ||
'Export all mappings into separate JSON files in directory -D. Ignored with -i and -a.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-N, --no-metadata', | ||
'Does not include metadata in the export file.' | ||
) | ||
) | ||
.addOption( | ||
new Option('--no-deps', 'Do not include any dependencies in export.') | ||
) | ||
.addOption( | ||
new Option( | ||
'--use-string-arrays', | ||
'Where applicable, use string arrays to store multi-line text (e.g. scripts).' | ||
).default(false, 'off') | ||
) | ||
.action( | ||
// implement command logic inside action handler | ||
async (host, realm, user, password, options, command) => { | ||
command.handleDefaultArgsAndOpts( | ||
host, | ||
realm, | ||
user, | ||
password, | ||
options, | ||
command | ||
); | ||
// export by id/name | ||
if (options.mappingId && (await getTokens())) { | ||
verboseMessage(`Exporting mapping ${options.mappingId}...`); | ||
const outcome = await exportMappingToFile( | ||
options.mappingId, | ||
options.file, | ||
options.metadata, | ||
{ | ||
deps: options.deps, | ||
useStringArrays: options.useStringArrays, | ||
} | ||
); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// --all -a | ||
else if (options.all && (await getTokens())) { | ||
verboseMessage(`Exporting all mappings to a single file...`); | ||
const outcome = await exportMappingsToFile( | ||
options.file, | ||
options.metadata, | ||
{ | ||
connectorId: options.connectorId, | ||
moType: options.managedObjectType, | ||
deps: options.deps, | ||
useStringArrays: options.useStringArrays, | ||
} | ||
); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// --all-separate -A | ||
else if (options.allSeparate && (await getTokens())) { | ||
verboseMessage('Exporting all mappings to separate files...'); | ||
const outcome = await exportMappingsToFiles(options.metadata, { | ||
connectorId: options.connectorId, | ||
moType: options.managedObjectType, | ||
deps: options.deps, | ||
useStringArrays: options.useStringArrays, | ||
}); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// unrecognized combination of options or no options | ||
else { | ||
printMessage( | ||
'Unrecognized combination of options or no options...', | ||
'error' | ||
); | ||
program.help(); | ||
process.exitCode = 1; | ||
} | ||
} | ||
// end command logic inside action handler | ||
); | ||
|
||
return program; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Option } from 'commander'; | ||
|
||
import { getTokens } from '../../ops/AuthenticateOps'; | ||
import { | ||
importFirstMappingFromFile, | ||
importMappingFromFile, | ||
importMappingsFromFile, | ||
importMappingsFromFiles, | ||
} from '../../ops/MappingOps'; | ||
import { printMessage, verboseMessage } from '../../utils/Console'; | ||
import { FrodoCommand } from '../FrodoCommand'; | ||
|
||
export default function setup() { | ||
const program = new FrodoCommand('frodo mapping import'); | ||
|
||
program | ||
.description('Import IDM mappings.') | ||
.addOption( | ||
new Option( | ||
'-i, --mapping-id <mapping-id>', | ||
'Mapping id. If specified, only one mapping is imported and the options -a and -A are ignored.' | ||
) | ||
) | ||
.addOption(new Option('-f, --file <file>', 'Name of the file to import')) | ||
.addOption( | ||
new Option( | ||
'-a, --all', | ||
'Import all mappings from single file. Ignored with -i.' | ||
) | ||
) | ||
.addOption( | ||
new Option( | ||
'-A, --all-separate', | ||
'Import all mappings from separate files (*.sync.json or *.mapping.json) in the current directory. Ignored with -i and -a.' | ||
) | ||
) | ||
.addOption(new Option('--no-deps', 'Do not include any dependencies.')) | ||
.action( | ||
// implement command logic inside action handler | ||
async (host, realm, user, password, options, command) => { | ||
command.handleDefaultArgsAndOpts( | ||
host, | ||
realm, | ||
user, | ||
password, | ||
options, | ||
command | ||
); | ||
// import by id/name | ||
if (options.mappingId && (await getTokens())) { | ||
verboseMessage(`Importing mapping ${options.mappingId}...`); | ||
const outcome = await importMappingFromFile( | ||
options.mappingId, | ||
options.file, | ||
{ | ||
deps: options.deps, | ||
} | ||
); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// --all -a | ||
else if (options.all && options.file && (await getTokens())) { | ||
verboseMessage( | ||
`Importing all mappings from a single file (${options.file})...` | ||
); | ||
const outcome = await importMappingsFromFile(options.file, { | ||
deps: options.deps, | ||
}); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// --all-separate -A | ||
else if (options.allSeparate && (await getTokens())) { | ||
verboseMessage('Importing all mappings from separate files...'); | ||
const outcome = await importMappingsFromFiles({ | ||
deps: options.deps, | ||
}); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// import first mapping in file | ||
else if (options.file && (await getTokens())) { | ||
verboseMessage('Importing first mapping in file...'); | ||
const outcome = await importFirstMappingFromFile(options.file, { | ||
deps: options.deps, | ||
}); | ||
if (!outcome) process.exitCode = 1; | ||
} | ||
// unrecognized combination of options or no options | ||
else { | ||
printMessage( | ||
'Unrecognized combination of options or no options...', | ||
'error' | ||
); | ||
program.help(); | ||
process.exitCode = 1; | ||
} | ||
} | ||
// end command logic inside action handler | ||
); | ||
|
||
return program; | ||
} |
Oops, something went wrong.