nomoss 0.0.3 → 0.0.5
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 +34 -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,549 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Array as Arr,
|
|
3
|
-
Context,
|
|
4
|
-
Effect,
|
|
5
|
-
Layer,
|
|
6
|
-
Match,
|
|
7
|
-
Option,
|
|
8
|
-
Record,
|
|
9
|
-
Schedule,
|
|
10
|
-
Schema,
|
|
11
|
-
Struct,
|
|
12
|
-
Tuple,
|
|
13
|
-
} from "effect";
|
|
14
|
-
import {
|
|
15
|
-
PlanDecision,
|
|
16
|
-
ResourceCommand,
|
|
17
|
-
ResourceCommandResult,
|
|
18
|
-
ResourceCommandUnsupported,
|
|
19
|
-
ResourceObservation,
|
|
20
|
-
} from "../../../core/resource/lifecycle.js";
|
|
21
|
-
import {
|
|
22
|
-
ResourceModel,
|
|
23
|
-
type ResourceNode,
|
|
24
|
-
resourceModelLayer,
|
|
25
|
-
} from "../../../core/resource/model.js";
|
|
26
|
-
import { ResourceCommandExecutionFailed } from "../../../core/resource/resourceCommandPolicy.js";
|
|
27
|
-
import { providerCommandPolicyTag } from "../../resourceCommandPolicyLayer.js";
|
|
28
|
-
import { AwsClient } from "../client/awsClient.js";
|
|
29
|
-
import { AwsJsonRpcPayload } from "../client/awsClientModel.js";
|
|
30
|
-
import type {
|
|
31
|
-
AwsAttributeResourceConfiguration,
|
|
32
|
-
AwsResourceAttributeValues,
|
|
33
|
-
AwsResourceOperation,
|
|
34
|
-
AwsResourceState,
|
|
35
|
-
} from "./resourceConfiguration.js";
|
|
36
|
-
import {
|
|
37
|
-
AwsResourceMapping,
|
|
38
|
-
AwsResourceMappingFailed,
|
|
39
|
-
awsResourceMappingLayer,
|
|
40
|
-
} from "./resourceMapping.js";
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The AwsResourceStabilizationTimeout reference lets an application limit the
|
|
44
|
-
* wait for observable AWS settings. Its twenty-minute default includes SQS's
|
|
45
|
-
* documented fifteen-minute retention propagation period and request time.
|
|
46
|
-
* A timeout leaves core's pending mutation available for retry.
|
|
47
|
-
*/
|
|
48
|
-
export const AwsResourceStabilizationTimeout = Context.Reference<number>(
|
|
49
|
-
"nomoss/providers/aws/management/resourcePolicy/stabilizationTimeout",
|
|
50
|
-
{ defaultValue: () => 20 * 60 * 1000 },
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The AwsResourcePolicy service completes creation and updates after provider
|
|
55
|
-
* reads confirm the desired attributes and managed tags. Deletion succeeds
|
|
56
|
-
* after a read confirms absence. Core owns persistence, replacement order, and
|
|
57
|
-
* recovery of unfinished stack operations.
|
|
58
|
-
*/
|
|
59
|
-
export class AwsResourcePolicy extends Context.Service<AwsResourcePolicy>()(
|
|
60
|
-
"nomoss/providers/aws/management/resourcePolicy/AwsResourcePolicy",
|
|
61
|
-
{
|
|
62
|
-
make: Effect.gen(function* () {
|
|
63
|
-
const client = yield* AwsClient;
|
|
64
|
-
const model = yield* ResourceModel;
|
|
65
|
-
const mapping = yield* AwsResourceMapping;
|
|
66
|
-
const equal = Schema.toEquivalence(Schema.Json);
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The invoke service method executes a native operation with its generated
|
|
70
|
-
* request, response, and modeled error codecs. Mutation operations can
|
|
71
|
-
* return Unit, represented by None. Object responses are returned as Some
|
|
72
|
-
* so observations can require their body without weakening the codec.
|
|
73
|
-
*/
|
|
74
|
-
const invoke = Effect.fn("AwsResourcePolicy.invoke")(function* (
|
|
75
|
-
definition: AwsAttributeResourceConfiguration,
|
|
76
|
-
operation: AwsResourceOperation,
|
|
77
|
-
input: object,
|
|
78
|
-
) {
|
|
79
|
-
const observed = yield* client.bindOperation(definition.service)(
|
|
80
|
-
operation,
|
|
81
|
-
)(input);
|
|
82
|
-
const body = yield* Schema.decodeUnknownEffect(
|
|
83
|
-
Schema.optional(AwsJsonRpcPayload),
|
|
84
|
-
)(observed);
|
|
85
|
-
const response: Option.Option<AwsJsonRpcPayload> =
|
|
86
|
-
Option.fromUndefinedOr(body);
|
|
87
|
-
|
|
88
|
-
return response;
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The observe service method returns a complete provider observation or
|
|
93
|
-
* absence for a configured missing-resource error. Permission, transport,
|
|
94
|
-
* and validation failures propagate so reconciliation retains ownership.
|
|
95
|
-
*/
|
|
96
|
-
const observe = Effect.fn("AwsResourcePolicy.observe")(
|
|
97
|
-
function* (
|
|
98
|
-
definition: AwsAttributeResourceConfiguration,
|
|
99
|
-
identity: string,
|
|
100
|
-
) {
|
|
101
|
-
// The observe operation requires both native reads because SQS returns
|
|
102
|
-
// settings and tags separately. Generated codecs validate each map before
|
|
103
|
-
// the resource mapper reconstructs the model that core can save.
|
|
104
|
-
const response = yield* invoke(
|
|
105
|
-
definition,
|
|
106
|
-
definition.operations.read,
|
|
107
|
-
{
|
|
108
|
-
[definition.mapping.identity.parameter]: identity,
|
|
109
|
-
AttributeNames: definition.mapping.readAttributeNames,
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
const body = yield* Effect.fromOption(response);
|
|
113
|
-
const attributes = yield* Schema.decodeUnknownEffect(
|
|
114
|
-
definition.attributeSchema,
|
|
115
|
-
)(body.Attributes ?? {});
|
|
116
|
-
const tagsResponse = yield* invoke(
|
|
117
|
-
definition,
|
|
118
|
-
definition.operations.readTags,
|
|
119
|
-
{
|
|
120
|
-
[definition.mapping.identity.parameter]: identity,
|
|
121
|
-
},
|
|
122
|
-
);
|
|
123
|
-
const tagsBody = yield* Effect.fromOption(tagsResponse);
|
|
124
|
-
const tags = yield* Schema.decodeUnknownEffect(
|
|
125
|
-
definition.tagMapSchema,
|
|
126
|
-
)(tagsBody[definition.mapping.tags.response] ?? {});
|
|
127
|
-
const state: AwsResourceState = yield* mapping.decodeResource(
|
|
128
|
-
definition,
|
|
129
|
-
identity,
|
|
130
|
-
attributes,
|
|
131
|
-
tags,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
return state;
|
|
135
|
-
},
|
|
136
|
-
(effect, definition) =>
|
|
137
|
-
effect.pipe(
|
|
138
|
-
Effect.asSome,
|
|
139
|
-
Effect.catchIf(
|
|
140
|
-
(failure) =>
|
|
141
|
-
failure._tag === "AwsServiceError" &&
|
|
142
|
-
Arr.contains(definition.mapping.missingErrors, failure.code),
|
|
143
|
-
() => Effect.succeedNone,
|
|
144
|
-
),
|
|
145
|
-
),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* The waitForState service method confirms declared settings and managed
|
|
150
|
-
* tags before a mutation can succeed. Unmanaged tags are preserved. Keys
|
|
151
|
-
* removed from the previous declaration must disappear from the provider.
|
|
152
|
-
*/
|
|
153
|
-
const waitForState = Effect.fn("AwsResourcePolicy.waitForState")(
|
|
154
|
-
function* (
|
|
155
|
-
definition: AwsAttributeResourceConfiguration,
|
|
156
|
-
identity: string,
|
|
157
|
-
attributes: AwsResourceAttributeValues,
|
|
158
|
-
tags: AwsResourceAttributeValues,
|
|
159
|
-
removedTags: ReadonlyArray<string> = [],
|
|
160
|
-
) {
|
|
161
|
-
const timeout = yield* AwsResourceStabilizationTimeout;
|
|
162
|
-
const pending = (observed: Option.Option<AwsResourceState>) =>
|
|
163
|
-
Option.match(observed, {
|
|
164
|
-
onNone: () => true,
|
|
165
|
-
onSome: (state) => {
|
|
166
|
-
const attributesReady = mapping.attributesMatch(
|
|
167
|
-
definition,
|
|
168
|
-
attributes,
|
|
169
|
-
state.attributes,
|
|
170
|
-
);
|
|
171
|
-
const tagsReady = Record.isSubrecord(tags, state.tags);
|
|
172
|
-
const tagsRemoved = Arr.every(
|
|
173
|
-
removedTags,
|
|
174
|
-
(key) => !Record.has(state.tags, key),
|
|
175
|
-
);
|
|
176
|
-
return !(attributesReady && tagsReady && tagsRemoved);
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
const state: AwsResourceState = yield* observe(
|
|
180
|
-
definition,
|
|
181
|
-
identity,
|
|
182
|
-
).pipe(
|
|
183
|
-
Effect.repeat({
|
|
184
|
-
while: pending,
|
|
185
|
-
schedule: Schedule.spaced("1 second"),
|
|
186
|
-
}),
|
|
187
|
-
Effect.timeout(timeout),
|
|
188
|
-
Effect.flatMap(Effect.fromOption),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
return state;
|
|
192
|
-
},
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* The create service method applies a resolved declaration and returns the
|
|
197
|
-
* observed resource for core to save. Its stable physical name lets SQS
|
|
198
|
-
* recover the same creation after a response or observation failure.
|
|
199
|
-
*/
|
|
200
|
-
const create = Effect.fn("AwsResourcePolicy.create")(function* (
|
|
201
|
-
definition: AwsAttributeResourceConfiguration,
|
|
202
|
-
node: ResourceNode,
|
|
203
|
-
) {
|
|
204
|
-
const desired = yield* mapping.prepare(definition, node);
|
|
205
|
-
const name = yield* mapping.physicalName(
|
|
206
|
-
definition,
|
|
207
|
-
node,
|
|
208
|
-
desired.properties,
|
|
209
|
-
);
|
|
210
|
-
const response = yield* invoke(
|
|
211
|
-
definition,
|
|
212
|
-
definition.operations.create,
|
|
213
|
-
{
|
|
214
|
-
[definition.mapping.name.parameter]: name,
|
|
215
|
-
Attributes: desired.attributes,
|
|
216
|
-
[definition.mapping.tags.createParameter]: desired.tags,
|
|
217
|
-
},
|
|
218
|
-
);
|
|
219
|
-
const body = yield* Effect.fromOption(response);
|
|
220
|
-
const identity = yield* Schema.decodeUnknownEffect(
|
|
221
|
-
Schema.NonEmptyString,
|
|
222
|
-
)(body[definition.mapping.identity.property]);
|
|
223
|
-
|
|
224
|
-
// The create operation waits for a complete read before returning a node.
|
|
225
|
-
// An accepted AWS request alone cannot release dependent resources or
|
|
226
|
-
// supply the application's output callback with validated saved values.
|
|
227
|
-
const observed = yield* waitForState(
|
|
228
|
-
definition,
|
|
229
|
-
identity,
|
|
230
|
-
desired.attributes,
|
|
231
|
-
desired.tags,
|
|
232
|
-
);
|
|
233
|
-
const applied = yield* model.withOutputs(node, observed.resource);
|
|
234
|
-
const result: ResourceCommandResult = ResourceCommandResult.Created({
|
|
235
|
-
node: applied,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
return result;
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* The read service method reconciles a saved provider identity. A present
|
|
243
|
-
* resource must retain that identity before its observation can reach core.
|
|
244
|
-
* Confirmed absence produces the Missing observation used by planning.
|
|
245
|
-
*/
|
|
246
|
-
const read = Effect.fn("AwsResourcePolicy.read")(function* (
|
|
247
|
-
definition: AwsAttributeResourceConfiguration,
|
|
248
|
-
node: ResourceNode,
|
|
249
|
-
) {
|
|
250
|
-
const identity = yield* model.decodeOutput(
|
|
251
|
-
node,
|
|
252
|
-
definition.mapping.identity.property,
|
|
253
|
-
Schema.NonEmptyString,
|
|
254
|
-
);
|
|
255
|
-
const observed = yield* observe(definition, identity);
|
|
256
|
-
const observation: ResourceObservation = yield* Option.match(observed, {
|
|
257
|
-
onNone: () => Effect.succeed(ResourceObservation.Missing({ node })),
|
|
258
|
-
onSome: Effect.fnUntraced(function* ({ resource }) {
|
|
259
|
-
const hydrated = yield* model.withObservedOutputs(node, resource);
|
|
260
|
-
const present: ResourceObservation = ResourceObservation.Present({
|
|
261
|
-
node: hydrated,
|
|
262
|
-
observed: resource,
|
|
263
|
-
});
|
|
264
|
-
return present;
|
|
265
|
-
}),
|
|
266
|
-
});
|
|
267
|
-
const result: ResourceCommandResult = ResourceCommandResult.Observed({
|
|
268
|
-
observation,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
return result;
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* The update service method changes settings and managed tags at a saved
|
|
276
|
-
* identity. Removed settings require configured reset values. Changes to
|
|
277
|
-
* create-only properties require core's replacement plan. Every native
|
|
278
|
-
* request is validated before the first update request reaches AWS.
|
|
279
|
-
*/
|
|
280
|
-
const update = Effect.fn("AwsResourcePolicy.update")(function* (
|
|
281
|
-
definition: AwsAttributeResourceConfiguration,
|
|
282
|
-
node: ResourceNode,
|
|
283
|
-
current: ResourceNode,
|
|
284
|
-
) {
|
|
285
|
-
const desired = yield* mapping.prepare(definition, node);
|
|
286
|
-
const previous = yield* mapping.prepare(definition, current);
|
|
287
|
-
const identity = yield* model.decodeOutput(
|
|
288
|
-
current,
|
|
289
|
-
definition.mapping.identity.property,
|
|
290
|
-
Schema.NonEmptyString,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
// The update operation resolves property removal before mutation because
|
|
294
|
-
// omission from SetQueueAttributes would preserve the old AWS value.
|
|
295
|
-
const removed = Record.filter(
|
|
296
|
-
definition.mapping.attributes,
|
|
297
|
-
(_, key) =>
|
|
298
|
-
Record.has(previous.properties, key) &&
|
|
299
|
-
!Record.has(desired.properties, key),
|
|
300
|
-
);
|
|
301
|
-
const resets = yield* Effect.forEach(
|
|
302
|
-
Record.toEntries(removed),
|
|
303
|
-
Effect.fnUntraced(function* ([property, rule]) {
|
|
304
|
-
const value = yield* Effect.fromOption(
|
|
305
|
-
Option.fromUndefinedOr(rule.reset),
|
|
306
|
-
() =>
|
|
307
|
-
new AwsResourceMappingFailed({
|
|
308
|
-
typeName: definition.mapping.typeName,
|
|
309
|
-
message: `Removing ${property} requires a configured reset value`,
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
return Tuple.make(property, value);
|
|
313
|
-
}),
|
|
314
|
-
);
|
|
315
|
-
const replacementRequired = Arr.some(
|
|
316
|
-
definition.createOnlyProperties,
|
|
317
|
-
(key) =>
|
|
318
|
-
!equal(
|
|
319
|
-
desired.properties[key] ?? null,
|
|
320
|
-
previous.properties[key] ?? null,
|
|
321
|
-
),
|
|
322
|
-
);
|
|
323
|
-
const decision = PlanDecision.Update({ node, current });
|
|
324
|
-
const command = ResourceCommand.Apply({ decision });
|
|
325
|
-
yield* Effect.fail(new ResourceCommandUnsupported({ command })).pipe(
|
|
326
|
-
Effect.when(Effect.succeed(replacementRequired)),
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
const properties = Record.union(
|
|
330
|
-
Record.fromEntries(resets),
|
|
331
|
-
desired.properties,
|
|
332
|
-
(_, declared) => declared,
|
|
333
|
-
);
|
|
334
|
-
const expected = yield* mapping.encodeAttributes(
|
|
335
|
-
definition,
|
|
336
|
-
properties,
|
|
337
|
-
);
|
|
338
|
-
const immutable = Record.filter(
|
|
339
|
-
definition.mapping.attributes,
|
|
340
|
-
(_, property) =>
|
|
341
|
-
Arr.contains(definition.createOnlyProperties, property),
|
|
342
|
-
);
|
|
343
|
-
const immutableAttributes = Arr.map(
|
|
344
|
-
Record.values(immutable),
|
|
345
|
-
({ attribute }) => attribute,
|
|
346
|
-
);
|
|
347
|
-
const attributes = Record.filter(
|
|
348
|
-
expected,
|
|
349
|
-
(_, attribute) => !Arr.contains(immutableAttributes, attribute),
|
|
350
|
-
);
|
|
351
|
-
const removedTags = Record.keys(
|
|
352
|
-
Record.filter(
|
|
353
|
-
previous.tags,
|
|
354
|
-
(_, key) => !Record.has(desired.tags, key),
|
|
355
|
-
),
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
// The update operation preflights all attribute and tag changes together.
|
|
359
|
-
// Empty changes skip APIs that reject empty maps. Only tags owned by the
|
|
360
|
-
// previous declaration qualify for removal; other provider tags remain.
|
|
361
|
-
const changes = Arr.filter(
|
|
362
|
-
[
|
|
363
|
-
{
|
|
364
|
-
enabled: !Record.isEmptyRecord(attributes),
|
|
365
|
-
operation: definition.operations.update,
|
|
366
|
-
input: {
|
|
367
|
-
[definition.mapping.identity.parameter]: identity,
|
|
368
|
-
Attributes: attributes,
|
|
369
|
-
},
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
enabled: !Record.isEmptyRecord(desired.tags),
|
|
373
|
-
operation: definition.operations.tag,
|
|
374
|
-
input: {
|
|
375
|
-
[definition.mapping.identity.parameter]: identity,
|
|
376
|
-
[definition.mapping.tags.updateParameter]: desired.tags,
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
enabled: removedTags.length > 0,
|
|
381
|
-
operation: definition.operations.untag,
|
|
382
|
-
input: {
|
|
383
|
-
[definition.mapping.identity.parameter]: identity,
|
|
384
|
-
[definition.mapping.tags.removeParameter]: removedTags,
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
],
|
|
388
|
-
(change) => change.enabled,
|
|
389
|
-
);
|
|
390
|
-
const validated = yield* Effect.forEach(
|
|
391
|
-
changes,
|
|
392
|
-
Effect.fnUntraced(function* (change) {
|
|
393
|
-
const input = yield* Schema.decodeUnknownEffect(
|
|
394
|
-
change.operation.input,
|
|
395
|
-
)(change.input);
|
|
396
|
-
return { operation: change.operation, input };
|
|
397
|
-
}),
|
|
398
|
-
);
|
|
399
|
-
yield* Effect.forEach(validated, (change) =>
|
|
400
|
-
invoke(definition, change.operation, change.input),
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
const observed = yield* waitForState(
|
|
404
|
-
definition,
|
|
405
|
-
identity,
|
|
406
|
-
attributes,
|
|
407
|
-
desired.tags,
|
|
408
|
-
removedTags,
|
|
409
|
-
);
|
|
410
|
-
const observedNode = Struct.assign(node, { outputs: current.outputs });
|
|
411
|
-
const applied = yield* model.withObservedOutputs(
|
|
412
|
-
observedNode,
|
|
413
|
-
observed.resource,
|
|
414
|
-
);
|
|
415
|
-
const result: ResourceCommandResult = ResourceCommandResult.Updated({
|
|
416
|
-
node: applied,
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
return result;
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* The destroy service method confirms provider absence before core can
|
|
424
|
-
* release ownership. A configured missing-resource error is idempotent
|
|
425
|
-
* success. Failed deletion or observation leaves saved ownership for retry.
|
|
426
|
-
*/
|
|
427
|
-
const destroy = Effect.fn("AwsResourcePolicy.destroy")(function* (
|
|
428
|
-
definition: AwsAttributeResourceConfiguration,
|
|
429
|
-
node: ResourceNode,
|
|
430
|
-
) {
|
|
431
|
-
const { property, parameter } = definition.mapping.identity;
|
|
432
|
-
const outputs = yield* model.decodeOutputs(
|
|
433
|
-
node,
|
|
434
|
-
Schema.Struct({ [property]: Schema.NonEmptyString }),
|
|
435
|
-
);
|
|
436
|
-
const identity = yield* Record.get(outputs, property).pipe(
|
|
437
|
-
Effect.fromOption,
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
yield* invoke(definition, definition.operations.remove, {
|
|
441
|
-
[parameter]: identity,
|
|
442
|
-
}).pipe(
|
|
443
|
-
Effect.catchIf(
|
|
444
|
-
(failure) =>
|
|
445
|
-
failure._tag === "AwsServiceError" &&
|
|
446
|
-
Arr.contains(definition.mapping.missingErrors, failure.code),
|
|
447
|
-
() => Effect.void,
|
|
448
|
-
),
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
// The destroy operation requires a missing read after deletion. An
|
|
452
|
-
// accepted DeleteQueue request can precede removal by up to 60 seconds.
|
|
453
|
-
yield* observe(definition, identity).pipe(
|
|
454
|
-
Effect.repeat({
|
|
455
|
-
while: Option.isSome,
|
|
456
|
-
schedule: Schedule.spaced("1 second"),
|
|
457
|
-
}),
|
|
458
|
-
Effect.timeout("75 seconds"),
|
|
459
|
-
);
|
|
460
|
-
const result: ResourceCommandResult = ResourceCommandResult.Destroyed({
|
|
461
|
-
node,
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
return result;
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* The execute service method handles core's resource command protocol.
|
|
469
|
-
* Failures retain the original command and typed cause so core can report
|
|
470
|
-
* the failed action and recover its saved lifecycle progress.
|
|
471
|
-
*/
|
|
472
|
-
const execute = Effect.fn("AwsResourcePolicy.execute")(
|
|
473
|
-
function* (
|
|
474
|
-
definition: AwsAttributeResourceConfiguration,
|
|
475
|
-
command: ResourceCommand,
|
|
476
|
-
) {
|
|
477
|
-
const action = yield* Match.value(command).pipe(
|
|
478
|
-
Match.tag("Apply", ({ decision }) => Effect.succeed(decision)),
|
|
479
|
-
Match.tag("Create", "Read", "Destroy", (command) =>
|
|
480
|
-
Effect.succeed(command),
|
|
481
|
-
),
|
|
482
|
-
Match.orElse(() =>
|
|
483
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
484
|
-
),
|
|
485
|
-
);
|
|
486
|
-
const result: ResourceCommandResult = yield* Match.value(action).pipe(
|
|
487
|
-
Match.tag("Create", ({ node }) => create(definition, node)),
|
|
488
|
-
Match.tag("Read", ({ node }) => read(definition, node)),
|
|
489
|
-
Match.tag("Update", ({ node, current }) =>
|
|
490
|
-
update(definition, node, current),
|
|
491
|
-
),
|
|
492
|
-
Match.tag("Delete", "Destroy", ({ node }) =>
|
|
493
|
-
destroy(definition, node),
|
|
494
|
-
),
|
|
495
|
-
Match.orElse(() =>
|
|
496
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
497
|
-
),
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
return result;
|
|
501
|
-
},
|
|
502
|
-
(effect, _, command) =>
|
|
503
|
-
effect.pipe(
|
|
504
|
-
Effect.mapError(
|
|
505
|
-
(cause) => new ResourceCommandExecutionFailed({ command, cause }),
|
|
506
|
-
),
|
|
507
|
-
),
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
return {
|
|
511
|
-
invoke,
|
|
512
|
-
observe,
|
|
513
|
-
waitForState,
|
|
514
|
-
create,
|
|
515
|
-
read,
|
|
516
|
-
update,
|
|
517
|
-
destroy,
|
|
518
|
-
execute,
|
|
519
|
-
};
|
|
520
|
-
}),
|
|
521
|
-
},
|
|
522
|
-
) {}
|
|
523
|
-
|
|
524
|
-
export const awsResourcePolicyLayer = Layer.effect(
|
|
525
|
-
AwsResourcePolicy,
|
|
526
|
-
AwsResourcePolicy.make,
|
|
527
|
-
).pipe(
|
|
528
|
-
Layer.provideMerge(awsResourceMappingLayer),
|
|
529
|
-
Layer.provide(resourceModelLayer),
|
|
530
|
-
);
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* The awsResourcePolicyRegistration function makes generated resource commands
|
|
534
|
-
* available in the application's shared runtime. The provider supplies the AWS
|
|
535
|
-
* client and digest, and declaration and execution share ResourceModel.
|
|
536
|
-
*/
|
|
537
|
-
export const awsResourcePolicyRegistration = (
|
|
538
|
-
definition: AwsAttributeResourceConfiguration,
|
|
539
|
-
) =>
|
|
540
|
-
Layer.effect(
|
|
541
|
-
providerCommandPolicyTag(definition.schema),
|
|
542
|
-
Effect.gen(function* () {
|
|
543
|
-
const policy = yield* AwsResourcePolicy;
|
|
544
|
-
return {
|
|
545
|
-
execute: (command: ResourceCommand) =>
|
|
546
|
-
policy.execute(definition, command),
|
|
547
|
-
};
|
|
548
|
-
}),
|
|
549
|
-
).pipe(Layer.provideMerge(awsResourcePolicyLayer));
|