cdk-real-drift 0.12.20 → 0.12.22
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.js +79 -8
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -594,6 +594,19 @@ async function loadConfig() {
|
|
|
594
594
|
if (e.code === "ENOENT") return { ignore: [] };
|
|
595
595
|
throw e;
|
|
596
596
|
}
|
|
597
|
+
return parseConfigRaw(raw);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Validate-and-parse the decoded `.cdkrd/ignore.yaml` text into a `CdkrdConfig`. This is
|
|
601
|
+
* loadConfig's body AFTER the read+decode, factored out so a caller that ALREADY holds the
|
|
602
|
+
* raw bytes (addIgnoreRules' pre-write `existingRaw`) can derive the same validated config
|
|
603
|
+
* from the SAME snapshot — without a second `readFile`. Sharing one snapshot between the
|
|
604
|
+
* write basis and the dedupe basis is the #1290 fix: a peer rule that landed on disk between
|
|
605
|
+
* two separate reads would otherwise be in the dedupe basis but not the write basis, and get
|
|
606
|
+
* clobbered. Applies every guard loadConfig applied on read (syntax errors, alias/anchor,
|
|
607
|
+
* non-mapping, unknown top-level key, `ignore` typed as an array, per-entry validation).
|
|
608
|
+
*/
|
|
609
|
+
function parseConfigRaw(raw) {
|
|
597
610
|
let parsed;
|
|
598
611
|
const doc = parseDocument(raw, { prettyErrors: true });
|
|
599
612
|
const [firstError] = doc.errors;
|
|
@@ -798,6 +811,10 @@ async function atomicWrite(dest, content) {
|
|
|
798
811
|
* a concurrent `cdkrd` process, the on-disk config is RE-READ immediately before the write
|
|
799
812
|
* and the incoming rules merged against THAT fresh state — so a rule another process
|
|
800
813
|
* appended between our initial `loadConfig` and our write is preserved, not clobbered.
|
|
814
|
+
* The re-read is a SINGLE snapshot: both the write basis (`existingRaw`, re-emitted with its
|
|
815
|
+
* comments) and the dedupe basis (`parseConfigRaw(existingRaw)`) come from those same bytes,
|
|
816
|
+
* so a peer rule on disk is BOTH carried forward AND deduped against — never in one but not
|
|
817
|
+
* the other (#1290).
|
|
801
818
|
*/
|
|
802
819
|
async function addIgnoreRules(newRules) {
|
|
803
820
|
const firstPass = mergeIgnoreRules((await loadConfig()).ignore, newRules);
|
|
@@ -814,7 +831,7 @@ async function addIgnoreRules(newRules) {
|
|
|
814
831
|
} catch (e) {
|
|
815
832
|
if (e.code !== "ENOENT") throw e;
|
|
816
833
|
}
|
|
817
|
-
const { added, alreadyPresent } = mergeIgnoreRules(existingRaw !== void 0 && existingRaw.trim() !== "" ? (
|
|
834
|
+
const { added, alreadyPresent } = mergeIgnoreRules(existingRaw !== void 0 && existingRaw.trim() !== "" ? parseConfigRaw(existingRaw).ignore : [], newRules);
|
|
818
835
|
if (added.length === 0) return {
|
|
819
836
|
path: CONFIG_PATH,
|
|
820
837
|
added,
|
|
@@ -11920,17 +11937,42 @@ const maskMapValues = (value) => {
|
|
|
11920
11937
|
}
|
|
11921
11938
|
return maskPlaceholder(value);
|
|
11922
11939
|
};
|
|
11940
|
+
const maskEnvironmentContainer = (value) => {
|
|
11941
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "Variables" in value) return {
|
|
11942
|
+
...value,
|
|
11943
|
+
Variables: maskMapValues(value.Variables)
|
|
11944
|
+
};
|
|
11945
|
+
return value;
|
|
11946
|
+
};
|
|
11947
|
+
const maskEnvVarArrayElement = (element) => {
|
|
11948
|
+
if (element && typeof element === "object" && !Array.isArray(element) && "Value" in element) return {
|
|
11949
|
+
...element,
|
|
11950
|
+
Value: maskPlaceholder(element.Value)
|
|
11951
|
+
};
|
|
11952
|
+
return element;
|
|
11953
|
+
};
|
|
11954
|
+
const maskEnvVarArray = (value) => Array.isArray(value) ? value.map(maskEnvVarArrayElement) : maskEnvVarArrayElement(value);
|
|
11923
11955
|
const REDACTED_VALUE_PATHS = {
|
|
11924
|
-
"AWS::Lambda::Function": [
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
11929
|
-
|
|
11930
|
-
|
|
11956
|
+
"AWS::Lambda::Function": [
|
|
11957
|
+
{
|
|
11958
|
+
pathRe: /(^|\.)Environment\.Variables\./,
|
|
11959
|
+
redact: maskWhole
|
|
11960
|
+
},
|
|
11961
|
+
{
|
|
11962
|
+
pathRe: /(^|\.)Environment\.Variables$/,
|
|
11963
|
+
redact: maskMapValues
|
|
11964
|
+
},
|
|
11965
|
+
{
|
|
11966
|
+
pathRe: /(^|\.)Environment$/,
|
|
11967
|
+
redact: maskEnvironmentContainer
|
|
11968
|
+
}
|
|
11969
|
+
],
|
|
11931
11970
|
"AWS::CodeBuild::Project": [{
|
|
11932
11971
|
pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
|
|
11933
11972
|
redact: maskWhole
|
|
11973
|
+
}, {
|
|
11974
|
+
pathRe: /(^|\.)Environment\.EnvironmentVariables$/,
|
|
11975
|
+
redact: maskEnvVarArray
|
|
11934
11976
|
}],
|
|
11935
11977
|
"AWS::EC2::LaunchTemplate": [{
|
|
11936
11978
|
pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
|
|
@@ -12592,6 +12634,18 @@ function addedChildParentLogicalId(logicalId) {
|
|
|
12592
12634
|
const slash = logicalId.indexOf("/");
|
|
12593
12635
|
return slash < 0 ? void 0 : logicalId.slice(0, slash);
|
|
12594
12636
|
}
|
|
12637
|
+
function addedChildIdentifier(logicalId) {
|
|
12638
|
+
const slash = logicalId.indexOf("/");
|
|
12639
|
+
return slash < 0 ? void 0 : logicalId.slice(slash + 1);
|
|
12640
|
+
}
|
|
12641
|
+
function addedChildWasAdopted(childLogicalId, physicalIdByLogical) {
|
|
12642
|
+
if (physicalIdByLogical === void 0 || physicalIdByLogical.size === 0) return false;
|
|
12643
|
+
const identifier = addedChildIdentifier(childLogicalId);
|
|
12644
|
+
if (identifier === void 0) return false;
|
|
12645
|
+
const trailing = identifier.slice(identifier.lastIndexOf("|") + 1);
|
|
12646
|
+
for (const livePhysicalId of physicalIdByLogical.values()) if (livePhysicalId === identifier || livePhysicalId === trailing) return true;
|
|
12647
|
+
return false;
|
|
12648
|
+
}
|
|
12595
12649
|
function descendDeclared(node, seg) {
|
|
12596
12650
|
if (node === null || typeof node !== "object") return void 0;
|
|
12597
12651
|
if (Array.isArray(node)) {
|
|
@@ -12724,11 +12778,16 @@ function applyBaseline(findings, baseline, opts = {}) {
|
|
|
12724
12778
|
const removedFromTemplate = [];
|
|
12725
12779
|
const replacedStale = [];
|
|
12726
12780
|
const typeMismatchStale = [];
|
|
12781
|
+
const adoptedStale = [];
|
|
12727
12782
|
for (const a of recorded) {
|
|
12728
12783
|
if (a.path === "") {
|
|
12729
12784
|
if (presentAddedLogical.has(a.logicalId)) continue;
|
|
12730
12785
|
const parent = addedChildParentLogicalId(a.logicalId);
|
|
12731
12786
|
if (!(parent !== void 0 && readParentLogical.has(parent))) continue;
|
|
12787
|
+
if (addedChildWasAdopted(a.logicalId, opts.physicalIdByLogical)) {
|
|
12788
|
+
adoptedStale.push(a.logicalId);
|
|
12789
|
+
continue;
|
|
12790
|
+
}
|
|
12732
12791
|
kept.push({
|
|
12733
12792
|
tier: "deleted",
|
|
12734
12793
|
logicalId: a.logicalId,
|
|
@@ -12775,6 +12834,7 @@ function applyBaseline(findings, baseline, opts = {}) {
|
|
|
12775
12834
|
if (removedFromTemplate.length > 0) opts.warn?.(formatRemovedFromTemplateNote(removedFromTemplate));
|
|
12776
12835
|
if (replacedStale.length > 0) opts.warn?.(formatReplacedStaleNote(replacedStale));
|
|
12777
12836
|
if (typeMismatchStale.length > 0) opts.warn?.(formatTypeMismatchStaleNote(typeMismatchStale));
|
|
12837
|
+
if (adoptedStale.length > 0) opts.warn?.(formatAdoptedStaleNote(adoptedStale));
|
|
12778
12838
|
return kept;
|
|
12779
12839
|
}
|
|
12780
12840
|
/**
|
|
@@ -12815,6 +12875,17 @@ function formatTypeMismatchStaleNote(paths) {
|
|
|
12815
12875
|
return `note: ${n === 1 ? `baseline entry (${paths[0]}) was` : `${n} baseline entries were`} recorded against a resource whose logicalId now has a DIFFERENT type — re-run \`cdkrd record\`.`;
|
|
12816
12876
|
}
|
|
12817
12877
|
/**
|
|
12878
|
+
* #1279: the folded one-line note for recorded out-of-band `added` resources that have since
|
|
12879
|
+
* been ADOPTED into the template (`cdk import`, or re-declared + deployed) — the child is no
|
|
12880
|
+
* longer enumerated as `added`, but its identifier matches a template resource's live physical
|
|
12881
|
+
* id, so it is alive and now IaC-managed, not deleted. Mirror of formatReplacedStaleNote. Pure
|
|
12882
|
+
* + exported for unit tests.
|
|
12883
|
+
*/
|
|
12884
|
+
function formatAdoptedStaleNote(logicalIds) {
|
|
12885
|
+
const n = logicalIds.length;
|
|
12886
|
+
return `note: ${n === 1 ? `recorded added resource (${logicalIds[0]}) was` : `${n} recorded added resources were`} adopted into the template (now IaC-managed) — re-run \`cdkrd record\` to clean up the baseline.`;
|
|
12887
|
+
}
|
|
12888
|
+
/**
|
|
12818
12889
|
* logicalId -> the resource's declared model, for applyBaseline's promotion check.
|
|
12819
12890
|
* #1079: carries the WHOLE declared object (not just its top-level key set) so a NESTED
|
|
12820
12891
|
* recorded path the user later declares is RESOLVED against the declared tree and folded
|