nomoss 0.0.3 → 0.0.4

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.
Files changed (150) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +5 -15
  3. package/ROADMAP.md +2 -0
  4. package/docs/README.md +1 -1
  5. package/docs/application/aws-resource-coverage.md +26 -0
  6. package/docs/application/aws-resource-lifecycle-management.md +13 -23
  7. package/docs/application/cli-workflow.md +1 -1
  8. package/docs/application/engine-design.md +2 -2
  9. package/docs/application/generation-architecture.md +10 -45
  10. package/docs/application/resource-command-policy-stage.md +2 -2
  11. package/docs/application/resource-graph.md +1 -1
  12. package/docs/application/resource-lifecycle-tracker.md +1 -9
  13. package/docs/application/resource-mapping.md +4 -9
  14. package/docs/application/resource-operations.md +4 -2
  15. package/docs/application/tracing.md +2 -6
  16. package/docs/development/code-documentation.md +2 -0
  17. package/docs/development/effect-native-development.md +44 -0
  18. package/docs/development/linting.md +1 -1
  19. package/docs/development/review-code.md +22 -6
  20. package/docs/development/review-remediation-spec.md +28 -37
  21. package/docs/development/spec-writing.md +1 -1
  22. package/docs/development/testing.md +23 -9
  23. package/docs/operations/observability-sop.md +11 -17
  24. package/docs/operations/releasing.md +3 -1
  25. package/examples/README.md +3 -26
  26. package/examples/commands.ts +2 -36
  27. package/examples/queue/application.ts +8 -2
  28. package/examples/state-machine/application.ts +3 -1
  29. package/package.json +40 -46
  30. package/providers/aws/README.md +21 -0
  31. package/providers/aws/awsEnvironment.ts +114 -0
  32. package/providers/aws/generated/managementRegistry.ts +136 -0
  33. package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
  34. package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
  35. package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
  36. package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
  37. package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
  38. package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
  39. package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
  40. package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
  41. package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
  42. package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
  43. package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
  44. package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
  45. package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
  46. package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
  47. package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
  48. package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
  49. package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
  50. package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
  51. package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
  52. package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
  53. package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
  54. package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
  55. package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
  56. package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
  57. package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
  58. package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
  59. package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
  60. package/providers/aws/management/mappings/iam/group.ts +63 -0
  61. package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
  62. package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
  63. package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
  64. package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
  65. package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
  66. package/providers/aws/management/mappings/iam/role.ts +74 -0
  67. package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
  68. package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
  69. package/providers/aws/management/mappings/iam/user.ts +61 -0
  70. package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
  71. package/providers/aws/management/operations/iam/accessKey.ts +206 -0
  72. package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
  73. package/providers/aws/management/operations/iam/policy.ts +476 -0
  74. package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
  75. package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
  76. package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
  77. package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
  78. package/providers/aws/management/resourceAssociations.ts +168 -0
  79. package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
  80. package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
  81. package/providers/aws/management/resourceManagementModule.ts +31 -0
  82. package/providers/aws/management/resourceManagementRegistry.ts +62 -0
  83. package/providers/aws/management/resourceMapping.ts +84 -0
  84. package/providers/aws/management/resourceOperation.ts +134 -0
  85. package/providers/aws/management/resourceTagOperations.ts +108 -0
  86. package/providers/aws/management/resourceTiming.ts +4 -0
  87. package/providers/aws/runtime.ts +52 -0
  88. package/src/core/resource/resourceCommandPolicy.ts +20 -0
  89. package/src/core/resource/resourceLifecycle.ts +644 -0
  90. package/src/core/resource/resourceStabilization.ts +120 -0
  91. package/src/core/resource/resourceVersions.ts +102 -0
  92. package/src/core/stack/planner.ts +9 -0
  93. package/src/core/stack/resourceStackLifecycle.ts +36 -3
  94. package/src/core/state/resourceState.ts +6 -4
  95. package/src/core/state/stateStore.ts +57 -10
  96. package/src/providers/file/resourcePolicy.ts +13 -12
  97. package/src/providers/providerRuntimeLayer.ts +5 -2
  98. package/src/providers/resourceCommandPolicyLayer.ts +117 -37
  99. package/src/providers/stripe/management/resourcePolicy.ts +22 -11
  100. package/examples/http-echo/application.ts +0 -87
  101. package/src/providers/aws/client/awsClient.ts +0 -418
  102. package/src/providers/aws/client/awsClientConfig.ts +0 -133
  103. package/src/providers/aws/client/awsClientModel.ts +0 -119
  104. package/src/providers/aws/client/awsHttpOperation.ts +0 -153
  105. package/src/providers/aws/client/awsQueryOperation.ts +0 -149
  106. package/src/providers/aws/client/awsRequestSigner.ts +0 -115
  107. package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
  108. package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
  109. package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
  110. package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
  111. package/src/providers/aws/client/generated/iam.ts +0 -10892
  112. package/src/providers/aws/client/generated/lambda.ts +0 -5403
  113. package/src/providers/aws/client/generated/sqs.ts +0 -3769
  114. package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
  115. package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
  116. package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
  117. package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
  118. package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
  119. package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
  120. package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
  121. package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
  122. package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
  123. package/src/providers/aws/cloudControl/client.ts +0 -69
  124. package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
  125. package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
  126. package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
  127. package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
  128. package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
  129. package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
  130. package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
  131. package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
  132. package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
  133. package/src/providers/aws/cloudControl/runtime.ts +0 -127
  134. package/src/providers/aws/management/resourceMapping.ts +0 -343
  135. package/src/providers/aws/management/resourceOperation.ts +0 -57
  136. package/src/providers/aws/management/resourcePolicy.ts +0 -549
  137. package/src/providers/aws/management/resourceRegistration.ts +0 -294
  138. package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
  139. package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
  140. package/src/providers/aws/resources/iam/grant.ts +0 -150
  141. package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
  142. package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
  143. package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
  144. package/src/providers/aws/resources/iam/role.ts +0 -426
  145. package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
  146. package/src/providers/aws/resources/lambda/function.ts +0 -403
  147. package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
  148. package/src/providers/aws/resources/lambda/permission.ts +0 -363
  149. package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
  150. package/src/providers/aws/runtime.ts +0 -70
@@ -0,0 +1,61 @@
1
+ import {
2
+ CreateUserRequest,
3
+ iamOperations,
4
+ User,
5
+ } from "@tradedal/aws-client-iam";
6
+ import { Schema } from "effect";
7
+ import {
8
+ AWSUserOutputsSchema,
9
+ AWSUserResourceSchema,
10
+ } from "nomoss/providers/aws/iam/user";
11
+ import {
12
+ type AwsResourceLifecycleMapping,
13
+ AwsResourceLifecycleRegistration,
14
+ } from "../../resourceLifecycleRegistration.js";
15
+ import { resourceRequest, resourceResponse } from "../../resourceOperation.js";
16
+ import { IamUserId } from "./iamIdentity.js";
17
+ import { iamLifecycleSettings } from "./iamLifecycleSettings.js";
18
+
19
+ const name = { UserName: User.schema.fields.UserName };
20
+ const path = Schema.optionalKey(User.schema.fields.Path);
21
+
22
+ /**
23
+ * The userLifecycleMapping definition requires the original UserId before
24
+ * the stack can mutate a user by name. That check still applies when the
25
+ * declaration supplied the name explicitly.
26
+ *
27
+ * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (User and GetUser)
28
+ * @see ../../../../../refs/effect/packages/effect/src/Schema.ts (encodeKeys)
29
+ */
30
+ const userLifecycleMapping = {
31
+ schema: AWSUserResourceSchema,
32
+ outputsSchema: AWSUserOutputsSchema,
33
+ generatedName: { property: "UserName", maxLength: 64 },
34
+ ownership: {
35
+ identity: Schema.Struct({ ...name, UserId: IamUserId }),
36
+ property: "UserId",
37
+ },
38
+ create: resourceResponse(
39
+ resourceRequest(iamOperations.CreateUser, CreateUserRequest.schema),
40
+ User,
41
+ ({ User }) => User,
42
+ ),
43
+ read: resourceResponse(iamOperations.GetUser, User, ({ User }) => User),
44
+ update: resourceRequest(
45
+ iamOperations.UpdateUser,
46
+ Schema.Struct({ ...name, Path: path }).pipe(
47
+ Schema.encodeKeys({ Path: "NewPath" }),
48
+ ),
49
+ ),
50
+ remove: iamOperations.DeleteUser,
51
+ } satisfies AwsResourceLifecycleMapping;
52
+
53
+ /**
54
+ * The makeUserManagement constructor registers the IAM user. An in-place
55
+ * update can change the user's path. The update request uses the saved
56
+ * user name, so use a replacement to change that name.
57
+ */
58
+ export const makeUserManagement = AwsResourceLifecycleRegistration.make(
59
+ iamLifecycleSettings,
60
+ userLifecycleMapping,
61
+ );
@@ -0,0 +1,75 @@
1
+ import {
2
+ GetGroupRequest,
3
+ Group,
4
+ iamOperations,
5
+ User,
6
+ } from "@tradedal/aws-client-iam";
7
+ import { Array as Arr, Schema, Struct } from "effect";
8
+ import {
9
+ AWSUserToGroupAdditionOutputsSchema,
10
+ AWSUserToGroupAdditionRequestSchema,
11
+ AWSUserToGroupAdditionResourceSchema,
12
+ } from "nomoss/providers/aws/iam/usertogroupaddition";
13
+ import {
14
+ AssociationPage,
15
+ type AwsResourceAssociationMapping,
16
+ AwsResourceAssociationRegistration,
17
+ } from "../../resourceAssociationRegistration.js";
18
+ import { resourceRequest, resourceResponse } from "../../resourceOperation.js";
19
+ import { iamLifecycleSettings } from "./iamLifecycleSettings.js";
20
+
21
+ const group = Schema.Struct({
22
+ Parent: Group.schema.fields.GroupName,
23
+ Marker: GetGroupRequest.schema.fields.Marker,
24
+ }).pipe(Schema.encodeKeys({ Parent: "GroupName" }));
25
+
26
+ const membership = Schema.Struct({
27
+ Parent: Group.schema.fields.GroupName,
28
+ Member: User.schema.fields.UserName,
29
+ }).pipe(Schema.encodeKeys({ Parent: "GroupName", Member: "UserName" }));
30
+
31
+ /**
32
+ * The userToGroupAddition mapping uses GetGroup to verify the group ID on
33
+ * each page. The lifecycle needs every page to tell whether the declared
34
+ * users are already members. A name alone could refer to a replacement group.
35
+ *
36
+ * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (GetGroup and RemoveUserFromGroup)
37
+ * @see ../../../../../refs/effect/packages/effect/src/Schema.ts (encodeKeys)
38
+ */
39
+ const userToGroupAddition = {
40
+ schema: AWSUserToGroupAdditionResourceSchema,
41
+ outputsSchema: AWSUserToGroupAdditionOutputsSchema,
42
+ request: Schema.Struct({
43
+ Parent: AWSUserToGroupAdditionRequestSchema.fields.GroupName,
44
+ Members: AWSUserToGroupAdditionRequestSchema.fields.Users,
45
+ }).pipe(Schema.encodeKeys({ Parent: "GroupName", Members: "Users" })),
46
+ list: resourceResponse(
47
+ resourceRequest(iamOperations.GetGroup, group),
48
+ AssociationPage,
49
+ (page) =>
50
+ Struct.assign(
51
+ {
52
+ ParentId: page.Group.GroupId,
53
+ Members: Arr.map(page.Users, ({ UserName }) => UserName),
54
+ },
55
+ Struct.pick(page, ["Marker", "IsTruncated"]),
56
+ ),
57
+ ),
58
+ operations: {
59
+ add: resourceRequest(iamOperations.AddUserToGroup, membership),
60
+ remove: resourceRequest(iamOperations.RemoveUserFromGroup, membership),
61
+ },
62
+ observationKeys: { parent: "GroupName", members: "Users" },
63
+ } satisfies AwsResourceAssociationMapping;
64
+
65
+ /**
66
+ * The makeUserToGroupAdditionManagement constructor registers a lifecycle
67
+ * for the selected memberships. If you remove that declaration, the stack
68
+ * uses the saved record to remove its users from the original group. Other
69
+ * members and the group itself stay in IAM.
70
+ */
71
+ export const makeUserToGroupAdditionManagement =
72
+ AwsResourceAssociationRegistration.make(
73
+ iamLifecycleSettings,
74
+ userToGroupAddition,
75
+ );
@@ -0,0 +1,206 @@
1
+ import { AwsClient } from "@tradedal/aws-client-core";
2
+ import { AwsServiceError } from "@tradedal/aws-client-core/model";
3
+ import {
4
+ type AccessKeyMetadata,
5
+ iamOperations,
6
+ iamService,
7
+ StatusType,
8
+ } from "@tradedal/aws-client-iam";
9
+ import { Array as Arr, Context, Effect, Option, Schema, Stream } from "effect";
10
+ import {
11
+ AWSAccessKeyOutputsSchema,
12
+ AWSAccessKeyRequestSchema,
13
+ AWSAccessKeyResourceSchema,
14
+ } from "nomoss/providers/aws/iam/accesskey";
15
+ import {
16
+ ResourceModel,
17
+ type ResourceNode,
18
+ } from "../../../../../src/core/resource/model.js";
19
+ import { ResourceLifecycle } from "../../../../../src/core/resource/resourceLifecycle.js";
20
+ import { resourceTiming } from "../../resourceTiming.js";
21
+
22
+ /**
23
+ * The identity schema requires the access key ID and its secret in saved
24
+ * state. IAM's key list can confirm the ID, but the stack can recover the
25
+ * secret only from the original create reply or its own state.
26
+ */
27
+ const identity = Schema.Struct({
28
+ UserName: AWSAccessKeyRequestSchema.fields.UserName,
29
+ Id: AwsCredentials.fields.accessKeyId,
30
+ SecretAccessKey: AwsCredentials.fields.secretAccessKey,
31
+ });
32
+
33
+ /**
34
+ * The checkpoint schema lets a stack resume an interrupted create without
35
+ * a second request for a key. The saved status records what IAM reported when
36
+ * it issued the key; a fresh read determines whether the stack still needs
37
+ * a status change.
38
+ */
39
+ const checkpoint = Schema.Struct({ ...identity.fields, Status: StatusType });
40
+
41
+ const requestedStatus = Schema.Literals(["Active", "Inactive"]);
42
+
43
+ const missing = AwsServiceError.hasCode("NoSuchEntity");
44
+
45
+ /**
46
+ * The AccessKeyManagement service supports an interrupted apply for a key
47
+ * that IAM has already issued. IAM exposes the secret in the create reply
48
+ * only, so the stack preserves that reply in protected state until it can
49
+ * confirm the key and expose its outputs.
50
+ *
51
+ * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (CreateAccessKey)
52
+ */
53
+ export class AccessKeyManagement extends Context.Service<AccessKeyManagement>()(
54
+ "nomoss/providers/aws/management/operations/iam/accessKey/AccessKeyManagement",
55
+ {
56
+ make: Effect.gen(function* () {
57
+ const model = yield* ResourceModel;
58
+ const client = yield* AwsClient;
59
+
60
+ const bind = client.bindOperation(iamService);
61
+
62
+ const createAccessKey = bind(iamOperations.CreateAccessKey);
63
+ const updateAccessKey = bind(iamOperations.UpdateAccessKey);
64
+ const deleteAccessKey = bind(iamOperations.DeleteAccessKey);
65
+
66
+ const listAccessKeys = client.bindOperationPages(iamService)(
67
+ iamOperations.ListAccessKeys,
68
+ );
69
+
70
+ yield* model.registerOutputsSchema(
71
+ AWSAccessKeyResourceSchema,
72
+ AWSAccessKeyOutputsSchema,
73
+ );
74
+
75
+ const propsFor = (node: ResourceNode) =>
76
+ model.decodeProps(node, AWSAccessKeyRequestSchema);
77
+
78
+ /**
79
+ * The statusFor operation uses Active if the declaration omits Status. If
80
+ * you remove an explicit Inactive value, the next apply can reactivate the
81
+ * same key.
82
+ */
83
+ const statusFor = (node: ResourceNode) =>
84
+ propsFor(node).pipe(
85
+ Effect.flatMap(({ Status }) =>
86
+ Schema.decodeUnknownEffect(requestedStatus)(Status ?? "Active"),
87
+ ),
88
+ );
89
+
90
+ /**
91
+ * The lookup operation can prove the saved key is absent if IAM reports
92
+ * that the user is gone or if the full key list excludes the saved ID.
93
+ * Stream.runHead stops at the first match. If a page fails before that
94
+ * match, the stack cannot assume it is safe to discard the key record.
95
+ *
96
+ * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (ListAccessKeys)
97
+ * @see ../../../../../refs/effect/packages/effect/src/Stream.ts (runHead)
98
+ */
99
+ const lookup = Effect.fn("AccessKey.lookup")(function* (
100
+ saved: typeof identity.Type,
101
+ ) {
102
+ const key: Option.Option<AccessKeyMetadata> = yield* listAccessKeys({
103
+ UserName: saved.UserName,
104
+ }).pipe(
105
+ Stream.map(({ AccessKeyMetadata }) =>
106
+ Arr.findFirst(
107
+ AccessKeyMetadata,
108
+ ({ AccessKeyId }) => AccessKeyId === saved.Id,
109
+ ),
110
+ ),
111
+ Stream.filter(Option.isSome),
112
+ Stream.map(({ value }) => value),
113
+ Stream.runHead,
114
+ Effect.catchIf(missing, () => Effect.succeedNone),
115
+ );
116
+
117
+ return yield* key.pipe(
118
+ Option.map(({ Status }) =>
119
+ Schema.decodeUnknownEffect(StatusType)(Status).pipe(
120
+ Effect.map((Status) => ({ ...saved, Status })),
121
+ ),
122
+ ),
123
+ Effect.transposeOption,
124
+ );
125
+ });
126
+
127
+ const lifecycle = yield* ResourceLifecycle.make(
128
+ { identity, lookup },
129
+ resourceTiming.iam,
130
+ );
131
+
132
+ /**
133
+ * The create operation rejects an invalid status before IAM issues a key.
134
+ * A declaration may ask for an inactive key, but IAM creates it as Active.
135
+ * The stack saves the issued key before it applies the requested status.
136
+ *
137
+ * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (CreateAccessKey)
138
+ */
139
+ const create = Effect.fn("AccessKey.create")(function* (
140
+ node: ResourceNode,
141
+ ) {
142
+ const { UserName } = yield* propsFor(node);
143
+
144
+ yield* statusFor(node);
145
+
146
+ const { AccessKey } = yield* createAccessKey({ UserName });
147
+
148
+ const created = yield* Schema.decodeEffect(checkpoint)({
149
+ UserName: AccessKey.UserName,
150
+ Id: AccessKey.AccessKeyId,
151
+ SecretAccessKey: AccessKey.SecretAccessKey,
152
+ Status: AccessKey.Status,
153
+ });
154
+
155
+ return created;
156
+ });
157
+
158
+ /**
159
+ * The applyStatus operation changes the status of the key the stack already
160
+ * has. If the latest read already shows the requested status, a resumed
161
+ * apply leaves it unchanged. The result checks that status on a later read.
162
+ */
163
+ const applyStatus = Effect.fn("AccessKey.applyStatus")(function* (
164
+ key: typeof checkpoint.Type,
165
+ Status: typeof requestedStatus.Type,
166
+ ) {
167
+ yield* updateAccessKey({
168
+ UserName: key.UserName,
169
+ AccessKeyId: key.Id,
170
+ Status,
171
+ }).pipe(Effect.when(Effect.succeed(key.Status !== Status)));
172
+
173
+ return (observed: typeof checkpoint.Type) => observed.Status === Status;
174
+ });
175
+
176
+ /**
177
+ * The remove operation accepts NoSuchEntity from IAM so teardown can resume
178
+ * after the provider deleted the key but the stack still has its record.
179
+ */
180
+ const remove = (key: typeof identity.Type) =>
181
+ deleteAccessKey({
182
+ UserName: key.UserName,
183
+ AccessKeyId: key.Id,
184
+ }).pipe(Effect.catchIf(missing, () => Effect.void));
185
+
186
+ return ResourceLifecycle.execute(
187
+ ResourceLifecycle.commands({
188
+ Read: (command) => lifecycle.observe(command),
189
+ Create: lifecycle.create(create, {
190
+ checkpoint,
191
+ configure: (node, observed) =>
192
+ statusFor(node).pipe(
193
+ Effect.flatMap((status) => applyStatus(observed, status)),
194
+ ),
195
+ }),
196
+ Update: lifecycle.update(
197
+ lifecycle.observedUpdate(statusFor, applyStatus),
198
+ ),
199
+ Destroy: lifecycle.remove(remove, {}),
200
+ }),
201
+ );
202
+ }),
203
+ },
204
+ ) {}
205
+
206
+ import { AwsCredentials } from "@tradedal/aws-client-core/config";