@go-to-k/cdkd 0.36.0 → 0.38.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.
Binary file
package/dist/index.js CHANGED
@@ -8213,6 +8213,85 @@ var IAMRoleProvider = class {
8213
8213
  throw err;
8214
8214
  }
8215
8215
  }
8216
+ /**
8217
+ * Read the AWS-current IAM role configuration in CFn-property shape.
8218
+ *
8219
+ * Issues `GetRole` for the top-level role configuration and
8220
+ * `ListRolePolicies` + `ListAttachedRolePolicies` for inline / managed
8221
+ * policy *names*. AWS URL-decodes `AssumeRolePolicyDocument` for us
8222
+ * when it surfaces — we re-parse it as JSON so the comparator can match
8223
+ * against state's already-parsed object.
8224
+ *
8225
+ * Coverage and shape decisions:
8226
+ * - `RoleName`, `Description`, `MaxSessionDuration`, `Path`,
8227
+ * `PermissionsBoundary` — straight from `Role.*`.
8228
+ * - `AssumeRolePolicyDocument` — `Role.AssumeRolePolicyDocument` is a
8229
+ * URL-encoded JSON string; we URL-decode + JSON-parse so cdkd state's
8230
+ * object form compares cleanly. (Both shapes — string and object — are
8231
+ * accepted by `create()`, but state typically stores the parsed object
8232
+ * after intrinsic resolution.)
8233
+ * - `ManagedPolicyArns` — array of ARN strings from
8234
+ * `ListAttachedRolePolicies`.
8235
+ * - `Policies` (inline policies with `PolicyDocument` bodies) is
8236
+ * intentionally omitted: surfacing names without bodies guarantees a
8237
+ * PolicyDocument-shaped drift on every role, and fetching every body
8238
+ * costs one extra `GetRolePolicy` per inline policy. Out of scope for
8239
+ * v1 — drift detection on inline IAM policy bodies can ship in a
8240
+ * follow-up.
8241
+ * - `Tags` is omitted for the same reason as Lambda's tags handling
8242
+ * (CDK auto-injects `aws:cdk:path` and the shape decision belongs in a
8243
+ * dedicated tags PR).
8244
+ *
8245
+ * Returns `undefined` when the role is gone (`NoSuchEntityException`).
8246
+ */
8247
+ async readCurrentState(physicalId, _logicalId, _resourceType) {
8248
+ let role;
8249
+ try {
8250
+ const resp = await this.iamClient.send(new GetRoleCommand({ RoleName: physicalId }));
8251
+ role = resp.Role;
8252
+ } catch (err) {
8253
+ if (err instanceof NoSuchEntityException)
8254
+ return void 0;
8255
+ throw err;
8256
+ }
8257
+ if (!role)
8258
+ return void 0;
8259
+ const result = {};
8260
+ if (role.RoleName !== void 0)
8261
+ result["RoleName"] = role.RoleName;
8262
+ if (role.Description !== void 0 && role.Description !== "") {
8263
+ result["Description"] = role.Description;
8264
+ }
8265
+ if (role.MaxSessionDuration !== void 0) {
8266
+ result["MaxSessionDuration"] = role.MaxSessionDuration;
8267
+ }
8268
+ if (role.Path !== void 0)
8269
+ result["Path"] = role.Path;
8270
+ if (role.PermissionsBoundary?.PermissionsBoundaryArn !== void 0) {
8271
+ result["PermissionsBoundary"] = role.PermissionsBoundary.PermissionsBoundaryArn;
8272
+ }
8273
+ if (role.AssumeRolePolicyDocument) {
8274
+ try {
8275
+ result["AssumeRolePolicyDocument"] = JSON.parse(
8276
+ decodeURIComponent(role.AssumeRolePolicyDocument)
8277
+ );
8278
+ } catch {
8279
+ result["AssumeRolePolicyDocument"] = role.AssumeRolePolicyDocument;
8280
+ }
8281
+ }
8282
+ try {
8283
+ const attached = await this.iamClient.send(
8284
+ new ListAttachedRolePoliciesCommand({ RoleName: physicalId })
8285
+ );
8286
+ const arns = (attached.AttachedPolicies ?? []).map((p) => p.PolicyArn).filter((arn) => !!arn);
8287
+ if (arns.length > 0)
8288
+ result["ManagedPolicyArns"] = arns;
8289
+ } catch (err) {
8290
+ if (!(err instanceof NoSuchEntityException))
8291
+ throw err;
8292
+ }
8293
+ return result;
8294
+ }
8216
8295
  /**
8217
8296
  * Adopt an existing IAM role into cdkd state.
8218
8297
  *