| 1 | import type * as iam from "@distilled.cloud/aws/iam"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Runtime binding for `iam:SimulateCustomPolicy` — evaluate how a set of |
| 7 | * candidate IAM policy documents would decide a list of actions, without |
| 8 | * attaching the policies to any entity. The building block for policy |
| 9 | * linters, "what would this grant?" previews, and authorization test |
| 10 | * harnesses. |
| 11 | * |
| 12 | * The policies are supplied as strings per request, so the binding takes no |
| 13 | * arguments and grants `iam:SimulateCustomPolicy` on `*`. Provide the |
| 14 | * implementation with `Effect.provide(AWS.IAM.SimulateCustomPolicyHttp)`. |
| 15 | * |
| 16 | * ### Simulating Policies |
| 17 | * **Example:** Preview a Candidate Policy |
| 18 | * ```typescript |
| 19 | * // init |
| 20 | * const simulateCustomPolicy = yield* IAM.SimulateCustomPolicy(); |
| 21 | * |
| 22 | * // runtime |
| 23 | * const { EvaluationResults } = yield* simulateCustomPolicy({ |
| 24 | * PolicyInputList: [ |
| 25 | * JSON.stringify({ |
| 26 | * Version: "2012-10-17", |
| 27 | * Statement: [ |
| 28 | * { Effect: "Allow", Action: "s3:ListAllMyBuckets", Resource: "*" }, |
| 29 | * ], |
| 30 | * }), |
| 31 | * ], |
| 32 | * ActionNames: ["s3:ListAllMyBuckets", "s3:DeleteBucket"], |
| 33 | * }); |
| 34 | * const decisions = EvaluationResults?.map((r) => r.EvalDecision); |
| 35 | * ``` |
| 36 | * |
| 37 | * @binding |
| 38 | */ |
| 39 | export interface SimulateCustomPolicy extends Binding.Service< |
| 40 | SimulateCustomPolicy, |
| 41 | "AWS.IAM.SimulateCustomPolicy", |
| 42 | () => Effect.Effect< |
| 43 | ( |
| 44 | request: iam.SimulateCustomPolicyRequest, |
| 45 | ) => Effect.Effect< |
| 46 | iam.SimulatePolicyResponse, |
| 47 | iam.SimulateCustomPolicyError |
| 48 | > |
| 49 | > |
| 50 | > {} |
| 51 | export const SimulateCustomPolicy = Binding.Service<SimulateCustomPolicy>( |
| 52 | "AWS.IAM.SimulateCustomPolicy", |
| 53 | ); |