2021-07-06 08:07:43 -04:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2021-12-17 07:16:21 -05:00
|
|
|
import { SCANNER_NAMES_MAP } from '~/security_configuration/components/constants';
|
2021-07-06 08:07:43 -04:00
|
|
|
|
2022-02-15 19:15:19 -05:00
|
|
|
/**
|
|
|
|
* This function takes in 3 arrays of objects, securityFeatures, complianceFeatures and features.
|
|
|
|
* securityFeatures and complianceFeatures are static arrays living in the constants.
|
|
|
|
* features is dynamic and coming from the backend.
|
|
|
|
* This function builds a superset of those arrays.
|
|
|
|
* It looks for matching keys within the dynamic and the static arrays
|
|
|
|
* and will enrich the objects with the available static data.
|
|
|
|
* @param [{}] securityFeatures
|
|
|
|
* @param [{}] complianceFeatures
|
|
|
|
* @param [{}] features
|
|
|
|
* @returns {Object} Object with enriched features from constants divided into Security and Compliance Features
|
|
|
|
*/
|
|
|
|
|
2021-06-01 08:09:36 -04:00
|
|
|
export const augmentFeatures = (securityFeatures, complianceFeatures, features = []) => {
|
|
|
|
const featuresByType = features.reduce((acc, feature) => {
|
2021-07-06 08:07:43 -04:00
|
|
|
acc[feature.type] = convertObjectPropsToCamelCase(feature, { deep: true });
|
2021-06-01 08:09:36 -04:00
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const augmentFeature = (feature) => {
|
|
|
|
const augmented = {
|
|
|
|
...feature,
|
|
|
|
...featuresByType[feature.type],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (augmented.secondary) {
|
|
|
|
augmented.secondary = { ...augmented.secondary, ...featuresByType[feature.secondary.type] };
|
|
|
|
}
|
|
|
|
|
|
|
|
return augmented;
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
augmentedSecurityFeatures: securityFeatures.map((feature) => augmentFeature(feature)),
|
|
|
|
augmentedComplianceFeatures: complianceFeatures.map((feature) => augmentFeature(feature)),
|
|
|
|
};
|
|
|
|
};
|
2021-12-17 07:16:21 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a list of security scanner IDs (such as SAST_IAC) into a list of their translated
|
|
|
|
* names defined in the SCANNER_NAMES_MAP constant (eg. IaC Scanning).
|
|
|
|
*
|
|
|
|
* @param {String[]} scannerNames
|
|
|
|
* @returns {String[]}
|
|
|
|
*/
|
|
|
|
export const translateScannerNames = (scannerNames = []) =>
|
|
|
|
scannerNames.map((scannerName) => SCANNER_NAMES_MAP[scannerName] || scannerName);
|