The best way to control Claude Code, Codex and more from any computer or phone

main
ts 87 lines 2.97 KB
Raw
1 import * as iam from "@distilled.cloud/aws/iam";
2 import * as Provider from "alchemy/Provider";
3 import { Resource } from "alchemy/Resource";
4 import { toWireDays } from "alchemy/Util/Duration";
5 import type * as Duration from "effect/Duration";
6 import * as Effect from "effect/Effect";
7 import type { Providers } from "../Providers.ts";
8
9 export interface AccountPasswordPolicyProps extends Omit<
10 iam.UpdateAccountPasswordPolicyRequest,
11 "MaxPasswordAge"
12 > {
13 /**
14 * Maximum password validity duration, e.g. `"90 days"` or
15 * `Duration.days(90)`. Sent to IAM as whole days (a bare number is
16 * milliseconds).
17 */
18 MaxPasswordAge?: Duration.Input;
19 }
20
21 export interface AccountPasswordPolicy extends Resource<
22 "AWS.IAM.AccountPasswordPolicy",
23 AccountPasswordPolicyProps,
24 iam.PasswordPolicy,
25 never,
26 Providers
27 > {}
28
29 /**
30 * The singleton IAM account password policy.
31 *
32 * `AccountPasswordPolicy` manages the account-wide password requirements that
33 * apply to IAM users with console passwords.
34 * ### Managing Password Rules
35 * **Example:** Require Strong Passwords
36 * ```typescript
37 * const policy = yield* AccountPasswordPolicy("PasswordPolicy", {
38 * MinimumPasswordLength: 16,
39 * RequireSymbols: true,
40 * RequireNumbers: true,
41 * RequireUppercaseCharacters: true,
42 * RequireLowercaseCharacters: true,
43 * AllowUsersToChangePassword: true,
44 * });
45 * ```
46 *
47 * @resource
48 */
49 export const AccountPasswordPolicy = Resource<AccountPasswordPolicy>(
50 "AWS.IAM.AccountPasswordPolicy",
51 );
52
53 export const AccountPasswordPolicyProvider = () =>
54 Provider.succeed(AccountPasswordPolicy, {
55 read: Effect.fn(function* () {
56 const response = yield* iam
57 .getAccountPasswordPolicy({})
58 .pipe(Effect.catchTag("NoSuchEntityException", () => Effect.undefined));
59 return response?.PasswordPolicy;
60 }),
61 // Account-level singleton: IAM exposes no enumeration API, only
62 // `getAccountPasswordPolicy`. Return the single policy as a one-element
63 // array, or `[]` when none is set (typed `NoSuchEntityException`).
64 list: () =>
65 iam.getAccountPasswordPolicy({}).pipe(
66 Effect.map((response) => [response.PasswordPolicy]),
67 Effect.catchTag("NoSuchEntityException", () => Effect.succeed([])),
68 ),
69 reconcile: Effect.fn(function* ({ news, session }) {
70 // The account password policy is a singleton driven entirely by
71 // `updateAccountPasswordPolicy`, which is itself a full upsert.
72 // Observation is implicit in the API — there is nothing meaningful
73 // to diff because the request payload *is* the desired state.
74 const request = {
75 ...news,
76 MaxPasswordAge: toWireDays(news.MaxPasswordAge),
77 };
78 yield* iam.updateAccountPasswordPolicy(request);
79 yield* session.note("account-password-policy");
80 return request;
81 }),
82 delete: Effect.fn(function* () {
83 yield* iam
84 .deleteAccountPasswordPolicy({})
85 .pipe(Effect.catchTag("NoSuchEntityException", () => Effect.void));
86 }),
87 });