Skip to content

Commit

Permalink
Merge pull request #384 from vscheuber/main
Browse files Browse the repository at this point in the history
update to frodo-lib 2.0.0-77 and remove secrets from recordings
  • Loading branch information
vscheuber authored Apr 9, 2024
2 parents a607bcb + 512988f commit 9733f59
Show file tree
Hide file tree
Showing 380 changed files with 1,325,040 additions and 165,031 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Update to frodo-lib 2.0.0-77

### Fixed

- Improved filtering out secrets from recordings
- rockcarver/frodo-lib#392: Implemented error handling pattern for methods with unusual amounts of REST calls like `frodo.config.exportFullConfiguration` and `frodo.config.importFullConfiguration` used in the `frodo config import` and `frodo config export` commands

## [2.0.0-54] - 2024-04-01

### Changed
Expand Down
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 @@ -119,7 +119,7 @@
]
},
"dependencies": {
"@rockcarver/frodo-lib": "2.0.0-75",
"@rockcarver/frodo-lib": "2.0.0-77",
"chokidar": "^3.5.3",
"cli-progress": "^3.11.2",
"cli-table3": "^0.6.3",
Expand Down
49 changes: 31 additions & 18 deletions src/cli/config/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,44 @@ program
// --all -a
if (options.all && (await getTokens())) {
verboseMessage('Exporting everything to a single file...');
await exportEverythingToFile(options.file, options.metadata, {
useStringArrays: options.useStringArrays,
noDecode: options.decode,
coords: options.coords,
includeDefault: options.default,
});
// require --directory -D for all-separate function
} else if (options.allSeparate && !state.getDirectory()) {
const outcome = await exportEverythingToFile(
options.file,
options.metadata,
{
useStringArrays: options.useStringArrays,
noDecode: options.decode,
coords: options.coords,
includeDefault: options.default,
}
);
if (!outcome) process.exitCode = 1;
}
// 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())) {
}
// --all-separate -A
else if (options.allSeparate && (await getTokens())) {
verboseMessage('Exporting everything to separate files...');
await exportEverythingToFiles(options.extract, options.metadata, {
useStringArrays: options.useStringArrays,
noDecode: options.decode,
coords: options.coords,
includeDefault: options.default,
});
// unrecognized combination of options or no options
} else {
const outcome = await exportEverythingToFiles(
options.extract,
options.metadata,
{
useStringArrays: options.useStringArrays,
noDecode: options.decode,
coords: options.coords,
includeDefault: options.default,
}
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
verboseMessage('Unrecognized combination of options or no options...');
program.help();
process.exitCode = 1;
Expand Down
26 changes: 16 additions & 10 deletions src/cli/config/config-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,44 @@ program
printMessage('-f or --file required when using -a or --all', 'error');
program.help();
process.exitCode = 1;
// --all -a
} else if (options.all && (await getTokens())) {
}
// --all -a
else if (options.all && (await getTokens())) {
verboseMessage('Exporting everything from a single file...');
await importEverythingFromFile(options.file, {
const outcome = await importEverythingFromFile(options.file, {
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.clean,
global: options.global,
realm: options.realm,
includeDefault: options.default,
});
// require --directory -D for all-separate function
} else if (options.allSeparate && !state.getDirectory()) {
if (!outcome) process.exitCode = 1;
}
// 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())) {
}
// --all-separate -A
else if (options.allSeparate && (await getTokens())) {
verboseMessage('Importing everything from separate files...');
await importEverythingFromFiles({
const outcome = await importEverythingFromFiles({
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.clean,
global: options.global,
realm: options.realm,
includeDefault: options.default,
});
// unrecognized combination of options or no options
} else {
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
verboseMessage('Unrecognized combination of options or no options...');
program.help();
process.exitCode = 1;
Expand Down
65 changes: 52 additions & 13 deletions src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { frodo, FrodoError, state } from '@rockcarver/frodo-lib';
import {
FullExportInterface,
FullExportOptions,
Expand All @@ -12,7 +12,7 @@ import {
getFullExportConfig,
getFullExportConfigFromDirectory,
} from '../utils/Config';
import { printError, printMessage } from '../utils/Console';
import { cleanupProgressIndicators, printError, printMessage } from '../utils/Console';

Check warning on line 15 in src/ops/ConfigOps.ts

View workflow job for this annotation

GitHub Actions / Build

Replace `·cleanupProgressIndicators,·printError,·printMessage·` with `⏎··cleanupProgressIndicators,⏎··printError,⏎··printMessage,⏎`
import { extractScriptToFile } from './ScriptOps';

const {
Expand All @@ -31,6 +31,7 @@ const { exportFullConfiguration, importFullConfiguration } = frodo.config;
* @param {String} file file name
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
* @param {FullExportOptions} options export options
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function exportEverythingToFile(
file: string,
Expand All @@ -41,9 +42,10 @@ export async function exportEverythingToFile(
coords: true,
includeDefault: false,
}
): Promise<void> {
): Promise<boolean> {
try {
const exportData = await exportFullConfiguration(options);
const collectErrors: Error[] = [];
const exportData = await exportFullConfiguration(options, collectErrors);
let fileName = getTypedFilename(
`${titleCase(getRealmName(state.getRealm()))}`,
`everything`
Expand All @@ -52,16 +54,22 @@ export async function exportEverythingToFile(
fileName = file;
}
saveJsonToFile(exportData, getFilePath(fileName, true), includeMeta);
if (collectErrors.length > 0) {
throw new FrodoError(`Errors occurred during full export`, collectErrors);
}
return true;
} catch (error) {
printError(error);
}
return false;
}

/**
* Export everything to separate files
* @param {boolean} extract Extracts the scripts from the exports into separate files if true
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
* @param {FullExportOptions} options export options
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function exportEverythingToFiles(
extract: boolean = false,
Expand All @@ -72,10 +80,13 @@ export async function exportEverythingToFiles(
coords: true,
includeDefault: false,
}
): Promise<void> {
): Promise<boolean> {
try {
const exportData: FullExportInterface =
await exportFullConfiguration(options);
const collectErrors: Error[] = [];
const exportData: FullExportInterface = await exportFullConfiguration(
options,
collectErrors
);
delete exportData.meta;
const baseDirectory = getWorkingDirectory(true);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -174,7 +185,9 @@ export async function exportEverythingToFiles(
}
} else {
const filename = getTypedFilename(
value && value.name ? value.name : id,
value && value.name && type !== 'emailTemplate'
? value.name
: id,
type
);
if (extract && type == 'script') {
Expand All @@ -198,15 +211,21 @@ export async function exportEverythingToFiles(
}
}
});
if (collectErrors.length > 0) {
throw new FrodoError(`Errors occurred during full export`, collectErrors);
}
return true;
} catch (error) {
printError(error);
}
return false;
}

/**
* Import everything from a single file
* @param {String} file The file path
* @param {string} file The file path
* @param {FullImportOptions} options import options
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function importEverythingFromFile(
file: string,
Expand All @@ -218,17 +237,28 @@ export async function importEverythingFromFile(
realm: false,
includeDefault: false,
}
) {
): Promise<boolean> {
try {
const data = await getFullExportConfig(file);
await importFullConfiguration(data, options);
const collectErrors: Error[] = [];
await importFullConfiguration(data, options, collectErrors);
if (collectErrors.length > 0) {
throw new FrodoError(
`Errors occurred during full config import`,
collectErrors
);
}
return true;
} catch (error) {
cleanupProgressIndicators();
printError(error);
}
return false;
}

/**
* Import everything from separate files
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function importEverythingFromFiles(
options: FullImportOptions = {
Expand All @@ -239,11 +269,20 @@ export async function importEverythingFromFiles(
realm: false,
includeDefault: false,
}
) {
): Promise<boolean> {
try {
const data = await getFullExportConfigFromDirectory(state.getDirectory());
await importFullConfiguration(data, options);
const collectErrors: Error[] = [];
await importFullConfiguration(data, options, collectErrors);
if (collectErrors.length > 0) {
throw new FrodoError(
`Errors occurred during full config import`,
collectErrors
);
}
return true;
} catch (error) {
printError(error);
}
return false;
}
15 changes: 14 additions & 1 deletion src/ops/IdmOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,16 @@ export async function importConfigEntityFromFile(
file: string,
validate?: boolean
): Promise<boolean> {
const filePath = getFilePath(file);
let indicatorId: string;
try {
indicatorId = createProgressIndicator(
'indeterminate',
0,
`Importing ${filePath}...`
);
const fileData = fs.readFileSync(
path.resolve(process.cwd(), getFilePath(file)),
path.resolve(process.cwd(), filePath),
'utf8'
);
const entityData = JSON.parse(fileData);
Expand All @@ -262,8 +269,14 @@ export async function importConfigEntityFromFile(
}

await updateConfigEntity(entityId, entityData);
stopProgressIndicator(
indicatorId,
`Imported ${entityId} from ${filePath}.`,
'success'
);
return true;
} catch (error) {
stopProgressIndicator(indicatorId, `Error importing ${filePath}.`, 'fail');
printError(error);
}
return false;
Expand Down
Loading

0 comments on commit 9733f59

Please sign in to comment.