Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
fix(profile): add ability to reset cache when the command is executed…
Browse files Browse the repository at this point in the history
… against an org multiple times

The PR adds an additional flag --resetcache to merge/reconcile which provides ability to reset cache
as required among subsequent runs

fixes #1413
  • Loading branch information
azlam-abdulsalam committed Oct 13, 2023
1 parent f28b47f commit 2e91203
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/sfpowerscripts-cli/messages/profile_merge.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"folderFlagDescription": "comma separated list of folders to scan for profiles. If ommited, the folders in the packageDirectories configuration will be used.",
"profileListFlagDescription": "comma separated list of profiles. If ommited, all the profiles found in the folder(s) will be merged",
"metadataFlagDescription": "comma separated list of metadata for which the permissions will be retrieved.",
"deleteFlagDescription": "set this flag to delete profile files that does not exist in the org."
"deleteFlagDescription": "set this flag to delete profile files that does not exist in the org.",
"resetCacheFlagDescription": "set this flag to reset the cache and retrieve the latest profile permissions from the org."
}
3 changes: 2 additions & 1 deletion packages/sfpowerscripts-cli/messages/profile_reconcile.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"nameFlagDescription": "list of profiles to be reconciled. If ommited, all the profiles components will be reconciled.",
"destFolderFlagDescription": " the destination folder for reconciled profiles, if omitted existing profiles will be reconciled and will be rewritten in the current location",
"sourceonlyFlagDescription": "set this flag to reconcile profiles only against component available in the project only. Configure ignored perissions in sfdx-project.json file in the array plugins->sfpowerkit->ignoredPermissions.",
"targetorgFlagDescription": " org against which profiles will be reconciled. this parameter can be ommited if sourceonly flag is set."
"targetorgFlagDescription": " org against which profiles will be reconciled. this parameter can be ommited if sourceonly flag is set.",
"resetCacheFlagDescription": "set this flag to reset the cache and retrieve the latest profile permissions from the org."
}
14 changes: 5 additions & 9 deletions packages/sfpowerscripts-cli/src/commands/profile/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default class Merge extends SfpowerscriptsCommand {
description: messages.getMessage('deleteFlagDescription'),
required: false,
}),
resetcache: Flags.boolean({
description: messages.getMessage('resetCacheFlagDescription'),
required: false,
}),
targetorg: requiredUserNameFlag,
'apiversion': orgApiVersionFlagSfdxStyle,
loglevel,
Expand All @@ -60,15 +64,7 @@ export default class Merge extends SfpowerscriptsCommand {
let argProfileList = this.flags.profilelist;
let argMetadatas = this.flags.metadata;

// argMetadatas = (val: string) => {
// let parts = val.split(':');
// return {
// MetadataType: parts[0].trim(),
// ApiName: parts.length >= 2 ? parts[1].trim() : '*',
// };
// };

Sfpowerkit.initCache();
Sfpowerkit.initCache(this.flags.resetcache);

let metadatas = undefined;
let invalidArguments = [];
Expand Down
5 changes: 5 additions & 0 deletions packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default class Reconcile extends SfpowerscriptsCommand {
description: messages.getMessage('sourceonlyFlagDescription'),
required: false,
}),
resetcache: Flags.boolean({
description: messages.getMessage('resetCacheFlagDescription'),
required: false,
}),
targetorg: requiredUserNameFlag,
'apiversion': orgApiVersionFlagSfdxStyle,
loglevel,
Expand All @@ -67,6 +71,7 @@ export default class Reconcile extends SfpowerscriptsCommand {
public async execute(): Promise<Array<{state: any, fullName: any, type: any, path: any}>> {
let argFolder = this.flags.folder;
let argProfileList = this.flags.profilelist;
Sfpowerkit.initCache(this.flags.resetcache);

if (!this.flags.sourceonly) {
if (_.isNil(this.flags.targetorg)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Retrieve extends SfpowerscriptsCommand {
folders.push(...argFolder);
}

Sfpowerkit.initCache();
Sfpowerkit.initCache(true);

SFPLogger.log(COLOR_WARNING(messages.getMessage('retriveDelayWarning')),LoggerLevel.INFO);
SFPLogger.log(COLOR_KEY_MESSAGE(`Retrieving profiles from ${this.flags.targetorg}`),LoggerLevel.INFO );
Expand Down
4 changes: 3 additions & 1 deletion packages/sfprofiles/src/utils/sfpowerkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export class Sfpowerkit {
fs.unlinkSync(cachePath);
}

public static initCache() {
public static initCache(resetCache?:boolean) {
try {
if(resetCache)
Sfpowerkit.resetCache();
//Set the cache path on init,
//TODO: Move this to a temporary directory with randomization
Sfpowerkit.cache = new SQLITEKeyValue(FileUtils.getLocalCachePath('sfpowerkit-cache.db'));
Expand Down

0 comments on commit 2e91203

Please sign in to comment.