cdk-real-drift 0.7.0 → 0.7.2

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
@@ -3040,15 +3040,25 @@ function resolveGeneratedDefault(resourceType, physicalId) {
3040
3040
  return substitutePhysical(tmpl, physicalId, physicalNameOf(physicalId));
3041
3041
  }
3042
3042
  function stripAwsTagsDeep(v) {
3043
- return stripTagsWalk(v, false);
3044
- }
3045
- function stripTagsWalk(v, underTagsKey) {
3046
- if (Array.isArray(v)) return v.filter((t) => !(t && typeof t === "object" && typeof t.Key === "string" && t.Key.startsWith("aws:"))).map((t) => stripTagsWalk(t, false));
3043
+ return stripTagsWalk(v, false, void 0);
3044
+ }
3045
+ const AWS_TAG_FILTER_PROPS = new Set([
3046
+ "TagFilters",
3047
+ "Ec2TagFilters",
3048
+ "Ec2TagSet",
3049
+ "Ec2TagGroup",
3050
+ "TargetTags"
3051
+ ]);
3052
+ function stripTagsWalk(v, underTagsKey, parentKey) {
3053
+ if (Array.isArray(v)) {
3054
+ const underFilter = parentKey !== void 0 && AWS_TAG_FILTER_PROPS.has(parentKey);
3055
+ return v.filter((t) => underFilter || !(t && typeof t === "object" && typeof t.Key === "string" && t.Key.startsWith("aws:"))).map((t) => stripTagsWalk(t, false, void 0));
3056
+ }
3047
3057
  if (v && typeof v === "object") {
3048
3058
  const out = {};
3049
3059
  for (const [k, val] of Object.entries(v)) {
3050
3060
  if (underTagsKey && k.startsWith("aws:")) continue;
3051
- out[k] = stripTagsWalk(val, k === "Tags");
3061
+ out[k] = stripTagsWalk(val, k === "Tags", k);
3052
3062
  }
3053
3063
  return out;
3054
3064
  }
@@ -5000,6 +5010,19 @@ function isSelfEchoTrivialEmpty(v, physicalId) {
5000
5010
  const rest = entries.filter(([, val]) => val !== physicalId);
5001
5011
  return rest.length < entries.length && rest.every(([, val]) => isTrivialEmpty(val));
5002
5012
  }
5013
+ const RDS_OPTION_SETTING_DEFAULTS = {
5014
+ SERVER_AUDIT: "FORCE_PLUS_PERMANENT",
5015
+ SERVER_AUDIT_LOGGING: "ON",
5016
+ SERVER_AUDIT_FILE_PATH: "/rdsdbdata/log/audit/"
5017
+ };
5018
+ function isIdentityOnlyHusk(el, idField) {
5019
+ return Object.entries(el).every(([k, v]) => k === idField || isTrivialEmpty(v));
5020
+ }
5021
+ function isRdsOptionSettingDefault(resourceType, el, name, value) {
5022
+ if (resourceType !== "AWS::RDS::OptionGroup") return false;
5023
+ if (isIdentityOnlyHusk(el, "Name")) return true;
5024
+ return name in RDS_OPTION_SETTING_DEFAULTS && value === RDS_OPTION_SETTING_DEFAULTS[name];
5025
+ }
5003
5026
  function isEmptyPolicyShell(v) {
5004
5027
  if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
5005
5028
  const o = v;
@@ -5682,8 +5705,9 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5682
5705
  const loName = String(loRec[nvSubsetSpec.nameField]);
5683
5706
  const loValue = loRec[nvSubsetSpec.valueField];
5684
5707
  const isFirehoseRetriesDefault = resourceType === "AWS::KinesisFirehose::DeliveryStream" && loName === "NumberOfRetries" && loValue === "3";
5708
+ const isRdsOptionDefault = isRdsOptionSettingDefault(resourceType, loRec, loName, loValue);
5685
5709
  findings.push({
5686
- tier: isFirehoseRetriesDefault ? "atDefault" : "undeclared",
5710
+ tier: isFirehoseRetriesDefault || isRdsOptionDefault ? "atDefault" : "undeclared",
5687
5711
  logicalId,
5688
5712
  resourceType,
5689
5713
  path: `${d.path}[${loName}]`,
@@ -11376,6 +11400,12 @@ function removeAt(root, segs) {
11376
11400
  //#region src/revert/writers.ts
11377
11401
  const str = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
11378
11402
  const strList = (v) => (Array.isArray(v) ? v : [v]).map(str).filter((s) => s !== void 0);
11403
+ const opTopSeg = (path) => path.replace(/^\//, "").split("/")[0] ?? "";
11404
+ const assertOpsConsumed = (resourceType, ops, handled) => {
11405
+ const isHandled = typeof handled === "function" ? handled : (s) => handled.has(s);
11406
+ const dropped = [...new Set(ops.map((o) => opTopSeg(o.path)).filter((s) => !isHandled(s)))];
11407
+ if (dropped.length > 0) throw new Error(`${resourceType} revert cannot apply ${dropped.join(", ")}: this SDK writer supports only a subset of properties and does not handle ${dropped.length > 1 ? "these" : "this one"}; update ${dropped.length > 1 ? "them" : "it"} manually`);
11408
+ };
11379
11409
  async function desiredModel(type, ctx, ops) {
11380
11410
  const reader = SDK_OVERRIDES[type];
11381
11411
  const current = (reader && await reader(ctx)) ?? {};
@@ -11666,11 +11696,11 @@ const writeDocDbCluster = async (ctx, ops) => {
11666
11696
  else throw new Error(`DocDB DBCluster ${top} cannot be cleared via ModifyDBCluster (its unset state is AWS-assigned/required, not expressible in a selective modify); update it manually`);
11667
11697
  any = true;
11668
11698
  }
11669
- if (!any) return;
11670
- await new DocDBClient({
11699
+ if (any) await new DocDBClient({
11671
11700
  region: ctx.region,
11672
11701
  ...CLIENT_TIMEOUTS
11673
11702
  }).send(new ModifyDBClusterCommand(input));
11703
+ assertOpsConsumed("DocDB DBCluster", ops, DOCDB_CLUSTER_MODIFY_PARAMS);
11674
11704
  };
11675
11705
  const DOCDB_INSTANCE_MODIFY_PARAMS = new Set([
11676
11706
  "DBInstanceClass",
@@ -11695,11 +11725,11 @@ const writeDocDbInstance = async (ctx, ops) => {
11695
11725
  else throw new Error(`DocDB DBInstance ${top} cannot be cleared via ModifyDBInstance (its unset state is AWS-assigned/required, not expressible in a selective modify); update it manually`);
11696
11726
  any = true;
11697
11727
  }
11698
- if (!any) return;
11699
- await new DocDBClient({
11728
+ if (any) await new DocDBClient({
11700
11729
  region: ctx.region,
11701
11730
  ...CLIENT_TIMEOUTS
11702
11731
  }).send(new ModifyDBInstanceCommand(input));
11732
+ assertOpsConsumed("DocDB DBInstance", ops, DOCDB_INSTANCE_MODIFY_PARAMS);
11703
11733
  };
11704
11734
  const writeCloudFrontDistribution = async (ctx, ops) => {
11705
11735
  const id = str(ctx.physicalId);
@@ -11798,6 +11828,7 @@ const writeGlueJob = async (ctx, ops) => {
11798
11828
  JobName: name,
11799
11829
  JobUpdate: update
11800
11830
  }));
11831
+ assertOpsConsumed("Glue Job", ops, (top) => GLUE_JOB_UPDATE_FIELDS.includes(top) || top === "MaxCapacity" || top === "AllocatedCapacity");
11801
11832
  };
11802
11833
  const writeGlueTable = async (ctx, ops) => {
11803
11834
  const m = await desiredModel("AWS::Glue::Table", ctx, ops);
@@ -12074,6 +12105,7 @@ const writeOpenSearchDomain = async (ctx, ops) => {
12074
12105
  } else input[p] = reverted[p];
12075
12106
  }
12076
12107
  await c.send(new UpdateDomainConfigCommand(input));
12108
+ assertOpsConsumed("OpenSearch Domain", ops, OS_UPDATABLE_OPTIONS);
12077
12109
  };
12078
12110
  const writeLogGroupBearerTokenAuth = async (ctx, ops) => {
12079
12111
  const lg = str(ctx.physicalId) ?? str(ctx.declared["LogGroupName"]);
@@ -12216,7 +12248,7 @@ function camelKeysDeep(v) {
12216
12248
  const writeEcsServiceWriteOnlyProps = async (ctx, ops) => {
12217
12249
  const cluster = str(ctx.declared["Cluster"]);
12218
12250
  const service = str(ctx.physicalId);
12219
- if (!cluster || !service) return;
12251
+ if (!cluster || !service) throw new Error("cannot resolve ECS cluster/service for revert");
12220
12252
  const input = {
12221
12253
  cluster,
12222
12254
  service
@@ -12464,6 +12496,7 @@ const writeEc2ClientVpnEndpoint = async (ctx, ops) => {
12464
12496
  ...CLIENT_TIMEOUTS
12465
12497
  }).send(new ModifyClientVpnEndpointCommand(input));
12466
12498
  if (unExpressible.length > 0) throw new Error(`EC2 ClientVpnEndpoint ${unExpressible.join(", ")} cannot be cleared via ModifyClientVpnEndpoint (unset state is not expressible in a selective modify)${any ? "; the other revert op(s) were applied" : ""}; update ${unExpressible.length > 1 ? "them" : "it"} manually`);
12499
+ assertOpsConsumed("EC2 ClientVpnEndpoint", ops, (top) => CLIENT_VPN_SCALAR_PARAMS.has(top) || top === "ConnectionLogOptions" || top === "DnsServers" || top === "SecurityGroupIds");
12467
12500
  };
12468
12501
  const LEX_CFN_TO_LEX_RESOLUTION_STRATEGY = {
12469
12502
  ORIGINAL_VALUE: "OriginalValue",
@@ -12805,11 +12838,11 @@ const writeElasticBeanstalkApplication = async (ctx, ops) => {
12805
12838
  any = true;
12806
12839
  }
12807
12840
  }
12808
- if (!any) return;
12809
- await new ElasticBeanstalkClient({
12841
+ if (any) await new ElasticBeanstalkClient({
12810
12842
  region: ctx.region,
12811
12843
  ...CLIENT_TIMEOUTS
12812
12844
  }).send(new UpdateApplicationCommand(input));
12845
+ assertOpsConsumed("ElasticBeanstalk Application", ops, EB_APPLICATION_MODIFY_PARAMS);
12813
12846
  };
12814
12847
  const EB_ENVIRONMENT_MODIFY_PARAMS = new Set(["Description"]);
12815
12848
  const writeElasticBeanstalkEnvironment = async (ctx, ops) => {
@@ -12824,11 +12857,11 @@ const writeElasticBeanstalkEnvironment = async (ctx, ops) => {
12824
12857
  any = true;
12825
12858
  }
12826
12859
  }
12827
- if (!any) return;
12828
- await new ElasticBeanstalkClient({
12860
+ if (any) await new ElasticBeanstalkClient({
12829
12861
  region: ctx.region,
12830
12862
  ...CLIENT_TIMEOUTS
12831
12863
  }).send(new UpdateEnvironmentCommand(input));
12864
+ assertOpsConsumed("ElasticBeanstalk Environment", ops, EB_ENVIRONMENT_MODIFY_PARAMS);
12832
12865
  };
12833
12866
  const KVS_STREAM_RETENTION_DEFAULT = 0;
12834
12867
  const KVS_CHANNEL_MESSAGE_TTL_DEFAULT = 60;
@@ -12954,6 +12987,7 @@ const writeApiGatewayV2Stage = async (ctx, ops) => {
12954
12987
  input[p] = desired[p];
12955
12988
  }
12956
12989
  if (Object.keys(input).length > 2) await client.send(new UpdateStageCommand(input));
12990
+ assertOpsConsumed("ApiGatewayV2 Stage", ops, APIGWV2_STAGE_UPDATE_FIELDS);
12957
12991
  };
12958
12992
  const writeApiGatewayRestApiPolicy = async (ctx) => {
12959
12993
  const restApiId = str(ctx.physicalId) ?? str(ctx.declared["RestApiId"]);
@@ -13185,6 +13219,12 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
13185
13219
  "AWS::Cognito::UserPool\0MfaConfiguration",
13186
13220
  "AWS::Cognito::UserPool\0UserPoolTier",
13187
13221
  "AWS::Cognito::UserPool\0Policies",
13222
+ "AWS::Cognito::UserPool\0VerificationMessageTemplate",
13223
+ "AWS::Cognito::UserPool\0AccountRecoverySetting",
13224
+ "AWS::Cognito::UserPool\0EmailConfiguration",
13225
+ "AWS::Cognito::UserPool\0KeyConfiguration",
13226
+ "AWS::Cognito::UserPool\0IssuerConfiguration",
13227
+ "AWS::Cognito::UserPool\0WebAuthnFactorConfiguration",
13188
13228
  "AWS::SNS::Subscription\0FilterPolicyScope",
13189
13229
  "AWS::InternetMonitor::Monitor\0Status",
13190
13230
  "AWS::RolesAnywhere::Profile\0DurationSeconds",
@@ -15848,6 +15888,24 @@ function finalCheckExit(code, fail) {
15848
15888
  return fail || code !== 1 ? code : 0;
15849
15889
  }
15850
15890
  /**
15891
+ * Whether `check` should open its interactive after-report resolve menu (Record / Revert /
15892
+ * Ignore / Decide-per-finding). It fires only when there is something to act on (drift,
15893
+ * unrecorded values, or no baseline yet — R141's day-1 establish) AND the run is a TTY human
15894
+ * who can make the decision. It is gated OUT of every machine/automation mode:
15895
+ * - --json / --show-all / --pre-deploy — machine output or baseline-untouched contracts,
15896
+ * - --fail — the CI drift-exit path,
15897
+ * - #1054: --yes — `--yes` has NO documented `check` contract (HELP scopes it to record /
15898
+ * ignore / revert; check's automation flag is --fail / non-TTY). In the menu the USER is
15899
+ * the decision-maker, but `--yes` means "no decision needed" in the record/ignore/revert
15900
+ * sub-actions it threads into — so a `check --yes` in a TTY silently overrode explicit
15901
+ * per-finding choices (recorded / ignored / reverted values the user declined, including
15902
+ * folded values never shown in the report). Under --yes, check just reports.
15903
+ * Pure + exported for tests.
15904
+ */
15905
+ function shouldOfferInteractiveResolve(a, ctx) {
15906
+ return (ctx.code === 1 || ctx.hasUnrecorded || !ctx.hasBaseline) && !a.json && !a.showAll && !a.preDeploy && !a.fail && !a.yes && ctx.interactive;
15907
+ }
15908
+ /**
15851
15909
  * #781: does a committed baseline exist for this stack IN THE REGION being checked?
15852
15910
  * A committed baseline is named `<stackName>.<accountId>.<region>.json` under
15853
15911
  * `.cdkrd/baselines/`. The gone stack's ACCOUNT is unknown without an STS call, so it
@@ -16092,7 +16150,12 @@ async function runCheck(args) {
16092
16150
  expandAtDefault: a.showAll
16093
16151
  });
16094
16152
  const hasUnrecorded = reconciled.some((f) => f.unrecorded === true);
16095
- if ((code === 1 || hasUnrecorded || !baseline) && !a.json && !a.showAll && !a.preDeploy && !a.fail && isInteractive()) code = await resolveInteractively({
16153
+ if (shouldOfferInteractiveResolve(a, {
16154
+ code,
16155
+ hasUnrecorded,
16156
+ hasBaseline: baseline !== void 0,
16157
+ interactive: isInteractive()
16158
+ })) code = await resolveInteractively({
16096
16159
  stackName,
16097
16160
  region,
16098
16161
  desired,