Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
178 changes: 177 additions & 1 deletion package-lock.json

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

95 changes: 93 additions & 2 deletions src/cli/config/config-import.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//------------------ Modified file by Sean for test import/promote command-------------original file is in config-import-backup.ts

import { state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import * as s from '../../help/SampleData';
import { getTokens } from '../../ops/AuthenticateOps';
import {
compareWithMasterDirectoryAndDeleteFromCloud,
compareWithMasterFileAndDeleteFromCloud,
importEntityfromFile,
importEverythingFromFile,
importEverythingFromFiles,
Expand Down Expand Up @@ -55,6 +59,7 @@ export default function setup() {
'Import all scripts including the default scripts.'
)
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this extra new line since it wasn't there before

.addOption(
new Option(
'--include-active-values',
Expand All @@ -73,6 +78,18 @@ export default function setup() {
'Import global entity. Ignored with -a and -A.'
)
)
.addOption(
new Option(
'--delete-and-import',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we should rename this command to something more concise, just as --sync or --reconcile, or maybe --sync-compare or --reconcile-compare so it's obvious that the flag is related to the --compare flag. It's probably fine to keep it as --delete-and-import for now though, but we may want to ask @hfranklin what he thinks makes the most sense here.

'Deletes whatever added to the current cloud after comparison from --compare flag. Then it imports master config file/directory back to cloud. Only run when --compare flag is on.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is a little confusing to me. I think this might be a better description:

'Syncs changes found by using --compare from the master config file/directory to the current deployment. This includes importing any new/updated configuration, and deleting any configuration that is not in the master config.'

)
)
.addOption(
new Option(
'--compare',
'This export config data from the current tenant as an object, and it compares whatever changes between this object and the config data from the master file/directory.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description can be more concise. How about this:

'Compares changes between config in the master file or directory (specified with -f or -D flags respectively) with config exported from the current deployment.'

We will also want to also update the descriptions for -f and -D to mention that they are also used to specify the location for the master config for the --compare flag.

)
)
.addHelpText(
'after',
`How Frodo handles secrets:\n`['brightGreen'] +
Expand Down Expand Up @@ -112,8 +129,17 @@ export default function setup() {
program.help();
process.exitCode = 1;
}
if (options.deleteAndImport && !options.compare) {
printMessage(
'--compare flag is needed to run --delete-and-import',
'error'
);
program.help();
process.exitCode = 1;
}

// --all -a
else if (options.all && (await getTokens())) {
else if (options.all && !options.compare && (await getTokens())) {
verboseMessage('Exporting everything from a single file...');
const outcome = await importEverythingFromFile(options.file, {
reUuidJourneys: options.reUuidJourneys,
Expand All @@ -125,6 +151,34 @@ export default function setup() {
});
if (!outcome) process.exitCode = 1;
}
// What I added single file, compare and delete
else if (options.all && options.compare && (await getTokens())) {
verboseMessage('compare and delete option in ');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verbose message should probably be more specific, such as:

'Comparing${options.deleteAndImport ? ' and syncing' : ''} master config in '${options.file}' with deployment config.'

const outcome = await compareWithMasterFileAndDeleteFromCloud(
options.file, // Master File
options.deleteAndImport, //what if
{
useStringArrays: false,
noDecode: undefined,
coords: false, // we are not going to get coords value in case master does not have coord values.
includeDefault: undefined,
includeActiveValues: false, //we are not going to get active values from tenant in comparison to be safe.
target: undefined,
includeReadOnly: undefined,
onlyRealm: undefined,
onlyGlobal: undefined,
},
{
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.cleanServices,
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
}
);
if (!outcome) process.exitCode = 1;
}
// require --directory -D for all-separate function
else if (options.allSeparate && !state.getDirectory()) {
printMessage(
Expand All @@ -135,7 +189,11 @@ export default function setup() {
process.exitCode = 1;
}
// --all-separate -A
else if (options.allSeparate && (await getTokens())) {
else if (
options.allSeparate &&
!options.compare &&
(await getTokens())
) {
verboseMessage('Importing everything from separate files...');
const outcome = await importEverythingFromFiles({
reUuidJourneys: options.reUuidJourneys,
Expand All @@ -147,6 +205,39 @@ export default function setup() {
});
if (!outcome) process.exitCode = 1;
}
//what I added
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment

else if (
options.allSeparate &&
options.compare &&
(await getTokens())
) {
verboseMessage('Export-compare-delete-import option in ...');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message should be updated to be more specific, such as:
'Comparing${options.deleteAndImport ? ' and syncing' : ''} master config in '${state.getDirectory()}' with deployment config.'

const outcome = await compareWithMasterDirectoryAndDeleteFromCloud(
options.deleteAndImport, //what-if
{
// export options
useStringArrays: false,
noDecode: false,
coords: false, // we are not going to get coords value in case master does not have coord values.
includeDefault: undefined,
includeActiveValues: false, //we are not going to get active values from tenant in comparison to be safe.
target: undefined,
includeReadOnly: undefined,
onlyRealm: undefined,
onlyGlobal: undefined,
},
{
//import options
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.cleanServices,
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
}
);
if (!outcome) process.exitCode = 1;
}
// Import entity from file
else if (options.file && (await getTokens())) {
verboseMessage('Importing config entity from file...');
Expand Down
Loading