From 2f58374c395f0f23224a723f8dfed91c47f77d4f Mon Sep 17 00:00:00 2001 From: Cody Jackson Date: Mon, 23 Dec 2019 10:10:05 -0700 Subject: [PATCH] Ensure skipping works for multiple cis versions We validating the security scan config appropriately when a version was already present in the skip list. This now ensures a version exists before verifying that it contains an array. We were also replacing the existing skip object in the security-scan-config which prevented us from storing multiple versions at a time. We now extend the object instead using the spread operator. rancher/rancher#24733 rancher/rancher#24742 --- app/authenticated/cluster/cis/scan/controller.js | 4 ++-- .../cluster/cis/scan/detail/controller.js | 2 +- lib/shared/addon/security-scan-config/service.js | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/authenticated/cluster/cis/scan/controller.js b/app/authenticated/cluster/cis/scan/controller.js index ebf61ca2d..19c41f399 100644 --- a/app/authenticated/cluster/cis/scan/controller.js +++ b/app/authenticated/cluster/cis/scan/controller.js @@ -49,7 +49,7 @@ export default Controller.extend({ runningClusterScans: computed.filterBy('clusterScans', 'isRunning', true), - isRKE: computed.alias('scope.currentCluster.isRKE'), + isRKE: computed.alias('scope.currentCluster.isRKE'), actions: { runScan() { get(this, 'scope.currentCluster').doAction('runSecurityScan', { @@ -59,7 +59,7 @@ export default Controller.extend({ } }, disableRunScanButton: computed('runningClusterScans', 'scope.currentCluster.systemProject', function() { - return get(this, 'runningClusterScans') || !get(this, 'scope.currentCluster.systemProject'); + return get(this, 'runningClusterScans.length') > 0 || !get(this, 'scope.currentCluster.systemProject'); }), bulkActionHandler: computed(function() { diff --git a/app/authenticated/cluster/cis/scan/detail/controller.js b/app/authenticated/cluster/cis/scan/detail/controller.js index 08f5cf61b..ba30e091a 100644 --- a/app/authenticated/cluster/cis/scan/detail/controller.js +++ b/app/authenticated/cluster/cis/scan/detail/controller.js @@ -62,7 +62,7 @@ export default Controller.extend({ }, disableRunScanButton: computed('runningClusterScans', 'scope.currentCluster.systemProject', function() { - return get(this, 'runningClusterScans') || !get(this, 'scope.currentCluster.systemProject'); + return get(this, 'runningClusterScans.length') > 0 || !get(this, 'scope.currentCluster.systemProject'); }), tests: computed('model.scan.report', 'securityScanConfig.skipList', function() { diff --git a/lib/shared/addon/security-scan-config/service.js b/lib/shared/addon/security-scan-config/service.js index 466e072b0..15087f95b 100644 --- a/lib/shared/addon/security-scan-config/service.js +++ b/lib/shared/addon/security-scan-config/service.js @@ -77,7 +77,7 @@ export default Service.extend({ return; } - if (!Array.isArray(parsed.skip[version])) { + if (parsed.skip[version] && !Array.isArray(parsed.skip[version])) { throw new Error("Security Scan Config didin't contain the 'skip' array."); } } catch (error) { @@ -145,7 +145,14 @@ export default Service.extend({ editSkipList(newValue) { const version = get(this, 'report.version'); - const newSkipListObject = { skip: { [version]: newValue } }; + + const existingSkip = get(this, 'parsedSecurityScanConfig.skip') || {}; + const newSkipListObject = { + skip: { + ...existingSkip, + [version]: newValue + } + }; const newConfig = { [get(this, 'FILE_KEY')]: JSON.stringify(newSkipListObject) }; this.editSecurityScanConfig(newConfig);