From 2e91203a8a0c017401e5f9d5cd40748fe3e50436 Mon Sep 17 00:00:00 2001 From: azlam Date: Fri, 13 Oct 2023 14:21:47 +1100 Subject: [PATCH] fix(profile): add ability to reset cache when the command is executed 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 --- .../sfpowerscripts-cli/messages/profile_merge.json | 3 ++- .../messages/profile_reconcile.json | 3 ++- .../src/commands/profile/merge.ts | 14 +++++--------- .../src/commands/profile/reconcile.ts | 5 +++++ .../src/commands/profile/retrieve.ts | 2 +- packages/sfprofiles/src/utils/sfpowerkit.ts | 4 +++- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/sfpowerscripts-cli/messages/profile_merge.json b/packages/sfpowerscripts-cli/messages/profile_merge.json index f477a2467..6f93dadc2 100644 --- a/packages/sfpowerscripts-cli/messages/profile_merge.json +++ b/packages/sfpowerscripts-cli/messages/profile_merge.json @@ -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." } diff --git a/packages/sfpowerscripts-cli/messages/profile_reconcile.json b/packages/sfpowerscripts-cli/messages/profile_reconcile.json index 8248bc9d6..4d0eaee6f 100644 --- a/packages/sfpowerscripts-cli/messages/profile_reconcile.json +++ b/packages/sfpowerscripts-cli/messages/profile_reconcile.json @@ -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." } diff --git a/packages/sfpowerscripts-cli/src/commands/profile/merge.ts b/packages/sfpowerscripts-cli/src/commands/profile/merge.ts index 01d93482d..97dabf53b 100644 --- a/packages/sfpowerscripts-cli/src/commands/profile/merge.ts +++ b/packages/sfpowerscripts-cli/src/commands/profile/merge.ts @@ -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, @@ -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 = []; diff --git a/packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts b/packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts index cb9e85402..7e3bad3dc 100644 --- a/packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts +++ b/packages/sfpowerscripts-cli/src/commands/profile/reconcile.ts @@ -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, @@ -67,6 +71,7 @@ export default class Reconcile extends SfpowerscriptsCommand { public async execute(): Promise> { let argFolder = this.flags.folder; let argProfileList = this.flags.profilelist; + Sfpowerkit.initCache(this.flags.resetcache); if (!this.flags.sourceonly) { if (_.isNil(this.flags.targetorg)) { diff --git a/packages/sfpowerscripts-cli/src/commands/profile/retrieve.ts b/packages/sfpowerscripts-cli/src/commands/profile/retrieve.ts index 0f55d6be9..09b938462 100644 --- a/packages/sfpowerscripts-cli/src/commands/profile/retrieve.ts +++ b/packages/sfpowerscripts-cli/src/commands/profile/retrieve.ts @@ -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 ); diff --git a/packages/sfprofiles/src/utils/sfpowerkit.ts b/packages/sfprofiles/src/utils/sfpowerkit.ts index 9d0b4afdd..aa6e3bd7e 100644 --- a/packages/sfprofiles/src/utils/sfpowerkit.ts +++ b/packages/sfprofiles/src/utils/sfpowerkit.ts @@ -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'));