cdk-real-drift 0.2.63 → 0.2.65

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 CHANGED
@@ -474,17 +474,22 @@ ignore:
474
474
  form still match. Widening a stamped scope to a `*` glob (to intentionally ignore a
475
475
  path across every stack/account/region) stays a hand-edit.
476
476
  - All four fields accept `*` / `?` globs, but the `path` axis is **segment-aware**
477
- while the scope axes are not. In `path`, `*` / `?` match within a single `.`-delimited
478
- segment (`*.DesiredCount` matches `<anyId>.DesiredCount`, not a deeper
479
- `Tbl.Config.DesiredCount`) — a parent `path` still covers child paths via the subtree
480
- walk, so the segment bound does not under-match. Inside a `[...]` bracket key a `*` /
477
+ while the scope axes are not. In `path`, `*` / `?` match within a single
478
+ segment, bounded by `.`, `/`, and `[` (`*.DesiredCount` matches
479
+ `<anyId>.DesiredCount`, not a deeper `Tbl.Config.DesiredCount`; `MyApi/*`
480
+ matches a direct construct-path child but not a grandchild
481
+ `MyApi/Resource/Method`) — a parent `path` still covers child paths via the
482
+ subtree walk, so the segment bound does not under-match. Inside a `[...]`
483
+ bracket key a `*` /
481
484
  `?` is **unbounded within that bracket** (the brackets delimit the key, so a `.`
482
485
  between them is data): `Alb.LoadBalancerAttributes[*]` and
483
486
  `Alb.LoadBalancerAttributes[routing.*]` both match the dotted key
484
487
  `[routing.http2.enabled]`. On **stack / account / region**, `*` / `?` are unbounded
485
488
  (those names carry no `.`). The three scope axes are exactly the
486
489
  baseline file's identity axes; each is **omitted to leave that axis unscoped**
487
- (match-all) — a present-but-empty `""` is rejected (it would match nothing).
490
+ (match-all) — a present-but-empty `""` is rejected (it would match nothing),
491
+ as is an all-wildcard `path` (`*`, `**`, `*.*`) — it would silence _every_
492
+ finding, so a rule must name at least one literal segment.
488
493
  **Account** keeps a `stack: "Prod*"` rule from
489
494
  leaking into a same-named stack in another account (stack-name uniqueness only
490
495
  holds within one account / App); **region** is independent the same way — the same
package/dist/cli.js CHANGED
@@ -389,7 +389,7 @@ function matchesGlob(pattern, name) {
389
389
  }
390
390
  /**
391
391
  * Path-axis glob (for ignore-rule `path` patterns against a `<id>.<sub.path>` target):
392
- * a SEGMENT-aware variant where `*` / `?` do NOT cross a `.` or `[` boundary. So
392
+ * a SEGMENT-aware variant where `*` / `?` do NOT cross a `.`, `[`, or `/` boundary. So
393
393
  * `*.DesiredCount` matches `<anyId>.DesiredCount` (the documented intent — `*` = one id
394
394
  * segment) but NOT a same-named leaf nested deeper (`Tbl.Config.DesiredCount`, or a
395
395
  * free-form-map key literally named `DesiredCount`). Subtree coverage of a PARENT rule
@@ -397,6 +397,15 @@ function matchesGlob(pattern, name) {
397
397
  * walk in `pathMatches`, so bounding `*` here does not under-match. The stack/region
398
398
  * axes keep `matchesGlob` (their names contain no `.`/`[`, so it is equivalent there).
399
399
  *
400
+ * `/` is ALSO a hard segment boundary: `applyIgnores` matches against `/`-joined
401
+ * construct paths (`MyApi/Resource/Method`), so `MyApi/*` means "a direct child of
402
+ * MyApi" — bounding `*` at `/` keeps it from leaking to arbitrarily deep descendants
403
+ * (`MyApi/Resource/Method`). Deep-subtree coverage of a `/`-parent rule is still
404
+ * handled by the ancestor walk in `pathMatches` (which trims at `.` / `[`; a rule that
405
+ * means the whole subtree ends at the parent segment). Inside a `[...]` bracket a `/`
406
+ * is DATA, not a boundary — the brackets already delimit the key — so it stays literal
407
+ * there, exactly like `.`.
408
+ *
400
409
  * INSIDE a `[...]` bracket segment a `*` / `?` is UNBOUNDED within that bracket: the
401
410
  * brackets already delimit the key, so a `.` between them is DATA, not a segment
402
411
  * boundary — cdkrd's own canonical paths carry dotted bracket keys such as
@@ -407,8 +416,8 @@ function matchesGlob(pattern, name) {
407
416
  function matchesPathGlob(pattern, target) {
408
417
  let out = "^";
409
418
  let inBracket = false;
410
- for (const ch of pattern.replace(/\*+/g, "*")) if (ch === "*") out += inBracket ? "[^\\]]*" : "[^.[]*";
411
- else if (ch === "?") out += inBracket ? "[^\\]]" : "[^.[]";
419
+ for (const ch of pattern.replace(/\*+/g, "*")) if (ch === "*") out += inBracket ? "[^\\]]*" : "[^.[/]*";
420
+ else if (ch === "?") out += inBracket ? "[^\\]]" : "[^.[/]";
412
421
  else {
413
422
  if (ch === "[") inBracket = true;
414
423
  else if (ch === "]") inBracket = false;
@@ -472,6 +481,18 @@ async function loadConfig() {
472
481
  return { ignore };
473
482
  }
474
483
  /**
484
+ * True when `path` is an all-wildcard universal matcher — a pattern with NO literal
485
+ * segment content, made only of the glob metachars (`*` / `?`) and the segment
486
+ * separators (`.` `[` `]` `/`). Examples: `*`, `**`, `*.*`, `?`, a slash-joined
487
+ * `*` pair, `*.*[*]`.
488
+ * Such a rule ignores EVERY finding (issue #842), so the validator rejects it the same
489
+ * way it rejects an empty path. A pattern with even one literal character (`Foo*`,
490
+ * `*.DesiredCount`, `MyApi/*`) is NOT universal and is allowed. Exported for tests.
491
+ */
492
+ function isUniversalPath(path) {
493
+ return path.replace(/[*?.[\]/]/g, "") === "";
494
+ }
495
+ /**
475
496
  * Validate one `ignore` array entry: a mapping with a required string `path` and
476
497
  * optional string `stack` / `account` / `region` (and no other keys — the same fail-fast
477
498
  * typo guard as the unknown-top-level-key check, so a mistyped `reigon` is rejected
@@ -485,6 +506,7 @@ function validateIgnoreEntry(entry, index) {
485
506
  if (unknown.length > 0) throw new Error(`${at}: unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} — known keys: "path", "stack", "account", "region"`);
486
507
  if (typeof obj.path !== "string") throw new Error(`${at}: "path" is required and must be a string`);
487
508
  if (obj.path === "") throw new Error(`${at}: "path" must not be empty`);
509
+ if (isUniversalPath(obj.path)) throw new Error(`${at}: "path" must not be an all-wildcard pattern ("${obj.path}") — it would ignore every finding; name at least one literal path segment`);
488
510
  for (const k of [
489
511
  "stack",
490
512
  "account",
@@ -879,6 +901,7 @@ function resolve$1(node, ctx) {
879
901
  case "Fn::Join": {
880
902
  if (!Array.isArray(v)) return UNRESOLVED;
881
903
  const [delim, list] = v;
904
+ if (typeof delim !== "string") return UNRESOLVED;
882
905
  const resolved = resolve$1(list, ctx);
883
906
  if (!Array.isArray(resolved)) return UNRESOLVED;
884
907
  const parts = resolved.filter((p) => p !== NOVALUE);
@@ -918,6 +941,11 @@ function resolve$1(node, ctx) {
918
941
  if (typeof delim !== "string" || typeof src !== "string") return UNRESOLVED;
919
942
  return src.split(delim);
920
943
  }
944
+ case "Fn::Cidr": {
945
+ if (!Array.isArray(v) || v.length < 3) return UNRESOLVED;
946
+ const [ipBlock, count, cidrBits] = v.slice(0, 3).map((x) => resolve$1(x, ctx));
947
+ return resolveCidr(ipBlock, count, cidrBits);
948
+ }
921
949
  case "Fn::ImportValue": {
922
950
  const name = resolve$1(v, ctx);
923
951
  if (typeof name !== "string") return UNRESOLVED;
@@ -984,6 +1012,11 @@ function evalCondition(name, ctx) {
984
1012
  }
985
1013
  const GETATT_DECLARED_PROPERTY = { "AWS::Cognito::IdentityPool": { Name: "IdentityPoolName" } };
986
1014
  function resolveGetAtt(v, ctx) {
1015
+ if (typeof v === "string") {
1016
+ const dot = v.indexOf(".");
1017
+ if (dot < 0) return UNRESOLVED;
1018
+ v = [v.slice(0, dot), v.slice(dot + 1)];
1019
+ }
987
1020
  if (!Array.isArray(v) || v.length < 2) return UNRESOLVED;
988
1021
  const logicalId = String(v[0]);
989
1022
  const attr = String(v[1]);
@@ -1013,6 +1046,54 @@ function resolveGetAtt(v, ctx) {
1013
1046
  const got = getPath(model, segs);
1014
1047
  return got === void 0 ? UNRESOLVED : got;
1015
1048
  }
1049
+ function resolveCidr(ipBlock, count, cidrBits) {
1050
+ if (typeof ipBlock !== "string") return UNRESOLVED;
1051
+ const cnt = Number(count);
1052
+ const bits = Number(cidrBits);
1053
+ if (!Number.isInteger(cnt) || cnt <= 0) return UNRESOLVED;
1054
+ if (!Number.isInteger(bits) || bits < 0 || bits > 32) return UNRESOLVED;
1055
+ if (ipBlock.includes(":")) return UNRESOLVED;
1056
+ const slash = ipBlock.indexOf("/");
1057
+ if (slash < 0) return UNRESOLVED;
1058
+ const ipPart = ipBlock.slice(0, slash);
1059
+ const prefix = Number(ipBlock.slice(slash + 1));
1060
+ if (!Number.isInteger(prefix) || prefix < 0 || prefix > 32) return UNRESOLVED;
1061
+ const base = ipv4ToInt(ipPart);
1062
+ if (base === void 0) return UNRESOLVED;
1063
+ const maskLen = 32 - bits;
1064
+ if (maskLen < prefix) return UNRESOLVED;
1065
+ const step = 2 ** bits;
1066
+ const blockSize = 2 ** (32 - prefix);
1067
+ const alignedBase = Math.floor(base / step) * step;
1068
+ if (cnt * step > blockSize) return UNRESOLVED;
1069
+ const out = [];
1070
+ for (let i = 0; i < cnt; i++) {
1071
+ const addr = alignedBase + i * step;
1072
+ if (addr > 4294967295) return UNRESOLVED;
1073
+ out.push(`${intToIpv4(addr)}/${maskLen}`);
1074
+ }
1075
+ return out;
1076
+ }
1077
+ function ipv4ToInt(ip) {
1078
+ const parts = ip.split(".");
1079
+ if (parts.length !== 4) return void 0;
1080
+ let n = 0;
1081
+ for (const p of parts) {
1082
+ if (!/^\d{1,3}$/.test(p)) return void 0;
1083
+ const octet = Number(p);
1084
+ if (octet < 0 || octet > 255) return void 0;
1085
+ n = n * 256 + octet;
1086
+ }
1087
+ return n >>> 0;
1088
+ }
1089
+ function intToIpv4(n) {
1090
+ return [
1091
+ n >>> 24 & 255,
1092
+ n >>> 16 & 255,
1093
+ n >>> 8 & 255,
1094
+ n & 255
1095
+ ].join(".");
1096
+ }
1016
1097
  function getPath(obj, segs) {
1017
1098
  let node = obj;
1018
1099
  for (const s of segs) {
@@ -1032,11 +1113,11 @@ function resolveSub(v, ctx) {
1032
1113
  let tmpl;
1033
1114
  let vars = {};
1034
1115
  if (typeof v === "string") tmpl = v;
1035
- else {
1036
- const arr = v;
1037
- tmpl = arr[0];
1038
- vars = arr[1] ?? {};
1039
- }
1116
+ else if (Array.isArray(v)) {
1117
+ tmpl = v[0];
1118
+ vars = v[1] ?? {};
1119
+ } else return UNRESOLVED;
1120
+ if (typeof tmpl !== "string") return UNRESOLVED;
1040
1121
  let unresolved = false;
1041
1122
  const out = tmpl.replace(/\$\{([^}]+)\}/g, (_m, ref) => {
1042
1123
  if (ref.startsWith("!")) return `\${${ref.slice(1)}}`;
@@ -3264,6 +3345,35 @@ function buildCustomTags() {
3264
3345
  return tags;
3265
3346
  }
3266
3347
  const CUSTOM_TAGS = buildCustomTags();
3348
+ const TRUE_BOOL_TEST = /^(?:[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/;
3349
+ const FALSE_BOOL_TEST = /^(?:[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/;
3350
+ const BOOL_TAG = "tag:yaml.org,2002:bool";
3351
+ const TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp";
3352
+ function restrictYaml11Tags(baseTags) {
3353
+ const restricted = [];
3354
+ for (const tag of baseTags) {
3355
+ if (typeof tag === "string") {
3356
+ restricted.push(tag);
3357
+ continue;
3358
+ }
3359
+ if (tag.tag === TIMESTAMP_TAG) continue;
3360
+ if (tag.tag === BOOL_TAG) {
3361
+ const scalar = tag;
3362
+ const isTrueTag = scalar.identify?.(true) === true;
3363
+ restricted.push({
3364
+ ...scalar,
3365
+ test: isTrueTag ? TRUE_BOOL_TEST : FALSE_BOOL_TEST
3366
+ });
3367
+ continue;
3368
+ }
3369
+ restricted.push(tag);
3370
+ }
3371
+ return restricted.concat(CUSTOM_TAGS);
3372
+ }
3373
+ const CFN_YAML_PARSE_OPTIONS = {
3374
+ schema: "yaml-1.1",
3375
+ customTags: restrictYaml11Tags
3376
+ };
3267
3377
  function detectTemplateFormat(text) {
3268
3378
  const trimmed = (text.charCodeAt(0) === 65279 ? text.slice(1) : text).trimStart();
3269
3379
  if (trimmed.length === 0) return "json";
@@ -3275,10 +3385,7 @@ function parseCfnTemplate(text) {
3275
3385
  const body = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
3276
3386
  let parsed;
3277
3387
  if (format === "json") parsed = JSON.parse(body);
3278
- else parsed = parse(body, {
3279
- version: "1.1",
3280
- customTags: CUSTOM_TAGS
3281
- });
3388
+ else parsed = parse(body, CFN_YAML_PARSE_OPTIONS);
3282
3389
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Template root is not an object.");
3283
3390
  return parsed;
3284
3391
  }
@@ -10822,13 +10929,22 @@ const writeLexBotLocales = async (ctx, ops) => {
10822
10929
  const loc = rawLocale;
10823
10930
  const localeId = lexStr(loc.LocaleId);
10824
10931
  if (!localeId) throw new Error("Lex BotLocales revert: a declared locale has no LocaleId");
10825
- const liveSlotTypes = await c.send(new ListSlotTypesCommand({
10826
- botId,
10827
- botVersion,
10828
- localeId
10829
- }));
10932
+ const slotTypeSummaries = [];
10933
+ {
10934
+ let nextToken;
10935
+ do {
10936
+ const r = await c.send(new ListSlotTypesCommand({
10937
+ botId,
10938
+ botVersion,
10939
+ localeId,
10940
+ ...nextToken && { nextToken }
10941
+ }));
10942
+ slotTypeSummaries.push(...r.slotTypeSummaries ?? []);
10943
+ nextToken = r.nextToken;
10944
+ } while (nextToken);
10945
+ }
10830
10946
  const slotTypeNameToId = /* @__PURE__ */ new Map();
10831
- for (const s of liveSlotTypes.slotTypeSummaries ?? []) {
10947
+ for (const s of slotTypeSummaries) {
10832
10948
  const id = lexStr(s.slotTypeId);
10833
10949
  const name = lexStr(s.slotTypeName);
10834
10950
  if (id && name && !id.startsWith("AMAZON.")) slotTypeNameToId.set(name, id);
@@ -10881,13 +10997,22 @@ const writeLexBotLocales = async (ctx, ops) => {
10881
10997
  else input.valueSelectionSetting = live.valueSelectionSetting;
10882
10998
  await c.send(new UpdateSlotTypeCommand(input));
10883
10999
  }
10884
- const liveIntents = await c.send(new ListIntentsCommand({
10885
- botId,
10886
- botVersion,
10887
- localeId
10888
- }));
11000
+ const intentSummaries = [];
11001
+ {
11002
+ let nextToken;
11003
+ do {
11004
+ const r = await c.send(new ListIntentsCommand({
11005
+ botId,
11006
+ botVersion,
11007
+ localeId,
11008
+ ...nextToken && { nextToken }
11009
+ }));
11010
+ intentSummaries.push(...r.intentSummaries ?? []);
11011
+ nextToken = r.nextToken;
11012
+ } while (nextToken);
11013
+ }
10889
11014
  const intentNameToId = /* @__PURE__ */ new Map();
10890
- for (const i of liveIntents.intentSummaries ?? []) {
11015
+ for (const i of intentSummaries) {
10891
11016
  const id = lexStr(i.intentId);
10892
11017
  const name = lexStr(i.intentName);
10893
11018
  if (id && name) intentNameToId.set(name, id);
@@ -10914,14 +11039,23 @@ const writeLexBotLocales = async (ctx, ops) => {
10914
11039
  const iName = lexStr(di.Name);
10915
11040
  const intentId = iName ? intentNameToId.get(iName) : void 0;
10916
11041
  if (!intentId || !iName || isBuiltinIntent(iName)) continue;
10917
- const liveSlots = await c.send(new ListSlotsCommand({
10918
- botId,
10919
- botVersion,
10920
- localeId,
10921
- intentId
10922
- }));
11042
+ const slotSummaries = [];
11043
+ {
11044
+ let nextToken;
11045
+ do {
11046
+ const r = await c.send(new ListSlotsCommand({
11047
+ botId,
11048
+ botVersion,
11049
+ localeId,
11050
+ intentId,
11051
+ ...nextToken && { nextToken }
11052
+ }));
11053
+ slotSummaries.push(...r.slotSummaries ?? []);
11054
+ nextToken = r.nextToken;
11055
+ } while (nextToken);
11056
+ }
10923
11057
  const slotNameToId = /* @__PURE__ */ new Map();
10924
- for (const s of liveSlots.slotSummaries ?? []) {
11058
+ for (const s of slotSummaries) {
10925
11059
  const id = lexStr(s.slotId);
10926
11060
  const name = lexStr(s.slotName);
10927
11061
  if (id && name) slotNameToId.set(name, id);