UNPKG

az-deployment-denoise

Version:
70 lines 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.denoiseOperationResult = denoiseOperationResult; const azure_1 = require("./utils/azure"); function matchString(condition, value) { return condition === undefined || condition === value; } function matchStringRegex(condition, value) { return condition === undefined || new RegExp(condition).test(value); } function filterPropertyChanges(propertyChange, resourceId, rules, parentPath = '', isArray = false) { return propertyChange.map(pc => { let fullPath; if (isArray) { fullPath = `${parentPath}[]`; } else { fullPath = parentPath === '' ? pc.path : `${parentPath}.${pc.path}`; } for (const rule of rules) { const resource = (0, azure_1.parseAzureResource)(resourceId); const resourceGroupMatched = matchString(rule.resourceGroupName, resource.resourceGroup.name); const providerNamespaceMatched = matchString(rule.providerNamespace, resource.providerNamespace); const resourceTypeMatched = matchString(rule.resourceType, resource.type); const resourceNameMatched = matchString(rule.resourceName, resource.name); const resourceNameRegexMatched = matchStringRegex(rule.resourceNameRegex, resource.name); const propertyChangeTypeMatched = matchString(rule.propertyChangeType, pc.propertyChangeType); const pathMatched = matchString(rule.propertyPath, fullPath); if (resourceGroupMatched && providerNamespaceMatched && resourceTypeMatched && resourceNameMatched && resourceNameRegexMatched && propertyChangeTypeMatched && pathMatched) { return null; } } if (pc.propertyChangeType === 'Modify' && pc.children !== null) { pc.children = filterPropertyChanges(pc.children, resourceId, rules, fullPath); if (pc.children.length == 0) { return null; } return pc; } else if (pc.propertyChangeType === 'Array' && pc.children !== null) { pc.children = filterPropertyChanges(pc.children, resourceId, rules, fullPath, true); if (pc.children.length == 0) { return null; } return pc; } return pc; }).filter(pc => pc != null); } function denoiseOperationResult(operationReuslt, rules) { const filteredResult = structuredClone(operationReuslt); filteredResult.changes = filteredResult.changes.map(c => { if (c.changeType !== 'Modify') { return c; } c.delta = filterPropertyChanges(c.delta, c.resourceId, rules); if (c.delta.length == 0) { c.changeType = 'NoChange'; } return c; }).filter(c => c != null); return filteredResult; } //# sourceMappingURL=rule-engine.js.map