cdk-real-drift 0.4.43 → 0.5.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/README.md +10 -3
- package/dist/cli.js +267 -23
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -418,9 +418,16 @@ Nothing` (see [The model](#the-model-one-verb-you-run-three-it-offers)). Each
|
|
|
418
418
|
each write. REMOVE ops (deleting a live value not in your template) are labeled
|
|
419
419
|
`(REMOVE)`. **space** toggles · **→** selects all · **←** clears all · **enter**
|
|
420
420
|
confirms. `--yes` applies the full plan.
|
|
421
|
-
- **`record`** shows a multiselect of only the **delta** from the existing
|
|
422
|
-
|
|
423
|
-
|
|
421
|
+
- **`record`** shows a multiselect of only the **delta** from the existing
|
|
422
|
+
baseline; already-recorded unchanged values are auto-kept. **New** undeclared
|
|
423
|
+
values are pre-selected; a value that **changed since record** (a recorded value
|
|
424
|
+
altered out of band) is shown as `recorded → live` and default **UNSELECTED**,
|
|
425
|
+
so one Enter never silently blesses a changed value. A recorded value that
|
|
426
|
+
**reverted to its AWS default or was removed** since record is offered as a
|
|
427
|
+
separate default-unselected "drop from baseline?" row — leaving it keeps the
|
|
428
|
+
watch (it stays reported by `check`); a `--yes` record preserves it and echoes
|
|
429
|
+
what it accepted. Deselect a suspicious one and it stays reported by `check`.
|
|
430
|
+
Nested
|
|
424
431
|
undeclared sub-keys (a value inside an object you _did_ declare) are listed in
|
|
425
432
|
full alongside the top-level ones — a non-default one is a real out-of-band
|
|
426
433
|
setting, so it is surfaced, not hidden. `record` writes only undeclared + added
|
package/dist/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2C
|
|
|
23
23
|
import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
|
|
24
24
|
import { GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
|
|
25
25
|
import { DescribeDBClustersCommand, DescribeDBInstancesCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
26
|
+
import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
|
|
26
27
|
import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
|
|
27
28
|
import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
|
|
28
29
|
import { BudgetsClient, DescribeBudgetCommand } from "@aws-sdk/client-budgets";
|
|
@@ -32,7 +33,6 @@ import { BatchGetProjectsCommand, BatchGetReportGroupsCommand, CodeBuildClient,
|
|
|
32
33
|
import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBInstancesCommand as DescribeDBInstancesCommand$1, DocDBClient, ModifyDBClusterCommand, ModifyDBInstanceCommand } from "@aws-sdk/client-docdb";
|
|
33
34
|
import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand, DescribeSubnetGroupsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
|
|
34
35
|
import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
|
|
35
|
-
import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
|
|
36
36
|
import { AttachGroupPolicyCommand, AttachRolePolicyCommand, AttachUserPolicyCommand, CreatePolicyVersionCommand, DeletePolicyVersionCommand, DeleteRolePolicyCommand, DetachGroupPolicyCommand, DetachRolePolicyCommand, DetachUserPolicyCommand, GetGroupPolicyCommand, GetPolicyCommand as GetPolicyCommand$1, GetPolicyVersionCommand, GetRolePolicyCommand, GetUserPolicyCommand, IAMClient, ListAccessKeysCommand, ListEntitiesForPolicyCommand, ListPolicyVersionsCommand, PutGroupPolicyCommand, PutRolePolicyCommand, PutUserPolicyCommand } from "@aws-sdk/client-iam";
|
|
37
37
|
import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
|
|
38
38
|
import { DescribeCacheClustersCommand, DescribeCacheParameterGroupsCommand, DescribeCacheParametersCommand, DescribeReplicationGroupsCommand, DescribeUsersCommand, ElastiCacheClient, ModifyCacheParameterGroupCommand, ResetCacheParameterGroupCommand } from "@aws-sdk/client-elasticache";
|
|
@@ -5933,7 +5933,8 @@ const CHILD_ENUMERATORS = {
|
|
|
5933
5933
|
"AWS::KMS::Key": enumerateKmsKeyChildren,
|
|
5934
5934
|
"AWS::AppConfig::Application": enumerateAppConfigApplicationChildren,
|
|
5935
5935
|
"AWS::EFS::FileSystem": enumerateEfsFileSystemChildren,
|
|
5936
|
-
"AWS::RDS::DBCluster": enumerateRdsClusterChildren
|
|
5936
|
+
"AWS::RDS::DBCluster": enumerateRdsClusterChildren,
|
|
5937
|
+
"AWS::Route53::HostedZone": enumerateRoute53HostedZoneChildren
|
|
5937
5938
|
};
|
|
5938
5939
|
function isBodyDefinedRestApi(declared) {
|
|
5939
5940
|
return declared.Body != null || declared.BodyS3Location != null;
|
|
@@ -7611,6 +7612,102 @@ async function enumerateRdsClusterChildren(ctx) {
|
|
|
7611
7612
|
clusterMemberIds
|
|
7612
7613
|
});
|
|
7613
7614
|
}
|
|
7615
|
+
const canonRoute53Name = (s) => s.replace(/\.$/, "").toLowerCase();
|
|
7616
|
+
const route53RecordKey = (name, type, setIdentifier) => `${canonRoute53Name(name)}|${type.toUpperCase()}${setIdentifier !== void 0 ? `|${setIdentifier}` : ""}`;
|
|
7617
|
+
function diffRoute53HostedZoneChildren(input) {
|
|
7618
|
+
const { hostedZoneId, zoneApex, declaredRecords, liveRecords } = input;
|
|
7619
|
+
const declared = new Set(declaredRecords.map((r) => route53RecordKey(r.name, r.type, r.setIdentifier)));
|
|
7620
|
+
const soaName = liveRecords.find((r) => r.type.toUpperCase() === "SOA")?.name;
|
|
7621
|
+
const apex = zoneApex !== void 0 ? canonRoute53Name(zoneApex) : soaName !== void 0 ? canonRoute53Name(soaName) : void 0;
|
|
7622
|
+
const added = [];
|
|
7623
|
+
for (const r of liveRecords) {
|
|
7624
|
+
const type = r.type.toUpperCase();
|
|
7625
|
+
const name = canonRoute53Name(r.name);
|
|
7626
|
+
if (type === "SOA") continue;
|
|
7627
|
+
if (type === "NS" && apex !== void 0 && name === apex) continue;
|
|
7628
|
+
if (declared.has(route53RecordKey(r.name, r.type, r.setIdentifier))) continue;
|
|
7629
|
+
const identifier = `${hostedZoneId}_${r.name}_${type}` + (r.setIdentifier !== void 0 ? `_${r.setIdentifier}` : "");
|
|
7630
|
+
added.push({
|
|
7631
|
+
resourceType: "AWS::Route53::RecordSet",
|
|
7632
|
+
identifier,
|
|
7633
|
+
label: `${type} ${name}`,
|
|
7634
|
+
live: r.live ?? {
|
|
7635
|
+
Name: r.name,
|
|
7636
|
+
Type: r.type
|
|
7637
|
+
}
|
|
7638
|
+
});
|
|
7639
|
+
}
|
|
7640
|
+
return added;
|
|
7641
|
+
}
|
|
7642
|
+
async function pageResourceRecordSets(client, hostedZoneId) {
|
|
7643
|
+
const out = [];
|
|
7644
|
+
let startName;
|
|
7645
|
+
let startType;
|
|
7646
|
+
let startId;
|
|
7647
|
+
for (;;) {
|
|
7648
|
+
const res = await client.send(new ListResourceRecordSetsCommand({
|
|
7649
|
+
HostedZoneId: hostedZoneId,
|
|
7650
|
+
StartRecordName: startName,
|
|
7651
|
+
StartRecordType: startType,
|
|
7652
|
+
...startId !== void 0 && { StartRecordIdentifier: startId }
|
|
7653
|
+
}));
|
|
7654
|
+
out.push(...res.ResourceRecordSets ?? []);
|
|
7655
|
+
if (!res.IsTruncated) break;
|
|
7656
|
+
startName = res.NextRecordName;
|
|
7657
|
+
startType = res.NextRecordType;
|
|
7658
|
+
startId = res.NextRecordIdentifier;
|
|
7659
|
+
}
|
|
7660
|
+
return out;
|
|
7661
|
+
}
|
|
7662
|
+
function route53ZoneRefMatches(declared, hostedZoneId, zoneApex) {
|
|
7663
|
+
if (declared.HostedZoneId !== void 0 && parentRefMatches(declared.HostedZoneId, hostedZoneId)) return true;
|
|
7664
|
+
const hzName = declared.HostedZoneName;
|
|
7665
|
+
if (hzName === void 0) return false;
|
|
7666
|
+
if (hzName === UNRESOLVED || hasUnresolved(hzName)) return true;
|
|
7667
|
+
return typeof hzName === "string" && zoneApex !== void 0 && canonRoute53Name(hzName) === canonRoute53Name(zoneApex);
|
|
7668
|
+
}
|
|
7669
|
+
async function enumerateRoute53HostedZoneChildren(ctx) {
|
|
7670
|
+
const { parent, desired, region } = ctx;
|
|
7671
|
+
const hostedZoneId = parent.physicalId;
|
|
7672
|
+
if (!hostedZoneId) return [];
|
|
7673
|
+
const zoneApex = typeof parent.declared.Name === "string" ? parent.declared.Name : void 0;
|
|
7674
|
+
const declaredRecords = [];
|
|
7675
|
+
for (const r of desired.resources) {
|
|
7676
|
+
if (r.resourceType !== "AWS::Route53::RecordSet") continue;
|
|
7677
|
+
if (!route53ZoneRefMatches(r.declared, hostedZoneId, zoneApex)) continue;
|
|
7678
|
+
const name = typeof r.declared.Name === "string" ? r.declared.Name : void 0;
|
|
7679
|
+
const type = typeof r.declared.Type === "string" ? r.declared.Type : void 0;
|
|
7680
|
+
if (name && type) declaredRecords.push({
|
|
7681
|
+
name,
|
|
7682
|
+
type,
|
|
7683
|
+
setIdentifier: typeof r.declared.SetIdentifier === "string" ? r.declared.SetIdentifier : void 0
|
|
7684
|
+
});
|
|
7685
|
+
}
|
|
7686
|
+
return diffRoute53HostedZoneChildren({
|
|
7687
|
+
hostedZoneId,
|
|
7688
|
+
zoneApex,
|
|
7689
|
+
declaredRecords,
|
|
7690
|
+
liveRecords: (await pageResourceRecordSets(new Route53Client({
|
|
7691
|
+
region,
|
|
7692
|
+
...READ_RETRY
|
|
7693
|
+
}), hostedZoneId)).filter((r) => typeof r.Name === "string" && typeof r.Type === "string").map((r) => {
|
|
7694
|
+
const live = {
|
|
7695
|
+
Name: r.Name,
|
|
7696
|
+
Type: r.Type
|
|
7697
|
+
};
|
|
7698
|
+
if (r.TTL !== void 0) live.TTL = String(r.TTL);
|
|
7699
|
+
const values = r.ResourceRecords?.map((rr) => rr.Value).filter((v) => !!v);
|
|
7700
|
+
if (values && values.length > 0) live.ResourceRecords = values;
|
|
7701
|
+
if (r.AliasTarget) live.AliasTarget = r.AliasTarget;
|
|
7702
|
+
return {
|
|
7703
|
+
name: r.Name,
|
|
7704
|
+
type: r.Type,
|
|
7705
|
+
setIdentifier: r.SetIdentifier,
|
|
7706
|
+
live
|
|
7707
|
+
};
|
|
7708
|
+
})
|
|
7709
|
+
});
|
|
7710
|
+
}
|
|
7614
7711
|
|
|
7615
7712
|
//#endregion
|
|
7616
7713
|
//#region src/read/pem.ts
|
|
@@ -8560,7 +8657,7 @@ const readCodeBuildProject = async ({ physicalId, declared, region }) => {
|
|
|
8560
8657
|
region,
|
|
8561
8658
|
...READ_RETRY
|
|
8562
8659
|
}).send(new BatchGetProjectsCommand({ names: [name] }))).projects?.[0];
|
|
8563
|
-
if (!p)
|
|
8660
|
+
if (!p) throw new ResourceGoneError(`CodeBuild Project ${name} absent`);
|
|
8564
8661
|
const model = { Name: p.name };
|
|
8565
8662
|
if (p.serviceRole !== void 0) model.ServiceRole = p.serviceRole;
|
|
8566
8663
|
if (p.description !== void 0) model.Description = p.description;
|
|
@@ -8894,7 +8991,15 @@ const readAcmCertificate = async ({ physicalId, declared, region }) => {
|
|
|
8894
8991
|
Value: tag.Value ?? ""
|
|
8895
8992
|
}));
|
|
8896
8993
|
if (tags.length > 0) model.Tags = tags;
|
|
8897
|
-
} catch {
|
|
8994
|
+
} catch (err) {
|
|
8995
|
+
const declaredTags = Array.isArray(declared.Tags) ? declared.Tags.filter((t) => typeof t === "object" && t !== null).filter((t) => str$1(t.Key) !== void 0).map((t) => ({
|
|
8996
|
+
Key: t.Key,
|
|
8997
|
+
Value: str$1(t.Value) ?? ""
|
|
8998
|
+
})) : [];
|
|
8999
|
+
if (declaredTags.length > 0) model.Tags = declaredTags;
|
|
9000
|
+
const call = err?.name || "unknown error";
|
|
9001
|
+
process.stderr.write(`[cdkrd] warning: ACM ListTagsForCertificate for ${arn} failed (${call}) — mirroring declared Tags to avoid a false drift; grant acm:ListTagsForCertificate to detect out-of-band tag changes\n`);
|
|
9002
|
+
}
|
|
8898
9003
|
return model;
|
|
8899
9004
|
};
|
|
8900
9005
|
const SDK_OVERRIDES = {
|
|
@@ -10690,6 +10795,64 @@ function splitRecordedByBaseline(recorded, baseline) {
|
|
|
10690
10795
|
changed
|
|
10691
10796
|
};
|
|
10692
10797
|
}
|
|
10798
|
+
/**
|
|
10799
|
+
* #758: for a `changed` recorded entry (a path already in the baseline whose value differs
|
|
10800
|
+
* this run), return the OLD recorded value so the record picker can show a `recorded → live`
|
|
10801
|
+
* diff and the user can see WHAT they are blessing. Matches on the same three identity axes as
|
|
10802
|
+
* `splitRecordedByBaseline` (#793). Returns `undefined` for a genuinely NEW path (no baseline
|
|
10803
|
+
* entry) — the caller then renders a plain "new" row. A sentinel `{ hasRecorded: boolean }` is
|
|
10804
|
+
* used rather than a bare `undefined` return so an intentional recorded value of `undefined`/
|
|
10805
|
+
* `null` is still distinguishable from "no baseline entry".
|
|
10806
|
+
*/
|
|
10807
|
+
function recordedValueForChanged(entry, baseline) {
|
|
10808
|
+
const baselineEntry = baseline?.recorded.find((a) => a.logicalId === entry.logicalId && a.path === entry.path && a.resourceType === entry.resourceType);
|
|
10809
|
+
return baselineEntry ? {
|
|
10810
|
+
hasRecorded: true,
|
|
10811
|
+
recordedValue: baselineEntry.value
|
|
10812
|
+
} : {
|
|
10813
|
+
hasRecorded: false,
|
|
10814
|
+
recordedValue: void 0
|
|
10815
|
+
};
|
|
10816
|
+
}
|
|
10817
|
+
/**
|
|
10818
|
+
* #790: baseline entries that have NO counterpart in the freshly-built recorded set for a
|
|
10819
|
+
* resource that was READ CLEANLY this run — i.e. a recorded value reverted to its AWS default
|
|
10820
|
+
* (now classified `atDefault`/`generated`, so absent from `buildRecorded`) or a recorded
|
|
10821
|
+
* property REMOVED out of band. `check`'s `applyBaseline` force-surfaces these as drift, but a
|
|
10822
|
+
* naive re-`record` full-replaces the baseline with only the newly-built set, silently DROPPING
|
|
10823
|
+
* these entries — accepting exactly that drift with zero output. They must instead surface in
|
|
10824
|
+
* the record flow as explicit "drop this recorded watch?" rows (default UNSELECTED).
|
|
10825
|
+
*
|
|
10826
|
+
* An entry is a drop-candidate ONLY when its resource was genuinely OBSERVED and the value is
|
|
10827
|
+
* genuinely gone — every "the recorded value is stale for a benign reason" case is EXCLUDED so
|
|
10828
|
+
* it is never offered for a (misleading) drop:
|
|
10829
|
+
* - resource `skipped`/`modelReadFailed` this run → unread, not gone (carryForwardUnreadable
|
|
10830
|
+
* already preserves these; excluding them here keeps them silently preserved, not offered);
|
|
10831
|
+
* - resource `deleted`, or absent from the current template (`allLogicalIds`) → the resource
|
|
10832
|
+
* itself is gone (#675), a different story than a value reverting;
|
|
10833
|
+
* - path since PROMOTED into the template (declared) → the "clean up your baseline" nudge
|
|
10834
|
+
* (#749/#1079), not an accepted drift;
|
|
10835
|
+
* - the entry is an `added`-resource snapshot (empty path) → reconciled resource-wise, not a
|
|
10836
|
+
* property revert.
|
|
10837
|
+
* The remaining entries are true "recorded value reverted-to-default / removed since record".
|
|
10838
|
+
* Mirrors the exclusion set `applyBaseline`'s removed-since-record loop already applies.
|
|
10839
|
+
*/
|
|
10840
|
+
function baselineOnlyEntries(recorded, baseline, findings, opts = {}) {
|
|
10841
|
+
if (!baseline || baseline.recorded.length === 0) return [];
|
|
10842
|
+
const present = new Set(recorded.map(recordedKey));
|
|
10843
|
+
const skippedOrUnread = new Set(findings.filter((f) => f.tier === "skipped" || f.modelReadFailed).map((f) => f.logicalId));
|
|
10844
|
+
const deletedLogical = new Set(findings.filter((f) => f.tier === "deleted").map((f) => f.logicalId));
|
|
10845
|
+
const currentLogicalIds = opts.allLogicalIds === void 0 ? void 0 : Array.isArray(opts.allLogicalIds) ? new Set(opts.allLogicalIds) : opts.allLogicalIds;
|
|
10846
|
+
return baseline.recorded.filter((e) => {
|
|
10847
|
+
if (e.path === "") return false;
|
|
10848
|
+
if (present.has(recordedKey(e))) return false;
|
|
10849
|
+
if (skippedOrUnread.has(e.logicalId)) return false;
|
|
10850
|
+
if (deletedLogical.has(e.logicalId)) return false;
|
|
10851
|
+
if (currentLogicalIds !== void 0 && !currentLogicalIds.has(e.logicalId)) return false;
|
|
10852
|
+
if (declaredPathIsPromoted(opts.declaredByLogical?.get(e.logicalId), e.path)) return false;
|
|
10853
|
+
return true;
|
|
10854
|
+
});
|
|
10855
|
+
}
|
|
10693
10856
|
/** Selective record: build the recorded set from only the findings whose key is in
|
|
10694
10857
|
* `selectedKeys`. Empty set -> []; all keys -> equals buildRecorded(findings). */
|
|
10695
10858
|
function selectRecorded(findings, selectedKeys) {
|
|
@@ -10795,6 +10958,7 @@ function applyBaseline(findings, baseline, opts = {}) {
|
|
|
10795
10958
|
kept.push({
|
|
10796
10959
|
...f,
|
|
10797
10960
|
tier: "undeclared",
|
|
10961
|
+
desired: canonicalizeForCompare(entry.value),
|
|
10798
10962
|
...delta && { arrayDelta: delta }
|
|
10799
10963
|
});
|
|
10800
10964
|
continue;
|
|
@@ -13579,6 +13743,53 @@ function recordSelectMessage(stackName, region, foldedCount = 0) {
|
|
|
13579
13743
|
return `${stackLabel$1(stackName, region)}: select undeclared value(s) to record (unselected stay reported)${fold}`;
|
|
13580
13744
|
}
|
|
13581
13745
|
/**
|
|
13746
|
+
* #790: header for the record DROP multiselect — the baseline-only entries (a recorded value
|
|
13747
|
+
* reverted to its AWS default, or removed out of band). Selecting a row DROPS the recorded
|
|
13748
|
+
* watch (accept the drift); leaving it UNSELECTED preserves the entry (it keeps reporting as
|
|
13749
|
+
* drift). Default-unselected, so one Enter here changes nothing. Pure + exported for unit tests.
|
|
13750
|
+
*/
|
|
13751
|
+
function recordDropMessage(stackName, region) {
|
|
13752
|
+
return `${stackLabel$1(stackName, region)}: recorded value(s) reverted-to-default / removed since record — select to DROP from the baseline (unselected stay watched & reported)`;
|
|
13753
|
+
}
|
|
13754
|
+
/**
|
|
13755
|
+
* #758: a compact single-line preview of a recorded/live VALUE for a record-picker label —
|
|
13756
|
+
* so a `changed since record` row can show `recorded → live` and the user can see WHAT they
|
|
13757
|
+
* are blessing (instead of a bare `Res.Path`). JSON-encoded (scalars stay bare-ish), then
|
|
13758
|
+
* truncated to keep the multiselect row on one line. Pure + exported for unit tests.
|
|
13759
|
+
*/
|
|
13760
|
+
function previewValue(v, max = 40) {
|
|
13761
|
+
let s;
|
|
13762
|
+
try {
|
|
13763
|
+
s = typeof v === "string" ? v : JSON.stringify(v);
|
|
13764
|
+
} catch {
|
|
13765
|
+
s = String(v);
|
|
13766
|
+
}
|
|
13767
|
+
if (s === void 0) s = String(v);
|
|
13768
|
+
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
13769
|
+
}
|
|
13770
|
+
/**
|
|
13771
|
+
* #758: the record multiselect label for a `changed` entry — a path already in the baseline
|
|
13772
|
+
* whose live value differs this run (a recorded value CHANGED out of band). Distinct from a
|
|
13773
|
+
* plain new-path row: it shows `recorded → live` (or a `(changed since record)` marker when the
|
|
13774
|
+
* old value could not be paired) so the user does not silently bless a possibly-attacker-changed
|
|
13775
|
+
* value under a bare label. Pure + exported for unit tests.
|
|
13776
|
+
*/
|
|
13777
|
+
function changedRecordLabel(entry, recordedValue) {
|
|
13778
|
+
const id = entry.path ? `${entry.logicalId}.${entry.path}` : `${entry.logicalId} (added resource)`;
|
|
13779
|
+
if (!recordedValue.hasRecorded) return id;
|
|
13780
|
+
return `${id} (changed since record: ${previewValue(recordedValue.recordedValue)} → ${previewValue(entry.value)})`;
|
|
13781
|
+
}
|
|
13782
|
+
/**
|
|
13783
|
+
* #790: the record multiselect label for a `baseline-only` drop-candidate — a recorded value
|
|
13784
|
+
* that reverted to its AWS default (now folded away) or was REMOVED out of band, so it has no
|
|
13785
|
+
* current undeclared finding. Selecting the row DROPS the recorded watch (an accept-drift
|
|
13786
|
+
* action, so the row is default UNSELECTED); leaving it keeps the entry in the baseline. Pure +
|
|
13787
|
+
* exported for unit tests.
|
|
13788
|
+
*/
|
|
13789
|
+
function dropRecordLabel(entry) {
|
|
13790
|
+
return `${entry.path ? `${entry.logicalId}.${entry.path}` : `${entry.logicalId} (added resource)`} (reverted-to-default / removed since record — drop from baseline?)`;
|
|
13791
|
+
}
|
|
13792
|
+
/**
|
|
13582
13793
|
* Split the to-record delta into STANDOUT (itemized in the record multiselect) and FOLDED
|
|
13583
13794
|
* (nested live-only sub-keys — the `undeclared-subkey` mass the report folds, R96). Folded
|
|
13584
13795
|
* entries are auto-recorded as a summarized count instead of dozens of rows. `expandNested`
|
|
@@ -13688,8 +13899,19 @@ async function recordStack(p) {
|
|
|
13688
13899
|
if (existing) checkBaselineAccount(existing, desired.accountId, stackName);
|
|
13689
13900
|
if (!yes && existing) console.error(`note: ${stackLabel$1(stackName, region)}: will overwrite the existing baseline file on confirm (nothing written yet; it is git-tracked — review the diff afterwards). Pass --yes to silence.`);
|
|
13690
13901
|
let recorded = carryForwardUnreadable(buildRecorded(findings), existing, findings);
|
|
13902
|
+
const dropCandidates = baselineOnlyEntries(recorded, existing, findings, {
|
|
13903
|
+
declaredByLogical: declaredKeysByLogical(desired.resources),
|
|
13904
|
+
allLogicalIds: desired.resources.map((r) => r.logicalId)
|
|
13905
|
+
});
|
|
13906
|
+
const droppedKeys = /* @__PURE__ */ new Set();
|
|
13907
|
+
if (yes && existing) {
|
|
13908
|
+
const { changed } = splitRecordedByBaseline(recorded, existing);
|
|
13909
|
+
const changedExisting = changed.filter((e) => recordedValueForChanged(e, existing).hasRecorded);
|
|
13910
|
+
if (changedExisting.length > 0) console.error(`note: ${stackName}: --yes accepted ${changedExisting.length} recorded value(s) CHANGED out of band since record (review the baseline diff): ` + changedExisting.map((e) => `${e.logicalId}.${e.path}`).join(", "));
|
|
13911
|
+
if (dropCandidates.length > 0) console.error(`note: ${stackName}: --yes PRESERVED ${dropCandidates.length} recorded watch(es) whose value reverted-to-default / was removed since record (they still report as drift; re-run interactively to drop them)`);
|
|
13912
|
+
}
|
|
13691
13913
|
let refreshedOnly = false;
|
|
13692
|
-
if (!yes && recorded.length > 0) {
|
|
13914
|
+
if (!yes && (recorded.length > 0 || dropCandidates.length > 0)) {
|
|
13693
13915
|
if (!interactive) {
|
|
13694
13916
|
console.error(`error: record needs a decision — pass --yes to record ALL undeclared values, or run interactively`);
|
|
13695
13917
|
return {
|
|
@@ -13701,7 +13923,7 @@ async function recordStack(p) {
|
|
|
13701
13923
|
if (unchanged.length > 0) console.error(`note: ${stackName}: keeping ${unchanged.length} already-recorded unchanged value(s)`);
|
|
13702
13924
|
if (changed.length === 0) {
|
|
13703
13925
|
recorded = unchanged;
|
|
13704
|
-
refreshedOnly =
|
|
13926
|
+
refreshedOnly = dropCandidates.length === 0;
|
|
13705
13927
|
} else {
|
|
13706
13928
|
let picked;
|
|
13707
13929
|
if (preselectedKeys) picked = changed.map((e) => recordedKey(e)).filter((k) => preselectedKeys.has(k));
|
|
@@ -13721,11 +13943,14 @@ async function recordStack(p) {
|
|
|
13721
13943
|
}
|
|
13722
13944
|
picked = changed.map((e) => recordedKey(e));
|
|
13723
13945
|
} else {
|
|
13724
|
-
const fromPrompt = await bulkMultiselect(recordSelectMessage(stackName, region, folded.length), standout.map((e) =>
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
|
|
13728
|
-
|
|
13946
|
+
const fromPrompt = await bulkMultiselect(recordSelectMessage(stackName, region, folded.length), standout.map((e) => {
|
|
13947
|
+
const rec = recordedValueForChanged(e, existing);
|
|
13948
|
+
return {
|
|
13949
|
+
value: recordedKey(e),
|
|
13950
|
+
label: changedRecordLabel(e, rec),
|
|
13951
|
+
selected: !rec.hasRecorded
|
|
13952
|
+
};
|
|
13953
|
+
}));
|
|
13729
13954
|
if (fromPrompt === void 0) {
|
|
13730
13955
|
console.error(`note: ${stackName}: record cancelled — baseline unchanged`);
|
|
13731
13956
|
return {
|
|
@@ -13738,21 +13963,40 @@ async function recordStack(p) {
|
|
|
13738
13963
|
}
|
|
13739
13964
|
const selectedChanged = selectRecorded(findings, new Set(picked));
|
|
13740
13965
|
recorded = [...unchanged, ...selectedChanged];
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13966
|
+
}
|
|
13967
|
+
if (dropCandidates.length > 0 && !preselectedKeys) {
|
|
13968
|
+
const dropPrompt = await bulkMultiselect(recordDropMessage(stackName, region), dropCandidates.map((e) => ({
|
|
13969
|
+
value: recordedKey(e),
|
|
13970
|
+
label: dropRecordLabel(e),
|
|
13971
|
+
selected: false
|
|
13972
|
+
})));
|
|
13973
|
+
if (dropPrompt === void 0) {
|
|
13974
|
+
console.error(`note: ${stackName}: record cancelled — baseline unchanged`);
|
|
13975
|
+
return {
|
|
13976
|
+
wrote: false,
|
|
13977
|
+
refused: false
|
|
13978
|
+
};
|
|
13979
|
+
}
|
|
13980
|
+
for (const key of dropPrompt) droppedKeys.add(key);
|
|
13981
|
+
refreshedOnly = false;
|
|
13982
|
+
}
|
|
13983
|
+
recorded = [...recorded, ...dropCandidates.filter((e) => !droppedKeys.has(recordedKey(e)))];
|
|
13984
|
+
if (recorded.length === 0 && !preselectedKeys) {
|
|
13985
|
+
const proceed = await confirm({
|
|
13986
|
+
message: `${stackLabel$1(stackName, region)}: record nothing? This writes an EMPTY baseline — every undeclared value stays reported as unrecorded.`,
|
|
13987
|
+
initialValue: false
|
|
13988
|
+
});
|
|
13989
|
+
if (isCancel(proceed) || !proceed) {
|
|
13990
|
+
console.error(`note: ${stackName}: record cancelled — baseline unchanged`);
|
|
13991
|
+
return {
|
|
13992
|
+
wrote: false,
|
|
13993
|
+
refused: false
|
|
13994
|
+
};
|
|
13753
13995
|
}
|
|
13754
13996
|
}
|
|
13755
13997
|
}
|
|
13998
|
+
const presentKeys = new Set(recorded.map(recordedKey));
|
|
13999
|
+
for (const e of dropCandidates) if (!droppedKeys.has(recordedKey(e)) && !presentKeys.has(recordedKey(e))) recorded.push(e);
|
|
13756
14000
|
const { path, count } = await writeBaseline(stackName, region, desired.accountId, findings, desired.rawTemplate, recorded, {
|
|
13757
14001
|
allLogicalIds: desired.resources.map((r) => r.logicalId),
|
|
13758
14002
|
previous: existing,
|