cdk-real-drift 0.9.10 → 0.9.12

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 CHANGED
@@ -1683,6 +1683,76 @@ async function recordCorpusCase(dir, c) {
1683
1683
  return p;
1684
1684
  }
1685
1685
 
1686
+ //#endregion
1687
+ //#region src/normalize/cc-api-strip.ts
1688
+ const ALWAYS_STRIPPED = new Set([
1689
+ "CreationDate",
1690
+ "CreationTime",
1691
+ "CreatedTime",
1692
+ "CreatedDate",
1693
+ "CreatedAt",
1694
+ "LastModifiedDate",
1695
+ "LastModifiedTime",
1696
+ "LastModified",
1697
+ "LastUpdatedTime",
1698
+ "LastUpdatedDate",
1699
+ "UpdatedAt",
1700
+ "OwnerId",
1701
+ "OwnerAccountId",
1702
+ "CreatedBy",
1703
+ "OwnerArn",
1704
+ "RevisionId",
1705
+ "LastUpdateStatus",
1706
+ "LastUpdateStatusReason",
1707
+ "LastUpdateStatusReasonCode",
1708
+ "StackId",
1709
+ "PhysicalResourceId",
1710
+ "LogicalResourceId"
1711
+ ]);
1712
+ const FREE_FORM_MAP_PARENTS = new Set([
1713
+ "Variables",
1714
+ "Parameters",
1715
+ "DefaultArguments",
1716
+ "DockerLabels",
1717
+ "Labels",
1718
+ "Tags",
1719
+ "UserPoolTags",
1720
+ "BackupPlanTags",
1721
+ "BackupVaultTags",
1722
+ "RecoveryPointTags"
1723
+ ]);
1724
+ const TAG_PROPERTY_NAMES = new Set([
1725
+ "Tags",
1726
+ "UserPoolTags",
1727
+ "BackupPlanTags",
1728
+ "BackupVaultTags",
1729
+ "RecoveryPointTags",
1730
+ "IdentityPoolTags",
1731
+ "BotTags",
1732
+ "ResourceTags",
1733
+ "FileSystemTags",
1734
+ "HostedZoneTags"
1735
+ ]);
1736
+ function stripCcApiAwsManagedFields(awsProps) {
1737
+ return stripWalk(awsProps, false);
1738
+ }
1739
+ function stripWalk(value, freeForm) {
1740
+ if (value === null || value === void 0) return value;
1741
+ if (Array.isArray(value)) {
1742
+ const mapped = value.map((v) => stripWalk(v, freeForm));
1743
+ return freeForm ? mapped : mapped.filter((v) => v !== null && v !== void 0);
1744
+ }
1745
+ if (typeof value === "object") {
1746
+ const out = {};
1747
+ for (const [k, child] of Object.entries(value)) {
1748
+ if (!freeForm && ALWAYS_STRIPPED.has(k)) continue;
1749
+ out[k] = stripWalk(child, freeForm || FREE_FORM_MAP_PARENTS.has(k));
1750
+ }
1751
+ return out;
1752
+ }
1753
+ return value;
1754
+ }
1755
+
1686
1756
  //#endregion
1687
1757
  //#region src/normalize/noise.ts
1688
1758
  const KNOWN_DEFAULTS = {
@@ -3099,7 +3169,7 @@ function stripTagsWalk(v, underTagsKey, parentKey) {
3099
3169
  const out = {};
3100
3170
  for (const [k, val] of Object.entries(v)) {
3101
3171
  if (underTagsKey && k.startsWith("aws:")) continue;
3102
- out[k] = stripTagsWalk(val, k === "Tags", k);
3172
+ out[k] = stripTagsWalk(val, TAG_PROPERTY_NAMES.has(k), k);
3103
3173
  }
3104
3174
  return out;
3105
3175
  }
@@ -4348,60 +4418,6 @@ function isLogGroupArnWildcardMatch(desired, actual) {
4348
4418
  return stripLogGroupWildcard(desired) === stripLogGroupWildcard(actual);
4349
4419
  }
4350
4420
 
4351
- //#endregion
4352
- //#region src/normalize/cc-api-strip.ts
4353
- const ALWAYS_STRIPPED = new Set([
4354
- "CreationDate",
4355
- "CreationTime",
4356
- "CreatedTime",
4357
- "CreatedDate",
4358
- "CreatedAt",
4359
- "LastModifiedDate",
4360
- "LastModifiedTime",
4361
- "LastModified",
4362
- "LastUpdatedTime",
4363
- "LastUpdatedDate",
4364
- "UpdatedAt",
4365
- "OwnerId",
4366
- "OwnerAccountId",
4367
- "CreatedBy",
4368
- "OwnerArn",
4369
- "RevisionId",
4370
- "LastUpdateStatus",
4371
- "LastUpdateStatusReason",
4372
- "LastUpdateStatusReasonCode",
4373
- "StackId",
4374
- "PhysicalResourceId",
4375
- "LogicalResourceId"
4376
- ]);
4377
- const FREE_FORM_MAP_PARENTS = new Set([
4378
- "Variables",
4379
- "Parameters",
4380
- "DefaultArguments",
4381
- "DockerLabels",
4382
- "Labels",
4383
- "Tags"
4384
- ]);
4385
- function stripCcApiAwsManagedFields(awsProps) {
4386
- return stripWalk(awsProps, false);
4387
- }
4388
- function stripWalk(value, freeForm) {
4389
- if (value === null || value === void 0) return value;
4390
- if (Array.isArray(value)) {
4391
- const mapped = value.map((v) => stripWalk(v, freeForm));
4392
- return freeForm ? mapped : mapped.filter((v) => v !== null && v !== void 0);
4393
- }
4394
- if (typeof value === "object") {
4395
- const out = {};
4396
- for (const [k, child] of Object.entries(value)) {
4397
- if (!freeForm && ALWAYS_STRIPPED.has(k)) continue;
4398
- out[k] = stripWalk(child, freeForm || FREE_FORM_MAP_PARENTS.has(k));
4399
- }
4400
- return out;
4401
- }
4402
- return value;
4403
- }
4404
-
4405
4421
  //#endregion
4406
4422
  //#region src/read/client-config.ts
4407
4423
  /** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
@@ -12001,10 +12017,35 @@ async function bulkMultiselect(message, options) {
12001
12017
  function unescape(seg) {
12002
12018
  return seg.replace(/~1/g, "/").replace(/~0/g, "~");
12003
12019
  }
12020
+ function pointerSegs(path) {
12021
+ return path.split("/").slice(1).map(unescape);
12022
+ }
12023
+ var StaleRevertModelError = class extends Error {
12024
+ pointerPath;
12025
+ constructor(pointerPath) {
12026
+ super(`revert aborted: the live value at ${pointerPath} changed since drift was detected (an element in the same array was added or removed) — re-run \`check\` and revert again`);
12027
+ this.name = "StaleRevertModelError";
12028
+ this.pointerPath = pointerPath;
12029
+ }
12030
+ };
12031
+ function assertPriorUnchanged(model, ops) {
12032
+ for (const op of ops) {
12033
+ if (op.prior === void 0) continue;
12034
+ if (!deepEqual(getAt(model, pointerSegs(op.path)), op.prior)) throw new StaleRevertModelError(op.path);
12035
+ }
12036
+ }
12037
+ function getAt(root, segs) {
12038
+ let node = root;
12039
+ for (const seg of segs) {
12040
+ if (node === null || typeof node !== "object") return void 0;
12041
+ node = node[seg];
12042
+ }
12043
+ return node;
12044
+ }
12004
12045
  function applyOps(model, ops) {
12005
12046
  const out = structuredClone(model);
12006
12047
  for (const op of ops) {
12007
- const segs = op.path.split("/").slice(1).map(unescape);
12048
+ const segs = pointerSegs(op.path);
12008
12049
  if (op.op === "add") setAt(out, segs, op.value);
12009
12050
  else removeAt(out, segs);
12010
12051
  }
@@ -12042,10 +12083,12 @@ const assertOpsConsumed = (resourceType, ops, handled) => {
12042
12083
  async function desiredModel(type, ctx, ops) {
12043
12084
  const reader = SDK_OVERRIDES[type];
12044
12085
  const current = (reader && await reader(ctx)) ?? {};
12045
- return applyOps(current.PolicyDocument === void 0 ? current : {
12086
+ const aligned = current.PolicyDocument === void 0 ? current : {
12046
12087
  ...current,
12047
12088
  PolicyDocument: canonicalizeForCompare(current.PolicyDocument)
12048
- }, ops);
12089
+ };
12090
+ assertPriorUnchanged(aligned, ops);
12091
+ return applyOps(aligned, ops);
12049
12092
  }
12050
12093
  const policyJson = (m) => m.PolicyDocument === void 0 ? void 0 : JSON.stringify(m.PolicyDocument);
12051
12094
  const writeS3BucketPolicy = async (ctx, ops) => {
@@ -12405,7 +12448,9 @@ const writeWafv2WebAcl = async (ctx, ops) => {
12405
12448
  Scope: scope
12406
12449
  }));
12407
12450
  if (!cur.WebACL || !cur.LockToken) throw new Error("could not read current WebACL for revert");
12408
- const m = applyOps(canonicalizeForCompare(cur.WebACL), ops);
12451
+ const alignedWebAcl = canonicalizeForCompare(cur.WebACL);
12452
+ assertPriorUnchanged(alignedWebAcl, ops);
12453
+ const m = applyOps(alignedWebAcl, ops);
12409
12454
  const desc = m.Description;
12410
12455
  await c.send(new UpdateWebACLCommand({
12411
12456
  Name: name,
@@ -14292,41 +14337,44 @@ function writeOnlyReincludeOps(declared, schema, existingOps) {
14292
14337
  }
14293
14338
  return ops;
14294
14339
  }
14295
- const TAGS_POINTER = "/Tags";
14296
14340
  function asTagList(v) {
14297
14341
  return Array.isArray(v) ? v : [];
14298
14342
  }
14299
- function tagPreservingOps(ops, liveRaw) {
14300
- const liveTags = liveRaw?.["Tags"];
14343
+ function preserveManagedTags(op, pointer, liveTags) {
14301
14344
  if (liveTags !== null && typeof liveTags === "object" && !Array.isArray(liveTags)) {
14302
14345
  const managedMap = Object.fromEntries(Object.entries(liveTags).filter(([k]) => k.startsWith("aws:")));
14303
- if (Object.keys(managedMap).length === 0) return ops;
14304
- return ops.map((op) => {
14305
- if (op.path !== TAGS_POINTER) return op;
14306
- return {
14307
- op: "add",
14308
- path: TAGS_POINTER,
14309
- value: {
14310
- ...op.op === "add" && op.value !== null && typeof op.value === "object" && !Array.isArray(op.value) ? Object.fromEntries(Object.entries(op.value).filter(([k]) => !k.startsWith("aws:"))) : {},
14311
- ...managedMap
14312
- },
14313
- ...op.prior !== void 0 && { prior: op.prior },
14314
- human: `${op.human} (preserving aws:* managed tags)`
14315
- };
14316
- });
14317
- }
14318
- const managed = awsManagedTags(liveTags);
14319
- if (managed.length === 0) return ops;
14320
- return ops.map((op) => {
14321
- if (op.path !== TAGS_POINTER) return op;
14346
+ if (Object.keys(managedMap).length === 0) return op;
14322
14347
  return {
14323
14348
  op: "add",
14324
- path: TAGS_POINTER,
14325
- value: [...op.op === "add" ? asTagList(op.value).filter((t) => awsManagedTags([t]).length === 0) : [], ...managed],
14349
+ path: pointer,
14350
+ value: {
14351
+ ...op.op === "add" && op.value !== null && typeof op.value === "object" && !Array.isArray(op.value) ? Object.fromEntries(Object.entries(op.value).filter(([k]) => !k.startsWith("aws:"))) : {},
14352
+ ...managedMap
14353
+ },
14326
14354
  ...op.prior !== void 0 && { prior: op.prior },
14327
14355
  human: `${op.human} (preserving aws:* managed tags)`
14328
14356
  };
14357
+ }
14358
+ const managed = awsManagedTags(liveTags);
14359
+ if (managed.length === 0) return op;
14360
+ return {
14361
+ op: "add",
14362
+ path: pointer,
14363
+ value: [...op.op === "add" ? asTagList(op.value).filter((t) => awsManagedTags([t]).length === 0) : [], ...managed],
14364
+ ...op.prior !== void 0 && { prior: op.prior },
14365
+ human: `${op.human} (preserving aws:* managed tags)`
14366
+ };
14367
+ }
14368
+ function tagPreservingOps(ops, liveRaw) {
14369
+ let changed = false;
14370
+ const out = ops.map((op) => {
14371
+ const name = /^\/([^/]+)$/.exec(op.path)?.[1];
14372
+ if (name === void 0 || !TAG_PROPERTY_NAMES.has(name)) return op;
14373
+ const rewritten = preserveManagedTags(op, op.path, liveRaw?.[name]);
14374
+ if (rewritten !== op) changed = true;
14375
+ return rewritten;
14329
14376
  });
14377
+ return changed ? out : ops;
14330
14378
  }
14331
14379
  const CC_UPDATE_REJECTED_EMPTY_PATHS = {
14332
14380
  "AWS::VpcLattice::Rule": ["/Match/HttpMatch/HeaderMatches"],
@@ -15313,6 +15361,26 @@ async function revertStack(p) {
15313
15361
  out(style.note(` ↻ ${displayId}: ${reason} — retry ${attempt} (next in ${secs}s)…`));
15314
15362
  }
15315
15363
  });
15364
+ const itemsPerLogical = /* @__PURE__ */ new Map();
15365
+ for (const item of plan.items) itemsPerLogical.set(item.logicalId, (itemsPerLogical.get(item.logicalId) ?? 0) + 1);
15366
+ const streamedLogical = /* @__PURE__ */ new Set();
15367
+ const streamResultLine = (logicalId) => {
15368
+ if (streamedLogical.has(logicalId)) return;
15369
+ const forResource = applied.filter((a) => a.logicalId === logicalId);
15370
+ if (forResource.length < (itemsPerLogical.get(logicalId) ?? 0)) return;
15371
+ streamedLogical.add(logicalId);
15372
+ for (const s of summarizeRevertResults(forResource)) printRevertResultLine(s);
15373
+ };
15374
+ const printRevertResultLine = (s) => {
15375
+ if (s.ok) out(style.ok(` reverted: ${s.displayId}`));
15376
+ else {
15377
+ out(style.fail(` FAILED: ${s.displayId} — ${s.error}`));
15378
+ if (s.hint) {
15379
+ const suffix = waitMs === void 0 ? " (or re-run with --wait to block until it settles)" : "";
15380
+ out(style.note(` ↳ ${s.hint}${suffix}`));
15381
+ }
15382
+ }
15383
+ };
15316
15384
  const deleteItems = plan.items.filter((i) => i.kind === "delete");
15317
15385
  for (const item of plan.items) {
15318
15386
  if (item.kind === "delete") continue;
@@ -15353,6 +15421,7 @@ async function revertStack(p) {
15353
15421
  });
15354
15422
  if (!r.ok) worst = Math.max(worst, 2);
15355
15423
  if (!r.ok) failedUpdateIds.add(item.logicalId);
15424
+ streamResultLine(item.logicalId);
15356
15425
  }
15357
15426
  const deleteDeadlineMs = waitMs !== void 0 ? clock() + waitMs : void 0;
15358
15427
  const deleteOutcomes = await applyRevertDeletes(deleteItems, (item) => applyRevertDelete(cc, item, item.physicalId, buildRetryOpts(item.displayId, deleteDeadlineMs)));
@@ -15366,17 +15435,14 @@ async function revertStack(p) {
15366
15435
  ...r.hint !== void 0 && { hint: r.hint }
15367
15436
  });
15368
15437
  if (!r.ok) worst = Math.max(worst, 2);
15438
+ streamResultLine(item.logicalId);
15369
15439
  }
15370
15440
  const summarized = summarizeRevertResults(applied);
15371
15441
  const revertedCount = summarized.filter((s) => s.ok).length;
15372
15442
  const failedCount = summarized.filter((s) => !s.ok).length;
15373
- for (const s of summarized) if (s.ok) out(style.ok(` reverted: ${s.displayId}`));
15374
- else {
15375
- out(style.fail(` FAILED: ${s.displayId} — ${s.error}`));
15376
- if (s.hint) {
15377
- const suffix = waitMs === void 0 ? " (or re-run with --wait to block until it settles)" : "";
15378
- out(style.note(` ↳ ${s.hint}${suffix}`));
15379
- }
15443
+ for (const item of plan.items) {
15444
+ if (streamedLogical.has(item.logicalId)) continue;
15445
+ streamResultLine(item.logicalId);
15380
15446
  }
15381
15447
  const touched = new Set(plan.items.map((i) => i.logicalId));
15382
15448
  out("\n" + style.note(`verifying convergence (re-reading ${touched.size} resource(s))...`));