cdk-real-drift 0.2.42 → 0.2.44

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
@@ -29,7 +29,7 @@ import { DescribeDBClustersCommand, DescribeDBInstancesCommand as DescribeDBInst
29
29
  import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand, DescribeSubnetGroupsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
30
30
  import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
31
31
  import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
32
- import { AttachGroupPolicyCommand, AttachRolePolicyCommand, AttachUserPolicyCommand, CreatePolicyVersionCommand, DeletePolicyVersionCommand, DeleteRolePolicyCommand, DetachGroupPolicyCommand, DetachRolePolicyCommand, DetachUserPolicyCommand, GetGroupPolicyCommand, GetPolicyCommand as GetPolicyCommand$1, GetPolicyVersionCommand, GetRolePolicyCommand, GetUserPolicyCommand, IAMClient, ListEntitiesForPolicyCommand, ListPolicyVersionsCommand, PutGroupPolicyCommand, PutRolePolicyCommand, PutUserPolicyCommand } from "@aws-sdk/client-iam";
32
+ 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";
33
33
  import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
34
34
  import { DescribeCacheClustersCommand, DescribeCacheParameterGroupsCommand, DescribeCacheParametersCommand, DescribeReplicationGroupsCommand, DescribeUsersCommand, ElastiCacheClient, ModifyCacheParameterGroupCommand, ResetCacheParameterGroupCommand } from "@aws-sdk/client-elasticache";
35
35
  import { DescribeParameterGroupsCommand as DescribeParameterGroupsCommand$1, DescribeParametersCommand as DescribeParametersCommand$1, DescribeUsersCommand as DescribeUsersCommand$1, MemoryDBClient, ResetParameterGroupCommand, UpdateParameterGroupCommand as UpdateParameterGroupCommand$1 } from "@aws-sdk/client-memorydb";
@@ -2486,22 +2486,37 @@ function deepCompareUnordered(a, b) {
2486
2486
  const ak = Object.keys(ao);
2487
2487
  return ak.length === Object.keys(bo).length && ak.every((k) => Object.hasOwn(bo, k) && deepCompareUnordered(ao[k], bo[k]));
2488
2488
  }
2489
- function isJsonStringStructEqual(a, b) {
2490
- const parse = (s) => {
2489
+ function parseStructured(s) {
2490
+ let parsed;
2491
+ try {
2492
+ parsed = JSON.parse(s);
2493
+ } catch {
2491
2494
  try {
2492
- return JSON.parse(s);
2495
+ parsed = parse(s);
2493
2496
  } catch {
2494
2497
  return SENTINEL_UNPARSEABLE;
2495
2498
  }
2496
- };
2497
- if (typeof a === "string" && b !== null && typeof b === "object") {
2498
- const pa = parse(a);
2499
+ }
2500
+ return parsed !== null && typeof parsed === "object" ? parsed : SENTINEL_UNPARSEABLE;
2501
+ }
2502
+ function isJsonStringStructEqual(a, b) {
2503
+ const aStr = typeof a === "string";
2504
+ const bStr = typeof b === "string";
2505
+ const aObj = !aStr && a !== null && typeof a === "object";
2506
+ if (aStr && !bStr && b !== null && typeof b === "object") {
2507
+ const pa = parseStructured(a);
2499
2508
  return pa !== SENTINEL_UNPARSEABLE && deepCompareUnordered(pa, b);
2500
2509
  }
2501
- if (typeof b === "string" && a !== null && typeof a === "object") {
2502
- const pb = parse(b);
2510
+ if (bStr && aObj) {
2511
+ const pb = parseStructured(b);
2503
2512
  return pb !== SENTINEL_UNPARSEABLE && deepCompareUnordered(a, pb);
2504
2513
  }
2514
+ if (aStr && bStr) {
2515
+ const pa = parseStructured(a);
2516
+ if (pa === SENTINEL_UNPARSEABLE) return false;
2517
+ const pb = parseStructured(b);
2518
+ return pb !== SENTINEL_UNPARSEABLE && deepCompareUnordered(pa, pb);
2519
+ }
2505
2520
  return false;
2506
2521
  }
2507
2522
  const JSON_STRING_PROPS = { "AWS::Config::ConfigRule": new Set(["InputParameters"]) };
@@ -3300,14 +3315,7 @@ function prettyConstructPath(p) {
3300
3315
  */
3301
3316
  function collectPrincipalsWithSiblingPolicies(resources, ctx) {
3302
3317
  const principals = /* @__PURE__ */ new Map();
3303
- for (const res of Object.values(resources)) {
3304
- if (res?.Type !== "AWS::IAM::Policy") continue;
3305
- const name = resolvePolicyName(res.Properties?.PolicyName, ctx);
3306
- const refs = [
3307
- ...res.Properties?.Roles ?? [],
3308
- ...res.Properties?.Users ?? [],
3309
- ...res.Properties?.Groups ?? []
3310
- ];
3318
+ const attach = (name, refs) => {
3311
3319
  for (const r of refs) {
3312
3320
  const ref = r && typeof r === "object" ? r.Ref : void 0;
3313
3321
  if (typeof ref !== "string") continue;
@@ -3316,9 +3324,26 @@ function collectPrincipalsWithSiblingPolicies(resources, ctx) {
3316
3324
  if (name === void 0) principals.set(ref, "unresolved");
3317
3325
  else principals.set(ref, [...prev ?? [], name]);
3318
3326
  }
3327
+ };
3328
+ for (const res of Object.values(resources)) {
3329
+ const name = resolvePolicyName(res?.Properties?.PolicyName, ctx);
3330
+ if (res?.Type === "AWS::IAM::Policy") attach(name, [
3331
+ ...res.Properties?.Roles ?? [],
3332
+ ...res.Properties?.Users ?? [],
3333
+ ...res.Properties?.Groups ?? []
3334
+ ]);
3335
+ else {
3336
+ const singular = IAM_STANDALONE_INLINE_POLICY_TYPES.get(res?.Type);
3337
+ if (singular !== void 0) attach(name, [res?.Properties?.[singular]]);
3338
+ }
3319
3339
  }
3320
3340
  return principals;
3321
3341
  }
3342
+ const IAM_STANDALONE_INLINE_POLICY_TYPES = new Map([
3343
+ ["AWS::IAM::RolePolicy", "RoleName"],
3344
+ ["AWS::IAM::UserPolicy", "UserName"],
3345
+ ["AWS::IAM::GroupPolicy", "GroupName"]
3346
+ ]);
3322
3347
  /**
3323
3348
  * The set of ECS Cluster logicalIds that a sibling AWS::ECS::ClusterCapacityProviderAssociations
3324
3349
  * resource references (via its `Cluster: { Ref }`). CapacityProviders and
@@ -4114,6 +4139,10 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
4114
4139
  live.Policies = live.Policies.filter((p) => !(p && typeof p === "object" && names.has(p.PolicyName)));
4115
4140
  }
4116
4141
  let knownDef = KNOWN_DEFAULTS[resourceType] ?? {};
4142
+ if (resourceType === "AWS::IAM::AccessKey") knownDef = {
4143
+ ...knownDef,
4144
+ Status: "Active"
4145
+ };
4117
4146
  if (resourceType === "AWS::Redshift::Cluster" && typeof declaredIn?.["NodeType"] === "string" && declaredIn["NodeType"].startsWith("ra3")) knownDef = {
4118
4147
  ...knownDef,
4119
4148
  Encrypted: true,
@@ -6559,6 +6588,19 @@ const readIamPolicy = async ({ declared, region }) => {
6559
6588
  ...role ? { Roles: declared.Roles } : user ? { Users: declared.Users } : { Groups: declared.Groups }
6560
6589
  };
6561
6590
  };
6591
+ const readIamAccessKey = async ({ declared, physicalId, region }) => {
6592
+ const userName = str$1(declared.UserName);
6593
+ if (!userName) return void 0;
6594
+ const meta = ((await new IAMClient({
6595
+ region,
6596
+ ...READ_RETRY
6597
+ }).send(new ListAccessKeysCommand({ UserName: userName }))).AccessKeyMetadata ?? []).find((m) => m.AccessKeyId === physicalId);
6598
+ if (!meta) return void 0;
6599
+ return {
6600
+ UserName: userName,
6601
+ Status: meta.Status
6602
+ };
6603
+ };
6562
6604
  const readIamManagedPolicy = async ({ physicalId, region }) => {
6563
6605
  if (!physicalId.startsWith("arn:")) return void 0;
6564
6606
  const c = new IAMClient({
@@ -7658,6 +7700,7 @@ const SDK_OVERRIDES = {
7658
7700
  "AWS::SQS::QueuePolicy": readSqsQueuePolicy,
7659
7701
  "AWS::IAM::Policy": readIamPolicy,
7660
7702
  "AWS::IAM::ManagedPolicy": readIamManagedPolicy,
7703
+ "AWS::IAM::AccessKey": readIamAccessKey,
7661
7704
  "AWS::Lambda::Permission": readLambdaPermission,
7662
7705
  "AWS::Budgets::Budget": readBudget,
7663
7706
  "AWS::EC2::EIP": readEc2Eip,
@@ -8516,7 +8559,27 @@ async function isManagedBySiblingStack(cfn, c, cache) {
8516
8559
  if (cached !== void 0) return cached;
8517
8560
  let managed = false;
8518
8561
  try {
8519
- managed = ((await cfn.send(new DescribeStackResourcesCommand({ PhysicalResourceId: physicalId }))).StackResources ?? []).some((r) => r.PhysicalResourceId === physicalId && r.ResourceType === c.resourceType);
8562
+ const res = await cfn.send(new DescribeStackResourcesCommand({ PhysicalResourceId: physicalId }));
8563
+ const owns = (rs) => rs.some((r) => r.PhysicalResourceId === physicalId && r.ResourceType === c.resourceType);
8564
+ const first = res.StackResources ?? [];
8565
+ if (owns(first)) managed = true;
8566
+ else {
8567
+ const stackName = first[0]?.StackName;
8568
+ if (stackName) {
8569
+ let next;
8570
+ do {
8571
+ const page = await cfn.send(new ListStackResourcesCommand({
8572
+ StackName: stackName,
8573
+ NextToken: next
8574
+ }));
8575
+ if (owns(page.StackResourceSummaries ?? [])) {
8576
+ managed = true;
8577
+ break;
8578
+ }
8579
+ next = page.NextToken;
8580
+ } while (next);
8581
+ }
8582
+ }
8520
8583
  } catch {
8521
8584
  managed = false;
8522
8585
  }