snyk 1.858.0 → 1.859.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/272.index.js +50 -1
- package/dist/cli/272.index.js.map +1 -1
- package/dist/cli/459.index.js +14 -2
- package/dist/cli/459.index.js.map +1 -1
- package/dist/cli/commands/test/iac-local-execution/types.d.ts +11 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/iac/drift.d.ts +4 -1
- package/help/cli-commands/iac-drift-scan.md +43 -23
- package/package.json +1 -1
package/dist/cli/272.index.js
CHANGED
|
@@ -1479,6 +1479,24 @@ function terraformPlanReducer(scanInput, resource) {
|
|
|
1479
1479
|
}
|
|
1480
1480
|
return scanInput;
|
|
1481
1481
|
}
|
|
1482
|
+
function getExpressions(expressions) {
|
|
1483
|
+
const result = {};
|
|
1484
|
+
// expressions can be nested. we are only doing 1 depth to resolve top level depenencies
|
|
1485
|
+
for (const key of Object.keys(expressions)) {
|
|
1486
|
+
const referenceKey = getReference(expressions[key]);
|
|
1487
|
+
if (referenceKey) {
|
|
1488
|
+
result[key] = referenceKey;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
return result;
|
|
1492
|
+
}
|
|
1493
|
+
// this is very naive implementation
|
|
1494
|
+
// the referenences can be composed of number of keys
|
|
1495
|
+
// we only going to use the first reference for time being
|
|
1496
|
+
function getReference(value) {
|
|
1497
|
+
var _a;
|
|
1498
|
+
return (_a = value.references) === null || _a === void 0 ? void 0 : _a[0];
|
|
1499
|
+
}
|
|
1482
1500
|
function getResourceName(index, name) {
|
|
1483
1501
|
return index !== undefined ? `${name}["${index}"]` : name;
|
|
1484
1502
|
}
|
|
@@ -1502,15 +1520,46 @@ function isValidResourceActions(action, isFullScan) {
|
|
|
1502
1520
|
return validAction.every((field, idx) => action[idx] === field);
|
|
1503
1521
|
});
|
|
1504
1522
|
}
|
|
1523
|
+
function referencedResourcesResolver(scanInput, resources) {
|
|
1524
|
+
var _a, _b;
|
|
1525
|
+
// check root module for references in first depth of attributes
|
|
1526
|
+
for (const resource of resources) {
|
|
1527
|
+
const { type, name, mode, index, expressions } = resource;
|
|
1528
|
+
// don't care about references in data sources for time being
|
|
1529
|
+
if (mode == 'data') {
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
const inputKey = 'resource';
|
|
1533
|
+
// only update the references in resources that have some resolved attributes already
|
|
1534
|
+
const resolvedResource = (_b = (_a = scanInput[inputKey]) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b[getResourceName(index, name)];
|
|
1535
|
+
if (resolvedResource) {
|
|
1536
|
+
const resourceExpressions = getExpressions(expressions);
|
|
1537
|
+
for (const key of Object.keys(resourceExpressions)) {
|
|
1538
|
+
// only add non existing attributes. If we already have resolved value do not overwrite it with reference
|
|
1539
|
+
if (!resolvedResource[key]) {
|
|
1540
|
+
resolvedResource[key] = resourceExpressions[key];
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
scanInput[inputKey][type][getResourceName(index, name)] = resolvedResource;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
return scanInput;
|
|
1547
|
+
}
|
|
1505
1548
|
function extractResourceChanges(terraformPlanJson) {
|
|
1506
1549
|
return terraformPlanJson.resource_changes || [];
|
|
1507
1550
|
}
|
|
1551
|
+
function extractReferencedResources(terraformPlanJson) {
|
|
1552
|
+
var _a, _b;
|
|
1553
|
+
return ((_b = (_a = terraformPlanJson.configuration) === null || _a === void 0 ? void 0 : _a.root_module) === null || _b === void 0 ? void 0 : _b.resources) || [];
|
|
1554
|
+
}
|
|
1508
1555
|
function extractResourcesForScan(terraformPlanJson, isFullScan = false) {
|
|
1509
1556
|
const resourceChanges = extractResourceChanges(terraformPlanJson);
|
|
1510
|
-
|
|
1557
|
+
const scanInput = resourceChanges.reduce((memo, curr) => resourceChangeReducer(memo, curr, isFullScan), {
|
|
1511
1558
|
resource: {},
|
|
1512
1559
|
data: {},
|
|
1513
1560
|
});
|
|
1561
|
+
const referencedResources = extractReferencedResources(terraformPlanJson);
|
|
1562
|
+
return referencedResourcesResolver(scanInput, referencedResources);
|
|
1514
1563
|
}
|
|
1515
1564
|
function isTerraformPlan(terraformPlanJson) {
|
|
1516
1565
|
const missingRequiredFields = terraformPlanJson.resource_changes === undefined;
|