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.
- package/CHANGELOG.md +27 -0
- package/README.md +5 -15
- package/ROADMAP.md +2 -0
- package/docs/README.md +1 -1
- package/docs/application/aws-resource-coverage.md +26 -0
- package/docs/application/aws-resource-lifecycle-management.md +13 -23
- package/docs/application/cli-workflow.md +1 -1
- package/docs/application/engine-design.md +2 -2
- package/docs/application/generation-architecture.md +10 -45
- package/docs/application/resource-command-policy-stage.md +2 -2
- package/docs/application/resource-graph.md +1 -1
- package/docs/application/resource-lifecycle-tracker.md +1 -9
- package/docs/application/resource-mapping.md +4 -9
- package/docs/application/resource-operations.md +4 -2
- package/docs/application/tracing.md +2 -6
- package/docs/development/code-documentation.md +2 -0
- package/docs/development/effect-native-development.md +44 -0
- package/docs/development/linting.md +1 -1
- package/docs/development/review-code.md +22 -6
- package/docs/development/review-remediation-spec.md +28 -37
- package/docs/development/spec-writing.md +1 -1
- package/docs/development/testing.md +23 -9
- package/docs/operations/observability-sop.md +11 -17
- package/docs/operations/releasing.md +3 -1
- package/examples/README.md +3 -26
- package/examples/commands.ts +2 -36
- package/examples/queue/application.ts +8 -2
- package/examples/state-machine/application.ts +3 -1
- package/package.json +40 -46
- package/providers/aws/README.md +21 -0
- package/providers/aws/awsEnvironment.ts +114 -0
- package/providers/aws/generated/managementRegistry.ts +136 -0
- package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
- package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
- package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
- package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
- package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
- package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
- package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
- package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
- package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
- package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
- package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
- package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
- package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
- package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
- package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
- package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
- package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
- package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
- package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
- package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
- package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
- package/providers/aws/management/mappings/iam/group.ts +63 -0
- package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
- package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
- package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
- package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
- package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
- package/providers/aws/management/mappings/iam/role.ts +74 -0
- package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
- package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
- package/providers/aws/management/mappings/iam/user.ts +61 -0
- package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
- package/providers/aws/management/operations/iam/accessKey.ts +206 -0
- package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
- package/providers/aws/management/operations/iam/policy.ts +476 -0
- package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
- package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
- package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
- package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
- package/providers/aws/management/resourceAssociations.ts +168 -0
- package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
- package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
- package/providers/aws/management/resourceManagementModule.ts +31 -0
- package/providers/aws/management/resourceManagementRegistry.ts +62 -0
- package/providers/aws/management/resourceMapping.ts +84 -0
- package/providers/aws/management/resourceOperation.ts +134 -0
- package/providers/aws/management/resourceTagOperations.ts +108 -0
- package/providers/aws/management/resourceTiming.ts +4 -0
- package/providers/aws/runtime.ts +52 -0
- package/src/core/resource/resourceCommandPolicy.ts +20 -0
- package/src/core/resource/resourceLifecycle.ts +644 -0
- package/src/core/resource/resourceStabilization.ts +120 -0
- package/src/core/resource/resourceVersions.ts +102 -0
- package/src/core/stack/planner.ts +9 -0
- package/src/core/stack/resourceStackLifecycle.ts +36 -3
- package/src/core/state/resourceState.ts +6 -4
- package/src/core/state/stateStore.ts +57 -10
- package/src/providers/file/resourcePolicy.ts +13 -12
- package/src/providers/providerRuntimeLayer.ts +5 -2
- package/src/providers/resourceCommandPolicyLayer.ts +117 -37
- package/src/providers/stripe/management/resourcePolicy.ts +22 -11
- package/examples/http-echo/application.ts +0 -87
- package/src/providers/aws/client/awsClient.ts +0 -418
- package/src/providers/aws/client/awsClientConfig.ts +0 -133
- package/src/providers/aws/client/awsClientModel.ts +0 -119
- package/src/providers/aws/client/awsHttpOperation.ts +0 -153
- package/src/providers/aws/client/awsQueryOperation.ts +0 -149
- package/src/providers/aws/client/awsRequestSigner.ts +0 -115
- package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
- package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
- package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
- package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
- package/src/providers/aws/client/generated/iam.ts +0 -10892
- package/src/providers/aws/client/generated/lambda.ts +0 -5403
- package/src/providers/aws/client/generated/sqs.ts +0 -3769
- package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
- package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
- package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
- package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
- package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
- package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
- package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
- package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
- package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
- package/src/providers/aws/cloudControl/client.ts +0 -69
- package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
- package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
- package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
- package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
- package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
- package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
- package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
- package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
- package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
- package/src/providers/aws/cloudControl/runtime.ts +0 -127
- package/src/providers/aws/management/resourceMapping.ts +0 -343
- package/src/providers/aws/management/resourceOperation.ts +0 -57
- package/src/providers/aws/management/resourcePolicy.ts +0 -549
- package/src/providers/aws/management/resourceRegistration.ts +0 -294
- package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
- package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
- package/src/providers/aws/resources/iam/grant.ts +0 -150
- package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
- package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
- package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
- package/src/providers/aws/resources/iam/role.ts +0 -426
- package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
- package/src/providers/aws/resources/lambda/function.ts +0 -403
- package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
- package/src/providers/aws/resources/lambda/permission.ts +0 -363
- package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
- package/src/providers/aws/runtime.ts +0 -70
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Array as Arr,
|
|
3
|
-
Context,
|
|
4
|
-
Effect,
|
|
5
|
-
Layer,
|
|
6
|
-
Match,
|
|
7
|
-
Option,
|
|
8
|
-
Schedule,
|
|
9
|
-
Schema,
|
|
10
|
-
} from "effect";
|
|
11
|
-
import { Digest } from "effect/crypto";
|
|
12
|
-
import {
|
|
13
|
-
type ResourceCommand,
|
|
14
|
-
ResourceCommandResult,
|
|
15
|
-
ResourceCommandUnsupported,
|
|
16
|
-
ResourceObservation,
|
|
17
|
-
} from "../../../../core/resource/lifecycle.js";
|
|
18
|
-
import {
|
|
19
|
-
annotateResourceSchema,
|
|
20
|
-
ResourceModel,
|
|
21
|
-
type ResourceNode,
|
|
22
|
-
ResourceReferenceSchema,
|
|
23
|
-
resourceModelLayer,
|
|
24
|
-
} from "../../../../core/resource/model.js";
|
|
25
|
-
import {
|
|
26
|
-
ResourceCommandExecutionFailed,
|
|
27
|
-
ResourceCommandStackName,
|
|
28
|
-
} from "../../../../core/resource/resourceCommandPolicy.js";
|
|
29
|
-
import { ResourceGraphBuilder } from "../../../../core/resource/resourceGraphBuilder.js";
|
|
30
|
-
import { providerCommandPolicyTag } from "../../../resourceCommandPolicyLayer.js";
|
|
31
|
-
import { makeLambdaClient } from "../../client/generated/lambda.js";
|
|
32
|
-
import {
|
|
33
|
-
type AWSRouteResource,
|
|
34
|
-
AWSRouteResourceTypeSchema,
|
|
35
|
-
} from "../generated/native/apigatewayv2/route/index.js";
|
|
36
|
-
import type { AWSFunctionResource } from "../generated/native/lambda/function/index.js";
|
|
37
|
-
import {
|
|
38
|
-
AWSPermissionOutputsSchema,
|
|
39
|
-
AWSPermissionPropsSchema,
|
|
40
|
-
AWSPermissionRequestSchema,
|
|
41
|
-
AWSPermissionResourceSchema,
|
|
42
|
-
} from "../generated/native/lambda/permission/index.js";
|
|
43
|
-
|
|
44
|
-
/** The identity schema requires the saved function name and statement ID before reading or removing a permission. */
|
|
45
|
-
const identity = Schema.Struct({
|
|
46
|
-
FunctionName: AWSPermissionOutputsSchema.fields.FunctionName,
|
|
47
|
-
Id: Schema.requiredKey(AWSPermissionOutputsSchema.fields.Id),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const statement = Schema.Struct({ Sid: Schema.String });
|
|
51
|
-
/** The policy schema validates the statement IDs that establish whether Nomoss still owns a Lambda permission. */
|
|
52
|
-
const policy = Schema.fromJsonString(
|
|
53
|
-
Schema.Struct({ Statement: Schema.Array(statement) }),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const httpMethod = Schema.Literals([
|
|
57
|
-
"GET",
|
|
58
|
-
"HEAD",
|
|
59
|
-
"POST",
|
|
60
|
-
"PUT",
|
|
61
|
-
"PATCH",
|
|
62
|
-
"DELETE",
|
|
63
|
-
"OPTIONS",
|
|
64
|
-
"CONNECT",
|
|
65
|
-
"TRACE",
|
|
66
|
-
]);
|
|
67
|
-
const literalPath = Schema.String.check(Schema.isPattern(/^\/[^{}*?\s]*$/));
|
|
68
|
-
const httpRouteKey = Schema.TemplateLiteralParser([
|
|
69
|
-
httpMethod,
|
|
70
|
-
" ",
|
|
71
|
-
literalPath,
|
|
72
|
-
]);
|
|
73
|
-
|
|
74
|
-
const lambdaArn = Schema.TemplateLiteralParser([
|
|
75
|
-
"arn:",
|
|
76
|
-
Schema.String.check(Schema.isPattern(/^aws[a-z0-9-]*$/)),
|
|
77
|
-
":lambda:",
|
|
78
|
-
Schema.String.check(Schema.isPattern(/^[a-z0-9-]+$/)),
|
|
79
|
-
":",
|
|
80
|
-
Schema.String.check(Schema.isPattern(/^\d{12}$/)),
|
|
81
|
-
":function:",
|
|
82
|
-
Schema.NonEmptyString,
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
const routePermissionSchema = {
|
|
86
|
-
...AWSPermissionResourceSchema,
|
|
87
|
-
resource: "route-invocation-permission",
|
|
88
|
-
replacement: {
|
|
89
|
-
order: "createBeforeDestroy",
|
|
90
|
-
properties: [["FunctionName"], ["ApiId"], ["Method"], ["Path"]],
|
|
91
|
-
},
|
|
92
|
-
} as const;
|
|
93
|
-
|
|
94
|
-
const routePermissionRequest = Schema.Struct({
|
|
95
|
-
FunctionName: AWSPermissionRequestSchema.fields.FunctionName,
|
|
96
|
-
ApiId: Schema.String.check(Schema.isPattern(/^[a-z0-9]+$/)),
|
|
97
|
-
Method: httpMethod,
|
|
98
|
-
Path: literalPath,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const routePermissionProps = annotateResourceSchema(
|
|
102
|
-
routePermissionRequest.mapFields((fields) => ({
|
|
103
|
-
...fields,
|
|
104
|
-
FunctionName: AWSPermissionPropsSchema.fields.FunctionName,
|
|
105
|
-
ApiId: ResourceReferenceSchema(AWSRouteResourceTypeSchema, {
|
|
106
|
-
value: null,
|
|
107
|
-
outputs: [{ source: ["ApiId"], target: [] }],
|
|
108
|
-
}),
|
|
109
|
-
})),
|
|
110
|
-
routePermissionSchema,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The routeInvocationPermission function declares a Lambda policy statement
|
|
115
|
-
* for one HTTP method and literal path across the API's stages. The route
|
|
116
|
-
* supplies its API ID after deployment, so a route change can replace the
|
|
117
|
-
* statement without affecting permissions for other routes.
|
|
118
|
-
* The function and API must belong to the same account and region. Route
|
|
119
|
-
* keys with parameters, wildcards, ANY, or $default fail schema validation.
|
|
120
|
-
*
|
|
121
|
-
* @see ../../../../../docs/application/resource-graph.md (Relationships and request values)
|
|
122
|
-
* @see ../../../../../refs/aws-api-models/models/apigatewayv2/service/2018-11-29/apigatewayv2-2018-11-29.json (CreateRouteRequest)
|
|
123
|
-
* @see ../../../../../../command-options-fund/refs/effect/packages/effect/src/Schema.ts (TemplateLiteralParser)
|
|
124
|
-
*/
|
|
125
|
-
export const routeInvocationPermission = Effect.fn("Lambda.grantInvokeRoute")(
|
|
126
|
-
function* (fn: AWSFunctionResource<unknown>, route: AWSRouteResource) {
|
|
127
|
-
const [Method, , Path] = yield* Schema.decodeUnknownEffect(httpRouteKey)(
|
|
128
|
-
route.props.RouteKey,
|
|
129
|
-
);
|
|
130
|
-
const graph = yield* ResourceGraphBuilder;
|
|
131
|
-
const permission = yield* graph.resource({
|
|
132
|
-
logicalId: `${fn.key.logicalId}/InvokeRoute/${encodeURIComponent(route.key.logicalId)}`,
|
|
133
|
-
});
|
|
134
|
-
const props = yield* Schema.decodeEffect(routePermissionProps)({
|
|
135
|
-
FunctionName: fn,
|
|
136
|
-
ApiId: route,
|
|
137
|
-
Method,
|
|
138
|
-
Path,
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
yield* permission.register({
|
|
142
|
-
propsSchema: routePermissionProps,
|
|
143
|
-
requestSchema: routePermissionRequest,
|
|
144
|
-
outputsSchema: AWSPermissionOutputsSchema,
|
|
145
|
-
props,
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const isMissing = (error: { readonly _tag: string }) =>
|
|
151
|
-
error._tag === "AwsServiceError" &&
|
|
152
|
-
"code" in error &&
|
|
153
|
-
error.code === "ResourceNotFoundException";
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* The permissionCommands Layer manages individual statements in a function's
|
|
157
|
-
* policy. Lambda reads the entire policy, so the lifecycle checks the saved
|
|
158
|
-
* statement ID before it reports presence or completes removal.
|
|
159
|
-
*
|
|
160
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (AddPermission, GetPolicy, RemovePermission)
|
|
161
|
-
* @see ../../../../../../command-options-fund/refs/effect/packages/effect/src/Layer.ts (effectContext)
|
|
162
|
-
*/
|
|
163
|
-
export const permissionCommands = Layer.effectContext(
|
|
164
|
-
Effect.gen(function* () {
|
|
165
|
-
const model = yield* ResourceModel;
|
|
166
|
-
const lambda = yield* makeLambdaClient;
|
|
167
|
-
const digest = yield* Digest.Digest;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The readStatement function confirms presence using the statement ID.
|
|
171
|
-
* A missing policy counts as absence. An invalid policy fails the read.
|
|
172
|
-
*
|
|
173
|
-
* @see ../../../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (transposeOption)
|
|
174
|
-
*/
|
|
175
|
-
const readStatement = Effect.fn("LambdaPermission.readStatement")(
|
|
176
|
-
function* (permission: typeof identity.Type) {
|
|
177
|
-
const input = { FunctionName: permission.FunctionName };
|
|
178
|
-
|
|
179
|
-
const response = yield* lambda.getPolicy(input).pipe(
|
|
180
|
-
Effect.asSome,
|
|
181
|
-
Effect.catchIf(isMissing, () => Effect.succeedNone),
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
const encoded = Option.flatMap(response, ({ Policy }) =>
|
|
185
|
-
Option.fromUndefinedOr(Policy),
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
const parsed = yield* encoded.pipe(
|
|
189
|
-
Option.map(Schema.decodeEffect(policy)),
|
|
190
|
-
Effect.transposeOption,
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
return Option.exists(parsed, (document) =>
|
|
194
|
-
Arr.some(document.Statement, ({ Sid }) => Sid === permission.Id),
|
|
195
|
-
);
|
|
196
|
-
},
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
/** The read function reports whether the saved statement exists; validation and provider failures remain failures of the read. */
|
|
200
|
-
const read = Effect.fn("LambdaPermission.read")(function* (
|
|
201
|
-
node: ResourceNode,
|
|
202
|
-
) {
|
|
203
|
-
const permission = yield* model.decodeOutputs(node, identity);
|
|
204
|
-
|
|
205
|
-
const exists = yield* readStatement(permission);
|
|
206
|
-
|
|
207
|
-
const observation = Match.value(exists).pipe(
|
|
208
|
-
Match.when(true, () =>
|
|
209
|
-
ResourceObservation.Present({ node, observed: permission }),
|
|
210
|
-
),
|
|
211
|
-
Match.orElse(() => ResourceObservation.Missing({ node })),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const result: ResourceCommandResult = ResourceCommandResult.Observed({
|
|
215
|
-
observation,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
return result;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The create function derives the statement ID from the stack, logical
|
|
223
|
-
* ID, and resolved properties. A retry can find the same statement, and a
|
|
224
|
-
* replacement grant can coexist with the one it supersedes.
|
|
225
|
-
*/
|
|
226
|
-
const create = Effect.fn("LambdaPermission.create")(function* (
|
|
227
|
-
node: ResourceNode,
|
|
228
|
-
) {
|
|
229
|
-
const properties = yield* Match.value(node.schema.resource).pipe(
|
|
230
|
-
Match.when(routePermissionSchema.resource, () =>
|
|
231
|
-
Effect.gen(function* () {
|
|
232
|
-
const { FunctionName, ApiId, Method, Path } =
|
|
233
|
-
yield* model.decodeProps(node, routePermissionRequest);
|
|
234
|
-
|
|
235
|
-
// The route invocation permission uses the Lambda ARN's partition,
|
|
236
|
-
// account, and region with the API ID supplied by the route. The
|
|
237
|
-
// stage wildcard covers every stage for this method and path.
|
|
238
|
-
// See refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json,
|
|
239
|
-
// AddPermissionRequest.SourceArn.
|
|
240
|
-
const [, partition, , region, , account] =
|
|
241
|
-
yield* Schema.decodeUnknownEffect(lambdaArn)(FunctionName);
|
|
242
|
-
|
|
243
|
-
return yield* Schema.decodeEffect(AWSPermissionRequestSchema)({
|
|
244
|
-
Action: "lambda:InvokeFunction",
|
|
245
|
-
FunctionName,
|
|
246
|
-
Principal: "apigateway.amazonaws.com",
|
|
247
|
-
SourceArn: `arn:${partition}:execute-api:${region}:${account}:${ApiId}/*/${Method}${Path}`,
|
|
248
|
-
});
|
|
249
|
-
}),
|
|
250
|
-
),
|
|
251
|
-
Match.orElse(() => model.decodeProps(node, AWSPermissionRequestSchema)),
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
const stack = yield* ResourceCommandStackName.pipe(
|
|
255
|
-
Effect.flatMap(Effect.fromOption),
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const statementIdentity = [stack, node.key.logicalId, properties];
|
|
259
|
-
|
|
260
|
-
const seed = yield* Schema.encodeEffect(
|
|
261
|
-
Schema.fromJsonString(Schema.Json),
|
|
262
|
-
)(statementIdentity);
|
|
263
|
-
|
|
264
|
-
const hash = yield* digest.digestHex(
|
|
265
|
-
Digest.sha256,
|
|
266
|
-
new TextEncoder().encode(seed),
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
const permission = {
|
|
270
|
-
FunctionName: properties.FunctionName,
|
|
271
|
-
Id: `nomoss-${hash}`,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const exists = yield* readStatement(permission);
|
|
275
|
-
|
|
276
|
-
const input = { ...properties, StatementId: permission.Id };
|
|
277
|
-
|
|
278
|
-
yield* lambda
|
|
279
|
-
.addPermission(input)
|
|
280
|
-
.pipe(Effect.when(Effect.succeed(!exists)));
|
|
281
|
-
|
|
282
|
-
yield* readStatement(permission).pipe(
|
|
283
|
-
Effect.repeat({
|
|
284
|
-
while: (present) => !present,
|
|
285
|
-
schedule: Schedule.spaced("1 second"),
|
|
286
|
-
}),
|
|
287
|
-
Effect.timeout("30 seconds"),
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
const applied = yield* model.withOutputs(node, permission);
|
|
291
|
-
|
|
292
|
-
const result: ResourceCommandResult = ResourceCommandResult.Created({
|
|
293
|
-
node: applied,
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
return result;
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* The destroy function completes when GetPolicy confirms the statement
|
|
301
|
-
* is absent. A failed confirmation leaves the saved identity available
|
|
302
|
-
* for a retry.
|
|
303
|
-
*
|
|
304
|
-
* @see ../../../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (repeat and timeout)
|
|
305
|
-
*/
|
|
306
|
-
const destroy = Effect.fn("LambdaPermission.destroy")(function* (
|
|
307
|
-
node: ResourceNode,
|
|
308
|
-
) {
|
|
309
|
-
const permission = yield* model.decodeOutputs(node, identity);
|
|
310
|
-
|
|
311
|
-
const input = {
|
|
312
|
-
FunctionName: permission.FunctionName,
|
|
313
|
-
StatementId: permission.Id,
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
yield* lambda
|
|
317
|
-
.removePermission(input)
|
|
318
|
-
.pipe(Effect.catchIf(isMissing, () => Effect.void));
|
|
319
|
-
|
|
320
|
-
yield* readStatement(permission).pipe(
|
|
321
|
-
Effect.repeat({
|
|
322
|
-
while: (present) => present,
|
|
323
|
-
schedule: Schedule.spaced("1 second"),
|
|
324
|
-
}),
|
|
325
|
-
Effect.timeout("30 seconds"),
|
|
326
|
-
);
|
|
327
|
-
|
|
328
|
-
const result: ResourceCommandResult = ResourceCommandResult.Destroyed({
|
|
329
|
-
node,
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
return result;
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
/** The execute service method applies supported permission commands and returns typed failures for other commands or failed provider requests. */
|
|
336
|
-
const execute = Effect.fn("LambdaPermission.execute")(
|
|
337
|
-
(command: ResourceCommand) => {
|
|
338
|
-
const action = Match.value(command).pipe(
|
|
339
|
-
Match.tag("Apply", ({ decision }) => decision),
|
|
340
|
-
Match.orElse((command) => command),
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
return Match.value(action).pipe(
|
|
344
|
-
Match.tag("Read", ({ node }) => read(node)),
|
|
345
|
-
Match.tag("Create", ({ node }) => create(node)),
|
|
346
|
-
Match.tag("Destroy", "Delete", ({ node }) => destroy(node)),
|
|
347
|
-
Match.orElse(() =>
|
|
348
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
349
|
-
),
|
|
350
|
-
Effect.mapError(
|
|
351
|
-
(cause) => new ResourceCommandExecutionFailed({ command, cause }),
|
|
352
|
-
),
|
|
353
|
-
);
|
|
354
|
-
},
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
return Context.make(providerCommandPolicyTag(AWSPermissionResourceSchema), {
|
|
358
|
-
execute,
|
|
359
|
-
}).pipe(
|
|
360
|
-
Context.add(providerCommandPolicyTag(routePermissionSchema), { execute }),
|
|
361
|
-
);
|
|
362
|
-
}),
|
|
363
|
-
).pipe(Layer.provide(resourceModelLayer));
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
createStateMachineOperation,
|
|
4
|
-
deleteStateMachineOperation,
|
|
5
|
-
describeStateMachineOperation,
|
|
6
|
-
stepFunctionsService,
|
|
7
|
-
updateStateMachineOperation,
|
|
8
|
-
} from "../../client/generated/stepFunctions.js";
|
|
9
|
-
import {
|
|
10
|
-
resourceRequest,
|
|
11
|
-
resourceResponse,
|
|
12
|
-
} from "../../management/resourceOperation.js";
|
|
13
|
-
import { awsResourceRegistration } from "../../management/resourceRegistration.js";
|
|
14
|
-
import {
|
|
15
|
-
AWSStateMachineOutputsSchema,
|
|
16
|
-
AWSStateMachineRequestSchema,
|
|
17
|
-
AWSStateMachineResourceSchema,
|
|
18
|
-
} from "../generated/native/stepfunctions/statemachine/index.js";
|
|
19
|
-
|
|
20
|
-
const fields = AWSStateMachineRequestSchema.fields;
|
|
21
|
-
const outputs = AWSStateMachineOutputsSchema.fields;
|
|
22
|
-
|
|
23
|
-
// The application sets StateMachineName when it declares the workflow. After
|
|
24
|
-
// apply, it can read the name AWS reports through the Name output. Both use
|
|
25
|
-
// the same field in the AWS API.
|
|
26
|
-
const keys = {
|
|
27
|
-
Arn: "stateMachineArn",
|
|
28
|
-
Definition: "definition",
|
|
29
|
-
Name: "name",
|
|
30
|
-
RoleArn: "roleArn",
|
|
31
|
-
StateMachineName: "name",
|
|
32
|
-
StateMachineRevisionId: "revisionId",
|
|
33
|
-
StateMachineType: "type",
|
|
34
|
-
} as const;
|
|
35
|
-
|
|
36
|
-
const identity = Schema.Struct({
|
|
37
|
-
Arn: Schema.requiredKey(outputs.Arn),
|
|
38
|
-
}).pipe(Schema.encodeKeys(keys));
|
|
39
|
-
|
|
40
|
-
// Step Functions accepts and returns the workflow definition as JSON text.
|
|
41
|
-
// Schema.fromJsonString converts the declared object to text for AWS and
|
|
42
|
-
// parses the returned text so Nomoss can compare the definition with the
|
|
43
|
-
// declaration before saving an update.
|
|
44
|
-
//
|
|
45
|
-
// See refs/effect-website/apps/web/src/content/docs/v4/schema/transformations.mdx#json-strings
|
|
46
|
-
// in the command-options-fund reference checkout.
|
|
47
|
-
const settings = {
|
|
48
|
-
Definition: Schema.fromJsonString(Schema.requiredKey(fields.Definition)),
|
|
49
|
-
RoleArn: fields.RoleArn,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const createInput = Schema.Struct({
|
|
53
|
-
...settings,
|
|
54
|
-
StateMachineName: Schema.requiredKey(fields.StateMachineName),
|
|
55
|
-
StateMachineType: fields.StateMachineType,
|
|
56
|
-
}).pipe(Schema.encodeKeys(keys));
|
|
57
|
-
|
|
58
|
-
const observed = Schema.Struct({
|
|
59
|
-
...settings,
|
|
60
|
-
...AWSStateMachineOutputsSchema.fields,
|
|
61
|
-
Arn: Schema.requiredKey(outputs.Arn),
|
|
62
|
-
Name: Schema.requiredKey(outputs.Name),
|
|
63
|
-
StateMachineType: fields.StateMachineType,
|
|
64
|
-
}).pipe(Schema.encodeKeys(keys));
|
|
65
|
-
|
|
66
|
-
const changes = Schema.Struct({
|
|
67
|
-
...identity.to.fields,
|
|
68
|
-
Definition: Schema.optionalKey(settings.Definition),
|
|
69
|
-
RoleArn: Schema.optionalKey(settings.RoleArn),
|
|
70
|
-
}).pipe(Schema.encodeKeys(keys));
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The stateMachineCommands Layer keeps the ARN in saved state while AWS
|
|
74
|
-
* deletes the state machine. DeleteStateMachine starts deletion. The
|
|
75
|
-
* registration waits for DescribeStateMachine to return
|
|
76
|
-
* StateMachineDoesNotExist before core releases ownership.
|
|
77
|
-
*/
|
|
78
|
-
export const stateMachineCommands = awsResourceRegistration(
|
|
79
|
-
AWSStateMachineResourceSchema,
|
|
80
|
-
{
|
|
81
|
-
service: stepFunctionsService,
|
|
82
|
-
create: resourceResponse(
|
|
83
|
-
resourceRequest(createStateMachineOperation, createInput),
|
|
84
|
-
identity,
|
|
85
|
-
),
|
|
86
|
-
read: resourceResponse(
|
|
87
|
-
resourceRequest(describeStateMachineOperation, identity),
|
|
88
|
-
observed,
|
|
89
|
-
),
|
|
90
|
-
update: resourceRequest(updateStateMachineOperation, changes),
|
|
91
|
-
remove: resourceRequest(deleteStateMachineOperation, identity),
|
|
92
|
-
missingErrors: ["StateMachineDoesNotExist"],
|
|
93
|
-
timeout: "5 minutes",
|
|
94
|
-
},
|
|
95
|
-
);
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
2
|
-
import { Digest } from "effect/crypto";
|
|
3
|
-
import { resourceStackRuntimeLayer } from "../../core/runtime/stackRuntimeLayer.js";
|
|
4
|
-
import { providerResourceCommandPolicyLayerLive } from "../resourceCommandPolicyLayer.js";
|
|
5
|
-
import {
|
|
6
|
-
awsClientConfigurationLayerLive,
|
|
7
|
-
awsClientLayer,
|
|
8
|
-
} from "./client/awsClient.js";
|
|
9
|
-
import { httpApiCommands } from "./resources/apiGatewayV2/httpApi.js";
|
|
10
|
-
import { awsNativeResourceCommandLayer } from "./resources/generated/native/resourceCommands.js";
|
|
11
|
-
import { grantCommands } from "./resources/iam/grantCommands.js";
|
|
12
|
-
import { roleCommands } from "./resources/iam/role.js";
|
|
13
|
-
import { functionCommands } from "./resources/lambda/function.js";
|
|
14
|
-
import { permissionCommands } from "./resources/lambda/permission.js";
|
|
15
|
-
import { stateMachineCommands } from "./resources/stepFunctions/stateMachine.js";
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
AwsClientConfig,
|
|
19
|
-
AwsRegion,
|
|
20
|
-
awsClientConfigLayer,
|
|
21
|
-
} from "./client/awsClientConfig.js";
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The awsServiceResourceCommandLayer Layer makes native AWS registrations
|
|
25
|
-
* available to the stack runtime. Every registration uses the same AWS
|
|
26
|
-
* client and the resource schemas registered by the application.
|
|
27
|
-
*
|
|
28
|
-
* @see ../../../../command-options-fund/refs/effect-website/apps/web/src/content/docs/v4/requirements-management/layers.mdx#merging-layers
|
|
29
|
-
*/
|
|
30
|
-
export const awsServiceResourceCommandLayer = Layer.mergeAll(
|
|
31
|
-
awsNativeResourceCommandLayer,
|
|
32
|
-
stateMachineCommands,
|
|
33
|
-
httpApiCommands,
|
|
34
|
-
roleCommands,
|
|
35
|
-
grantCommands,
|
|
36
|
-
functionCommands,
|
|
37
|
-
permissionCommands,
|
|
38
|
-
).pipe(
|
|
39
|
-
Layer.provideMerge(awsClientLayer),
|
|
40
|
-
Layer.provide(Digest.layerWebCrypto),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The AwsProviderLive Layer registers native AWS resource commands for stack
|
|
45
|
-
* execution. Applications use Layer.provide to supply AWS client configuration
|
|
46
|
-
* and HTTP transport when they assemble the stack runtime.
|
|
47
|
-
*
|
|
48
|
-
* @see ../../../../command-options-fund/refs/effect-website/apps/web/src/content/docs/v4/requirements-management/layers.mdx#composing-layers
|
|
49
|
-
*/
|
|
50
|
-
export const AwsProviderLive = providerResourceCommandPolicyLayerLive.pipe(
|
|
51
|
-
Layer.provideMerge(awsServiceResourceCommandLayer),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The awsNativeStackLayer Layer connects native command execution to core's
|
|
56
|
-
* stack runtime. Applications supply state storage, the secret policy, AWS
|
|
57
|
-
* configuration, and HTTP transport in the same graph as their declarations.
|
|
58
|
-
*/
|
|
59
|
-
export const awsNativeStackLayer = resourceStackRuntimeLayer.pipe(
|
|
60
|
-
Layer.provideMerge(AwsProviderLive),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The awsNativeStackLayerLive Layer lets a stack execute native AWS commands
|
|
65
|
-
* with environment credentials and fetch transport. The application supplies
|
|
66
|
-
* state storage and its secret policy through the same runtime.
|
|
67
|
-
*/
|
|
68
|
-
export const awsNativeStackLayerLive = awsNativeStackLayer.pipe(
|
|
69
|
-
Layer.provide(awsClientConfigurationLayerLive),
|
|
70
|
-
);
|