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
@@ -1,152 +0,0 @@
1
- import { Layer, Schema } from "effect";
2
- import {
3
- QueueAttributeMap,
4
- sqsOperations,
5
- sqsService,
6
- TagMap,
7
- } from "../../../client/generated/sqs.js";
8
- import type { AwsAttributeResourceConfiguration } from "../../../management/resourceConfiguration.js";
9
- import { awsResourcePolicyRegistration } from "../../../management/resourcePolicy.js";
10
- import {
11
- AWSQueueRequestSchema,
12
- AWSQueueResourceSchema,
13
- } from "./sqs/queue/index.js";
14
-
15
- // Generated from verified AWS definitions and reviewed lifecycle mappings. Do not edit.
16
- /**
17
- * The awsQueueResourceConfiguration configuration lets the policy validate
18
- * AWS::SQS::Queue declarations against Registry properties and native
19
- * requests against generated operation codecs. Its saved identity,
20
- * replacement rules, and attribute types govern runtime execution.
21
- */
22
- export const awsQueueResourceConfiguration = {
23
- schema: AWSQueueResourceSchema,
24
- propsSchema: AWSQueueRequestSchema,
25
- attributeSchema: QueueAttributeMap,
26
- tagMapSchema: TagMap,
27
- tagsSchema: Schema.requiredKey(AWSQueueRequestSchema.fields.Tags),
28
- service: sqsService,
29
- mapping: {
30
- typeName: "AWS::SQS::Queue",
31
- operations: {
32
- create: "CreateQueue",
33
- read: "GetQueueAttributes",
34
- update: "SetQueueAttributes",
35
- remove: "DeleteQueue",
36
- readTags: "ListQueueTags",
37
- tag: "TagQueue",
38
- untag: "UntagQueue",
39
- },
40
- identity: {
41
- property: "QueueUrl",
42
- parameter: "QueueUrl",
43
- },
44
- name: {
45
- property: "QueueName",
46
- parameter: "QueueName",
47
- fifoProperty: "FifoQueue",
48
- },
49
- tags: {
50
- property: "Tags",
51
- createParameter: "tags",
52
- updateParameter: "Tags",
53
- removeParameter: "TagKeys",
54
- response: "Tags",
55
- },
56
- attributes: {
57
- ContentBasedDeduplication: {
58
- attribute: "ContentBasedDeduplication",
59
- reset: false,
60
- },
61
- DeduplicationScope: {
62
- attribute: "DeduplicationScope",
63
- },
64
- DelaySeconds: {
65
- attribute: "DelaySeconds",
66
- reset: 0,
67
- },
68
- FifoQueue: {
69
- attribute: "FifoQueue",
70
- },
71
- FifoThroughputLimit: {
72
- attribute: "FifoThroughputLimit",
73
- },
74
- KmsDataKeyReusePeriodSeconds: {
75
- attribute: "KmsDataKeyReusePeriodSeconds",
76
- reset: 300,
77
- },
78
- KmsMasterKeyId: {
79
- attribute: "KmsMasterKeyId",
80
- },
81
- SqsManagedSseEnabled: {
82
- attribute: "SqsManagedSseEnabled",
83
- },
84
- MaximumMessageSize: {
85
- attribute: "MaximumMessageSize",
86
- reset: 1048576,
87
- },
88
- MessageRetentionPeriod: {
89
- attribute: "MessageRetentionPeriod",
90
- reset: 345600,
91
- },
92
- ReceiveMessageWaitTimeSeconds: {
93
- attribute: "ReceiveMessageWaitTimeSeconds",
94
- reset: 0,
95
- },
96
- RedriveAllowPolicy: {
97
- attribute: "RedriveAllowPolicy",
98
- reset: "",
99
- },
100
- RedrivePolicy: {
101
- attribute: "RedrivePolicy",
102
- reset: "",
103
- },
104
- VisibilityTimeout: {
105
- attribute: "VisibilityTimeout",
106
- reset: 30,
107
- },
108
- },
109
- outputAttributes: {
110
- Arn: "QueueArn",
111
- },
112
- missingErrors: [
113
- "QueueDoesNotExist",
114
- "AWS.SimpleQueueService.NonExistentQueue",
115
- ],
116
- readAttributeNames: ["All"],
117
- },
118
- encodings: {
119
- ContentBasedDeduplication: "json",
120
- DeduplicationScope: "string",
121
- DelaySeconds: "json",
122
- FifoQueue: "json",
123
- FifoThroughputLimit: "string",
124
- KmsDataKeyReusePeriodSeconds: "json",
125
- KmsMasterKeyId: "string",
126
- SqsManagedSseEnabled: "json",
127
- MaximumMessageSize: "json",
128
- MessageRetentionPeriod: "json",
129
- ReceiveMessageWaitTimeSeconds: "json",
130
- RedriveAllowPolicy: "json",
131
- RedrivePolicy: "json",
132
- VisibilityTimeout: "json",
133
- },
134
- createOnlyProperties: ["FifoQueue", "QueueName"],
135
- operations: {
136
- create: sqsOperations.CreateQueue,
137
- read: sqsOperations.GetQueueAttributes,
138
- update: sqsOperations.SetQueueAttributes,
139
- remove: sqsOperations.DeleteQueue,
140
- readTags: sqsOperations.ListQueueTags,
141
- tag: sqsOperations.TagQueue,
142
- untag: sqsOperations.UntagQueue,
143
- },
144
- } satisfies AwsAttributeResourceConfiguration;
145
- /**
146
- * The awsNativeResourceCommandLayer Layer supplies generated resource
147
- * commands to the application's shared runtime. Declaration and execution
148
- * share ResourceModel; the provider supplies the AWS client and digest.
149
- */
150
- export const awsNativeResourceCommandLayer = Layer.mergeAll(
151
- awsResourcePolicyRegistration(awsQueueResourceConfiguration),
152
- );
@@ -1,150 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import {
3
- annotateResourceSchema,
4
- ResourceEntity,
5
- ResourceReferenceSchema,
6
- ResourceSchemaAnnotationSchema,
7
- } from "../../../../core/resource/model.js";
8
- import { ResourceGraphBuilder } from "../../../../core/resource/resourceGraphBuilder.js";
9
- import { ResourceGraphStore } from "../../../../core/resource/resourceGraphStore.js";
10
- import { AWSRoleResourceTypeSchema } from "../generated/native/iam/role/index.js";
11
- import { PolicyStatement } from "./policyStatement.js";
12
-
13
- export { PolicyStatement } from "./policyStatement.js";
14
-
15
- type RolePrincipal = ResourceEntity<typeof AWSRoleResourceTypeSchema.Type>;
16
-
17
- /**
18
- * The roleGrantSchema annotation identifies a policy owned by one role.
19
- * A different principal requires a separate AWS policy identity.
20
- */
21
- export const roleGrantSchema = ResourceSchemaAnnotationSchema.make({
22
- provider: "aws",
23
- service: "iam",
24
- resource: "role-grant",
25
- operation: "create",
26
- stateSecretOutputKeys: [],
27
- primaryIdentifier: [
28
- "/properties/RoleId",
29
- "/properties/RoleName",
30
- "/properties/PolicyName",
31
- ],
32
- replacement: {
33
- order: "createBeforeDestroy",
34
- properties: [["Principal"]],
35
- },
36
- });
37
-
38
- const Principal = Schema.Struct({
39
- RoleName: Schema.NonEmptyString,
40
- RoleId: Schema.NonEmptyString,
41
- });
42
-
43
- /**
44
- * The RoleGrantOutputs schema retains the role ID as well as the AWS names
45
- * used to read and remove the policy. IAM allows a deleted role's name to be
46
- * reused.
47
- */
48
- export const RoleGrantOutputs = Schema.Struct({
49
- ...Principal.fields,
50
- PolicyName: Schema.NonEmptyString,
51
- });
52
-
53
- const Actions = PolicyStatement.fields.actions;
54
- const Resources = Schema.NonEmptyArray(Schema.NonEmptyString);
55
-
56
- const GrantStatement = PolicyStatement.pipe(
57
- Schema.encodeKeys({
58
- actions: "Actions",
59
- resources: "Resource",
60
- effect: "Effect",
61
- conditions: "Condition",
62
- }),
63
- );
64
-
65
- /**
66
- * The RoleGrantRequest schema validates the resolved principal and policy
67
- * fields before IAM receives the inline policy.
68
- */
69
- export const RoleGrantRequest = Schema.Struct({
70
- Actions,
71
- Principal,
72
- Resource: Schema.Union([Resources, Schema.NonEmptyString]),
73
- Effect: PolicyStatement.fields.effect,
74
- Condition: PolicyStatement.fields.conditions,
75
- });
76
-
77
- const RoleReference = ResourceReferenceSchema(AWSRoleResourceTypeSchema, {
78
- value: { RoleName: null, RoleId: null },
79
- outputs: [
80
- { source: ["RoleName"], target: ["RoleName"] },
81
- { source: ["RoleId"], target: ["RoleId"] },
82
- ],
83
- });
84
-
85
- const RoleGrantType = Schema.Struct({
86
- provider: Schema.Literal("aws"),
87
- service: Schema.Literal("iam"),
88
- resource: Schema.Literal("role-grant"),
89
- });
90
-
91
- const RoleGrantProps = annotateResourceSchema(
92
- RoleGrantRequest.mapFields((fields) => ({
93
- ...fields,
94
- Principal: RoleReference,
95
- Resource: PolicyStatement.fields.resources,
96
- })),
97
- roleGrantSchema,
98
- );
99
-
100
- /**
101
- * The Grant class identifies an IAM policy managed by the stack. Its
102
- * applyBefore method makes a consuming resource wait for that policy.
103
- */
104
- export class Grant extends ResourceEntity<typeof RoleGrantType.Type> {
105
- /**
106
- * The applyBefore method orders a consumer after the grant. Both
107
- * declarations must belong to the graph being built.
108
- */
109
- applyBefore(resource: ResourceEntity) {
110
- return Effect.flatMap(ResourceGraphStore, (graph) =>
111
- graph.addDependency(this.key, resource.key, {
112
- kind: "prerequisite",
113
- reason: "IAM grant",
114
- }),
115
- );
116
- }
117
- }
118
-
119
- /**
120
- * The RoleGrant function registers one named identity policy for a
121
- * role. The grant keeps its identity when the statement changes, and the
122
- * graph resolves the role's immutable ID before IAM receives the policy.
123
- */
124
- export const RoleGrant = Effect.fn("RoleGrant")(function* (
125
- logicalId: string,
126
- principal: RolePrincipal,
127
- statement: PolicyStatement,
128
- ) {
129
- const graph = yield* ResourceGraphBuilder;
130
-
131
- const desired = yield* Schema.encodeEffect(GrantStatement)(statement);
132
- const key = { logicalId };
133
-
134
- const props = yield* Schema.decodeUnknownEffect(RoleGrantProps)({
135
- ...desired,
136
- Principal: principal,
137
- });
138
-
139
- const declaration = yield* graph.resource(key);
140
- const entity = yield* declaration.registerEntity(RoleGrantType, {
141
- propsSchema: RoleGrantProps,
142
- requestSchema: RoleGrantRequest,
143
- outputsSchema: RoleGrantOutputs,
144
- props,
145
- });
146
-
147
- const grant: Grant = new Grant(entity);
148
-
149
- return grant;
150
- });
@@ -1,283 +0,0 @@
1
- import { Data, Effect, Layer, Match, Option, Schedule, Schema } from "effect";
2
- import { Digest } from "effect/crypto";
3
- import {
4
- type ResourceCommand,
5
- ResourceCommandResult,
6
- ResourceCommandUnsupported,
7
- ResourceObservation,
8
- } from "../../../../core/resource/lifecycle.js";
9
- import {
10
- ResourceModel,
11
- type ResourceNode,
12
- resourceModelLayer,
13
- } from "../../../../core/resource/model.js";
14
- import {
15
- ResourceCommandExecutionFailed,
16
- ResourceCommandStackName,
17
- } from "../../../../core/resource/resourceCommandPolicy.js";
18
- import { providerCommandPolicyTag } from "../../../resourceCommandPolicyLayer.js";
19
- import { makeIAMClient } from "../../client/generated/iam.js";
20
- import {
21
- RoleGrantOutputs,
22
- RoleGrantRequest,
23
- roleGrantSchema,
24
- } from "./grant.js";
25
- import { decodeIamPolicy, encodeIamPolicy } from "./policyDocument.js";
26
-
27
- class IamGrantConflict extends Data.TaggedError("IamGrantConflict")<{
28
- readonly message: string;
29
- }> {}
30
-
31
- const Identity = RoleGrantOutputs;
32
- type Identity = typeof Identity.Type;
33
- type GrantRequest = typeof RoleGrantRequest.Type;
34
-
35
- const PolicyOwner = Schema.Struct({
36
- Statement: Schema.Tuple([Schema.Struct({ Sid: Schema.String })]),
37
- });
38
-
39
- const sameDocument = Schema.toEquivalence(Schema.JsonObject);
40
-
41
- const policyDocument = (identity: Identity, request: GrantRequest) => {
42
- const statement = {
43
- Sid: identity.PolicyName,
44
- Effect: request.Effect ?? "Allow",
45
- Action: request.Actions,
46
- Resource: request.Resource,
47
- };
48
-
49
- const scoped = Option.match(Option.fromUndefinedOr(request.Condition), {
50
- onNone: () => statement,
51
- onSome: (Condition) => ({ ...statement, Condition }),
52
- });
53
-
54
- return { Version: "2012-10-17", Statement: [scoped] };
55
- };
56
-
57
- /**
58
- * The grantCommands Layer owns one inline policy per grant. It checks the
59
- * role's immutable ID and the policy's statement ID before changing or
60
- * deleting an existing policy. A retry addresses the same policy name.
61
- *
62
- * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (GetRole, GetRolePolicy, PutRolePolicy and DeleteRolePolicy)
63
- */
64
- export const grantCommands = Layer.effect(
65
- providerCommandPolicyTag(roleGrantSchema),
66
- Effect.gen(function* () {
67
- const iam = yield* makeIAMClient;
68
- const model = yield* ResourceModel;
69
- const digest = yield* Digest.Digest;
70
-
71
- const readRole = (RoleName: string) =>
72
- iam.getRole({ RoleName }).pipe(
73
- Effect.map(({ Role }) => Option.some(Role.RoleId)),
74
- Effect.catchTag("AwsServiceError", (error) =>
75
- Match.value(error.code).pipe(
76
- Match.when("NoSuchEntity", () =>
77
- Effect.succeed(Option.none<string>()),
78
- ),
79
- Match.orElse(() => Effect.fail(error)),
80
- ),
81
- ),
82
- );
83
-
84
- /**
85
- * The readPolicy operation confirms that the inline policy is owned by
86
- * the grant before a caller can overwrite it or revoke it.
87
- */
88
- const readPolicy = Effect.fn("IamGrant.readPolicy")(function* (
89
- identity: Identity,
90
- ) {
91
- const { PolicyName, RoleName } = identity;
92
- const role = yield* readRole(RoleName);
93
-
94
- const sameRole = Option.exists(role, (id) => id === identity.RoleId);
95
- const current = yield* iam.getRolePolicy({ RoleName, PolicyName }).pipe(
96
- Effect.flatMap(({ PolicyDocument }) => decodeIamPolicy(PolicyDocument)),
97
- Effect.asSome,
98
- Effect.catchTag("AwsServiceError", (error) =>
99
- Match.value(error.code).pipe(
100
- Match.when("NoSuchEntity", () =>
101
- Effect.succeed(Option.none<Schema.JsonObject>()),
102
- ),
103
- Match.orElse(() => Effect.fail(error)),
104
- ),
105
- ),
106
- Effect.when(Effect.succeed(sameRole)),
107
- Effect.map(Option.flatten),
108
- );
109
-
110
- const ownsStatement = Schema.is(PolicyOwner);
111
- const conflict = Option.exists(
112
- current,
113
- (doc) => !ownsStatement(doc) || doc.Statement[0].Sid !== PolicyName,
114
- );
115
-
116
- yield* Effect.fail(
117
- new IamGrantConflict({
118
- message: `IAM policy "${PolicyName}" belongs to another declaration on role "${RoleName}".`,
119
- }),
120
- ).pipe(Effect.when(Effect.succeed(conflict)));
121
-
122
- return current;
123
- });
124
-
125
- const identityFor = Effect.fn("IamGrant.identityFor")(function* (
126
- node: ResourceNode,
127
- request: GrantRequest,
128
- ) {
129
- const stack = yield* ResourceCommandStackName.pipe(
130
- Effect.flatMap(Effect.fromOption),
131
- );
132
-
133
- const seed = yield* Schema.encodeEffect(
134
- Schema.fromJsonString(Schema.Json),
135
- )([stack, node.key.logicalId, request.Principal.RoleId]);
136
-
137
- const hash = yield* digest.digestHex(
138
- Digest.sha256,
139
- new TextEncoder().encode(seed),
140
- );
141
-
142
- return { ...request.Principal, PolicyName: `Nomoss${hash}` };
143
- });
144
-
145
- const write = Effect.fn("IamGrant.write")(function* (
146
- node: ResourceNode,
147
- identity: Identity,
148
- request: GrantRequest,
149
- ) {
150
- const { RoleName, PolicyName, RoleId } = identity;
151
- const role = yield* readRole(RoleName);
152
-
153
- const sameRole = Option.exists(role, (id) => id === RoleId);
154
-
155
- yield* Effect.fail(
156
- new IamGrantConflict({
157
- message: `The saved IAM role identity for "${RoleName}" is unavailable.`,
158
- }),
159
- ).pipe(Effect.when(Effect.succeed(!sameRole)));
160
-
161
- const current = yield* readPolicy(identity);
162
- const desired = policyDocument(identity, request);
163
-
164
- const unchanged = Option.exists(current, (doc) =>
165
- sameDocument(doc, desired),
166
- );
167
-
168
- yield* encodeIamPolicy(desired).pipe(
169
- Effect.flatMap((PolicyDocument) =>
170
- iam.putRolePolicy({ RoleName, PolicyName, PolicyDocument }),
171
- ),
172
- Effect.when(Effect.succeed(!unchanged)),
173
- );
174
-
175
- yield* readPolicy(identity).pipe(
176
- Effect.repeat({
177
- while: (policy) =>
178
- !Option.exists(policy, (doc) => sameDocument(doc, desired)),
179
- schedule: Schedule.spaced("1 second"),
180
- }),
181
- Effect.timeout("30 seconds"),
182
- );
183
-
184
- return yield* model.withOutputs(node, identity);
185
- });
186
-
187
- const create = Effect.fn("IamGrant.create")(function* (node: ResourceNode) {
188
- const request = yield* model.decodeProps(node, RoleGrantRequest);
189
- const identity = yield* identityFor(node, request);
190
- const applied = yield* write(node, identity, request);
191
-
192
- return ResourceCommandResult.Created({ node: applied });
193
- });
194
-
195
- const update = Effect.fn("IamGrant.update")(function* (
196
- node: ResourceNode,
197
- current: ResourceNode,
198
- ) {
199
- const request = yield* model.decodeProps(node, RoleGrantRequest);
200
- const identity = yield* model.decodeOutputs(current, Identity);
201
-
202
- const principalChanged = request.Principal.RoleId !== identity.RoleId;
203
-
204
- yield* Effect.fail(
205
- new IamGrantConflict({
206
- message:
207
- "The grant's principal has changed. Plan a replacement before applying the grant to another IAM role.",
208
- }),
209
- ).pipe(Effect.when(Effect.succeed(principalChanged)));
210
-
211
- const applied = yield* write(node, identity, request);
212
-
213
- return ResourceCommandResult.Updated({ node: applied });
214
- });
215
-
216
- const read = Effect.fn("IamGrant.read")(function* (node: ResourceNode) {
217
- const identity = yield* model.decodeOutputs(node, Identity);
218
- const document = yield* readPolicy(identity);
219
-
220
- const observation = Option.match(document, {
221
- onNone: () => ResourceObservation.Missing({ node }),
222
- onSome: (observed) => ResourceObservation.Present({ node, observed }),
223
- });
224
-
225
- return ResourceCommandResult.Observed({ observation });
226
- });
227
-
228
- const destroy = Effect.fn("IamGrant.destroy")(function* (
229
- node: ResourceNode,
230
- ) {
231
- const identity = yield* model.decodeOutputs(node, Identity);
232
- const { RoleName, PolicyName } = identity;
233
- const document = yield* readPolicy(identity);
234
-
235
- yield* iam.deleteRolePolicy({ RoleName, PolicyName }).pipe(
236
- Effect.catchTag("AwsServiceError", (error) =>
237
- Match.value(error.code).pipe(
238
- Match.when("NoSuchEntity", () => Effect.void),
239
- Match.orElse(() => Effect.fail(error)),
240
- ),
241
- ),
242
- Effect.when(Effect.succeed(Option.isSome(document))),
243
- );
244
-
245
- yield* readPolicy(identity).pipe(
246
- Effect.repeat({
247
- while: Option.isSome,
248
- schedule: Schedule.spaced("1 second"),
249
- }),
250
- Effect.timeout("30 seconds"),
251
- );
252
-
253
- return ResourceCommandResult.Destroyed({ node });
254
- });
255
-
256
- const execute = Effect.fn("IamGrant.execute")(
257
- (command: ResourceCommand) => {
258
- const action = Match.value(command).pipe(
259
- Match.tag("Apply", ({ decision }) => decision),
260
- Match.orElse((direct) => direct),
261
- );
262
-
263
- return Match.value(action).pipe(
264
- Match.tag("Create", ({ node }) => create(node)),
265
- Match.when(
266
- { _tag: "Update", current: Match.defined },
267
- ({ node, current }) => update(node, current),
268
- ),
269
- Match.tag("Read", ({ node }) => read(node)),
270
- Match.tag("Delete", "Destroy", ({ node }) => destroy(node)),
271
- Match.orElse(() =>
272
- Effect.fail(new ResourceCommandUnsupported({ command })),
273
- ),
274
- Effect.mapError(
275
- (cause) => new ResourceCommandExecutionFailed({ command, cause }),
276
- ),
277
- );
278
- },
279
- );
280
-
281
- return { execute };
282
- }),
283
- ).pipe(Layer.provide(resourceModelLayer));
@@ -1,30 +0,0 @@
1
- import { Effect, Match, Schema } from "effect";
2
-
3
- const PolicyJson = Schema.fromJsonString(Schema.JsonObject);
4
-
5
- /**
6
- * The encodeIamPolicy function validates a policy document and returns the
7
- * JSON string IAM operations accept. Both embedded and standalone policies
8
- * use the same encoding.
9
- *
10
- * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (policyDocumentType)
11
- */
12
- export const encodeIamPolicy = (document: Schema.JsonObject | string) =>
13
- Match.value(document).pipe(
14
- Match.when(Match.string, (text) => Schema.decodeEffect(PolicyJson)(text)),
15
- Match.orElse((json) => Effect.succeed(json)),
16
- Effect.flatMap(Schema.encodeEffect(PolicyJson)),
17
- );
18
-
19
- /**
20
- * The decodeIamPolicy function reads the policy document returned by IAM.
21
- * GetRolePolicy can return a URL-encoded JSON document.
22
- *
23
- * @see ../../../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (GetRolePolicyResponse)
24
- */
25
- export const decodeIamPolicy = Schema.decodeEffect(
26
- Schema.Union([
27
- PolicyJson,
28
- Schema.StringFromUriComponent.pipe(Schema.decodeTo(PolicyJson)),
29
- ]),
30
- );
@@ -1,59 +0,0 @@
1
- import { Schema } from "effect";
2
- import { ResourceReferenceSchema } from "../../../../core/resource/model.js";
3
- import { AWSManagedPolicyResourceTypeSchema } from "../generated/native/iam/managedpolicy/index.js";
4
- import { AWSRoleResourceTypeSchema } from "../generated/native/iam/role/index.js";
5
- import { AWSKeyResourceTypeSchema } from "../generated/native/kms/key/index.js";
6
- import { AWSFunctionResourceTypeSchema } from "../generated/native/lambda/function/index.js";
7
- import { AWSBucketResourceTypeSchema } from "../generated/native/s3/bucket/index.js";
8
- import { AWSTopicResourceTypeSchema } from "../generated/native/sns/topic/index.js";
9
- import { AWSQueueResourceTypeSchema } from "../generated/native/sqs/queue/index.js";
10
- import { AWSStateMachineResourceTypeSchema } from "../generated/native/stepfunctions/statemachine/index.js";
11
-
12
- // Policy resource references use each Registry definition's read-only ARN
13
- // property. The shared reference codec records the entity dependency and
14
- // resolves its applied value under docs/application/resource-graph.md,
15
- // "Relationships and request values". SNS and managed IAM policies declare
16
- // different ARN property names, so each has its own mapping.
17
- const ResourceArn = ResourceReferenceSchema(
18
- Schema.Union([
19
- AWSRoleResourceTypeSchema,
20
- AWSKeyResourceTypeSchema,
21
- AWSFunctionResourceTypeSchema,
22
- AWSBucketResourceTypeSchema,
23
- AWSQueueResourceTypeSchema,
24
- AWSStateMachineResourceTypeSchema,
25
- ]),
26
- { value: null, outputs: [{ source: ["Arn"], target: [] }] },
27
- );
28
-
29
- const TopicArn = ResourceReferenceSchema(AWSTopicResourceTypeSchema, {
30
- value: null,
31
- outputs: [{ source: ["TopicArn"], target: [] }],
32
- });
33
-
34
- const PolicyArn = ResourceReferenceSchema(AWSManagedPolicyResourceTypeSchema, {
35
- value: null,
36
- outputs: [{ source: ["PolicyArn"], target: [] }],
37
- });
38
-
39
- /**
40
- * The PolicyStatement schema validates an identity policy statement before
41
- * registration. Resource scope accepts ARN strings, wildcard patterns, or
42
- * declared queues, buckets, topics, keys, functions, state machines, roles,
43
- * and managed policies. Entity references resolve to their saved ARNs during
44
- * apply. Actions and conditions remain the application's decisions.
45
- *
46
- * @see ../../../../../docs/application/resource-graph.md (Relationships and request values)
47
- */
48
- export const PolicyStatement = Schema.Struct({
49
- actions: Schema.NonEmptyArray(Schema.NonEmptyString),
50
- resources: Schema.NonEmptyArray(
51
- Schema.Union([Schema.NonEmptyString, ResourceArn, TopicArn, PolicyArn]),
52
- ),
53
- effect: Schema.optionalKey(Schema.Literals(["Allow", "Deny"])),
54
- conditions: Schema.optionalKey(
55
- Schema.Record(Schema.NonEmptyString, Schema.JsonObject),
56
- ),
57
- });
58
-
59
- export type PolicyStatement = typeof PolicyStatement.Type;