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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Array as Arr, Context, Effect, Layer, Option, Schema } from "effect";
|
|
2
|
+
import { Digest } from "effect/crypto";
|
|
3
|
+
import {
|
|
4
|
+
type ResourceNode,
|
|
5
|
+
resourceGeneration,
|
|
6
|
+
} from "../../../src/core/resource/model.js";
|
|
7
|
+
import { ResourceCommandStackName } from "../../../src/core/resource/resourceCommandPolicy.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The AwsResourceMapping service gives stack commands repeatable names when
|
|
11
|
+
* the declaration omits a name. A retry can address the same resource name
|
|
12
|
+
* if the first request reached AWS before the stack could save the result.
|
|
13
|
+
*
|
|
14
|
+
* @see ../../../docs/application/aws-resource-lifecycle-management.md (Resource policy and recovery)
|
|
15
|
+
*/
|
|
16
|
+
export class AwsResourceMapping extends Context.Service<AwsResourceMapping>()(
|
|
17
|
+
"nomoss/providers/aws/management/resourceMapping/AwsResourceMapping",
|
|
18
|
+
{
|
|
19
|
+
make: Effect.gen(function* () {
|
|
20
|
+
const digest = yield* Digest.Digest;
|
|
21
|
+
|
|
22
|
+
const json = Schema.fromJsonString(Schema.Json);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The identityHash service method returns a hash scoped to the named stack
|
|
26
|
+
* and the resource's logical ID. Pass the identity values in the same order
|
|
27
|
+
* on retry to reproduce that hash.
|
|
28
|
+
*
|
|
29
|
+
* @see ../../../refs/effect/packages/effect/src/crypto/Digest.ts (digestHex)
|
|
30
|
+
*/
|
|
31
|
+
const identityHash = Effect.fn("AwsResourceMapping.identityHash")(
|
|
32
|
+
function* (node: ResourceNode, identity: ReadonlyArray<Schema.Json>) {
|
|
33
|
+
const owner = yield* ResourceCommandStackName.pipe(
|
|
34
|
+
Effect.flatMap(Effect.fromOption),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const key = Arr.appendAll([owner, node.key.logicalId], identity);
|
|
38
|
+
const seed = yield* Schema.encodeEffect(json)(key);
|
|
39
|
+
|
|
40
|
+
const hash: string = yield* digest.digestHex(
|
|
41
|
+
Digest.sha256,
|
|
42
|
+
new TextEncoder().encode(seed),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return hash;
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The resolveName service method returns an explicit name verbatim. If you
|
|
51
|
+
* omit the name, the method uses the resource generation and fits the result
|
|
52
|
+
* to the supplied length limit. A retry uses the same generation; a
|
|
53
|
+
* replacement uses a new one.
|
|
54
|
+
*
|
|
55
|
+
* @see ../../../docs/application/resource-operations.md (Create and replace a resource)
|
|
56
|
+
*/
|
|
57
|
+
const resolveName = Effect.fn("AwsResourceMapping.resolveName")(
|
|
58
|
+
function* (
|
|
59
|
+
node: ResourceNode,
|
|
60
|
+
name: string | undefined,
|
|
61
|
+
maximumLength: number,
|
|
62
|
+
) {
|
|
63
|
+
const explicitName = Option.fromUndefinedOr(name);
|
|
64
|
+
|
|
65
|
+
return yield* Option.match(explicitName, {
|
|
66
|
+
onSome: Effect.succeed,
|
|
67
|
+
onNone: Effect.fnUntraced(function* () {
|
|
68
|
+
const generation = resourceGeneration(node);
|
|
69
|
+
const hash = yield* identityHash(node, [generation]);
|
|
70
|
+
return `nomoss-${hash}`.substring(0, maximumLength);
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return { resolveName };
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
) {}
|
|
80
|
+
|
|
81
|
+
export const awsResourceMappingLayer = Layer.effect(
|
|
82
|
+
AwsResourceMapping,
|
|
83
|
+
AwsResourceMapping.make,
|
|
84
|
+
);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AwsJsonRpcPayload,
|
|
3
|
+
AwsOperation,
|
|
4
|
+
} from "@tradedal/aws-client-core/model";
|
|
5
|
+
import {
|
|
6
|
+
Effect,
|
|
7
|
+
RegExp as Regex,
|
|
8
|
+
Schema,
|
|
9
|
+
SchemaGetter,
|
|
10
|
+
SchemaTransformation,
|
|
11
|
+
String as Str,
|
|
12
|
+
} from "effect";
|
|
13
|
+
|
|
14
|
+
type Operation<Input, Output, Encoded = unknown> = AwsOperation & {
|
|
15
|
+
readonly input: Schema.Codec<Input, AwsJsonRpcPayload>;
|
|
16
|
+
readonly output: Schema.Codec<Output, Encoded>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The awsJsonDocument schema gives lifecycle reads a policy object whether
|
|
21
|
+
* IAM returns plain JSON text or URI-encoded text. A stack can then compare
|
|
22
|
+
* the document's contents with the declaration. The GetRolePolicy model
|
|
23
|
+
* describes these response formats.
|
|
24
|
+
*
|
|
25
|
+
* @see ../../../refs/aws-api-models/models/iam/service/2010-05-08/iam-2010-05-08.json (GetRolePolicy)
|
|
26
|
+
*/
|
|
27
|
+
export const awsJsonDocument = Schema.Union([
|
|
28
|
+
Schema.fromJsonString(Schema.JsonObject),
|
|
29
|
+
Schema.StringFromUriComponent.pipe(
|
|
30
|
+
Schema.decodeTo(Schema.fromJsonString(Schema.JsonObject)),
|
|
31
|
+
),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The awsJsonDocumentInput codec accepts a JSON object or a string from an
|
|
36
|
+
* IAM policy declaration. IAM receives text in either case. If the request
|
|
37
|
+
* codec reads valid JSON object text back, the lifecycle has an object it
|
|
38
|
+
* can compare with the current policy.
|
|
39
|
+
*
|
|
40
|
+
* @see ../../../refs/aws-cdk-service-spec/sources/CloudFormationSchema/us-east-1/aws-iam-role.json (AssumeRolePolicyDocument)
|
|
41
|
+
* @see ../../../refs/effect/packages/effect/src/Schema.ts (Union and fromJsonString)
|
|
42
|
+
*/
|
|
43
|
+
export const awsJsonDocumentInput = Schema.Union([
|
|
44
|
+
Schema.fromJsonString(Schema.JsonObject),
|
|
45
|
+
Schema.String,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The awsJsonDocumentValue schema accepts an object or JSON object text from
|
|
50
|
+
* a policy declaration. A lifecycle compares the document as an object so a
|
|
51
|
+
* difference in whitespace does not trigger an IAM write.
|
|
52
|
+
*/
|
|
53
|
+
export const awsJsonDocumentValue = Schema.Union([
|
|
54
|
+
Schema.JsonObject,
|
|
55
|
+
Schema.fromJsonString(Schema.JsonObject),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The relationshipValueCodec function lets a declaration refer to a related
|
|
60
|
+
* resource by its bare ID. For an API Gateway target, both "abc" and
|
|
61
|
+
* "integrations/abc" produce the AWS value "integrations/abc". The codec
|
|
62
|
+
* returns "abc" from that value so the lifecycle can compare the target
|
|
63
|
+
* with the integration's ID.
|
|
64
|
+
*
|
|
65
|
+
* @see ../../../refs/effect/packages/effect/src/Schema.ts (decodeTo)
|
|
66
|
+
*/
|
|
67
|
+
export const relationshipValueCodec = (prefix: string) => {
|
|
68
|
+
// The leadingPrefix pattern matches the literal prefix at the start of
|
|
69
|
+
// the value. For "integrations/", the codec turns "integrations/abc" into
|
|
70
|
+
// "abc" and leaves "xintegrations/abc" intact.
|
|
71
|
+
// See ../../../refs/effect/packages/effect/src/RegExp.ts (escape).
|
|
72
|
+
const leadingPrefix = new RegExp(`^${Regex.escape(prefix)}`);
|
|
73
|
+
const bareId = Str.replace(leadingPrefix, "");
|
|
74
|
+
|
|
75
|
+
return Schema.String.pipe(
|
|
76
|
+
Schema.decodeTo(
|
|
77
|
+
Schema.String,
|
|
78
|
+
SchemaTransformation.transform({
|
|
79
|
+
decode: bareId,
|
|
80
|
+
encode: (value) => prefix + bareId(value),
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The resourceRequest function lets a caller supply names from a stack
|
|
88
|
+
* declaration to a generated AWS operation. The mapping translates those
|
|
89
|
+
* names, and the generated request schema still checks the native request
|
|
90
|
+
* before the client sends it.
|
|
91
|
+
*
|
|
92
|
+
* @see ../../../refs/effect/packages/effect/src/Schema.ts (decodeTo)
|
|
93
|
+
*/
|
|
94
|
+
export const resourceRequest = <Input, NativeInput, Output, Encoded>(
|
|
95
|
+
operation: Operation<NativeInput, Output, Encoded>,
|
|
96
|
+
codec: Schema.Codec<Input, NoInfer<NativeInput>>,
|
|
97
|
+
) => {
|
|
98
|
+
const input = operation.input.pipe(Schema.decodeTo(codec));
|
|
99
|
+
|
|
100
|
+
return { ...operation, input };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The resourceResponse function lets a command require a provider value that
|
|
105
|
+
* the generated response schema permits AWS to omit. The generated schema
|
|
106
|
+
* checks the reply first. If the selected fields lack a required value such
|
|
107
|
+
* as the resource ID, the command fails before the stack can save the result.
|
|
108
|
+
*
|
|
109
|
+
* @see ../../../refs/effect/packages/effect/src/Schema.ts (decodeTo)
|
|
110
|
+
*/
|
|
111
|
+
export const resourceResponse = <Input, NativeOutput, Encoded, Output, Fields>(
|
|
112
|
+
operation: Operation<Input, NativeOutput, Encoded>,
|
|
113
|
+
codec: Schema.Codec<Output, Fields>,
|
|
114
|
+
select: (
|
|
115
|
+
response: NativeOutput,
|
|
116
|
+
) => NativeOutput | Schema.JsonObject | undefined = (response) => response,
|
|
117
|
+
) => {
|
|
118
|
+
const decode = SchemaGetter.transformEffect((response: NativeOutput) => {
|
|
119
|
+
const selected = select(response);
|
|
120
|
+
|
|
121
|
+
return Schema.decodeUnknownEffect(codec)(selected).pipe(
|
|
122
|
+
Effect.mapError((failure) => failure.issue),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const output = operation.output.pipe(
|
|
127
|
+
Schema.decodeTo(Schema.toType(codec), {
|
|
128
|
+
decode,
|
|
129
|
+
encode: SchemaGetter.forbiddenEncoding,
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return { ...operation, output };
|
|
134
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AwsClient } from "@tradedal/aws-client-core";
|
|
2
|
+
import type { AwsServiceDefinition } from "@tradedal/aws-client-core/model";
|
|
3
|
+
import { Array as Arr, Context, Effect, Option, Schema } from "effect";
|
|
4
|
+
import { associationChanges } from "./resourceAssociations.js";
|
|
5
|
+
import type { ResourceOperation } from "./resourceLifecycleRegistration.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The ResourceTags schema requires a value for each key. The stack needs
|
|
9
|
+
* both to tell whether a declared tag already has the requested value or
|
|
10
|
+
* needs another write.
|
|
11
|
+
*/
|
|
12
|
+
const ResourceTags = Schema.Array(
|
|
13
|
+
Schema.Struct({ Key: Schema.String, Value: Schema.String }),
|
|
14
|
+
);
|
|
15
|
+
type ResourceTags = typeof ResourceTags.Type;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The AwsResourceTagOperations service preserves tags that an operator
|
|
19
|
+
* or another tool added. A lifecycle definition must supply AWS operations
|
|
20
|
+
* that can set individual keys and remove selected keys.
|
|
21
|
+
*/
|
|
22
|
+
export class AwsResourceTagOperations extends Context.Service<AwsResourceTagOperations>()(
|
|
23
|
+
"nomoss/providers/aws/management/resourceTagOperations/AwsResourceTagOperations",
|
|
24
|
+
{
|
|
25
|
+
make: Effect.fn("AwsResourceTagOperations.make")(function* (
|
|
26
|
+
service: AwsServiceDefinition,
|
|
27
|
+
operations: {
|
|
28
|
+
readonly tag: ResourceOperation<unknown>;
|
|
29
|
+
readonly untag: ResourceOperation<unknown>;
|
|
30
|
+
},
|
|
31
|
+
) {
|
|
32
|
+
const client = yield* AwsClient;
|
|
33
|
+
|
|
34
|
+
const bind = client.bindOperation(service);
|
|
35
|
+
|
|
36
|
+
const tag = bind(operations.tag);
|
|
37
|
+
|
|
38
|
+
const untag = bind(operations.untag);
|
|
39
|
+
|
|
40
|
+
const tags = (value: ResourceTags | undefined) =>
|
|
41
|
+
Option.fromUndefinedOr(value).pipe(Option.toArray, Arr.flatten);
|
|
42
|
+
|
|
43
|
+
const includesTag = (
|
|
44
|
+
current: ResourceTags,
|
|
45
|
+
{ Key, Value }: ResourceTags[number],
|
|
46
|
+
) =>
|
|
47
|
+
Arr.some(
|
|
48
|
+
current,
|
|
49
|
+
(entry) => entry.Key === Key && entry.Value === Value,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The reconcile service method removes a key only if the prior declaration
|
|
54
|
+
* listed it and the new declaration omits it. Its check accepts a fresh
|
|
55
|
+
* provider read once every requested value appears and the keys selected
|
|
56
|
+
* for removal are absent.
|
|
57
|
+
*/
|
|
58
|
+
const reconcile = Effect.fn("AwsResourceTagOperations.reconcile")(
|
|
59
|
+
function* (
|
|
60
|
+
Parent: string,
|
|
61
|
+
observed: ResourceTags | undefined,
|
|
62
|
+
previous: ResourceTags | undefined,
|
|
63
|
+
desired: ResourceTags | undefined,
|
|
64
|
+
) {
|
|
65
|
+
const current = tags(observed);
|
|
66
|
+
|
|
67
|
+
const requested = tags(desired);
|
|
68
|
+
|
|
69
|
+
const keys = (values: ResourceTags) =>
|
|
70
|
+
Arr.map(values, ({ Key }) => Key);
|
|
71
|
+
|
|
72
|
+
const { remove } = associationChanges(
|
|
73
|
+
keys(current),
|
|
74
|
+
keys(tags(previous)),
|
|
75
|
+
keys(requested),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const changed = Arr.filter(
|
|
79
|
+
requested,
|
|
80
|
+
(entry) => !includesTag(current, entry),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
yield* tag({ Parent, Tags: changed }).pipe(
|
|
84
|
+
Effect.when(Effect.succeed(Arr.isReadonlyArrayNonEmpty(changed))),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
yield* untag({ Parent, TagKeys: remove }).pipe(
|
|
88
|
+
Effect.when(Effect.succeed(Arr.isReadonlyArrayNonEmpty(remove))),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return (observed: ResourceTags | undefined) => {
|
|
92
|
+
const confirmed = tags(observed);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
Arr.every(requested, (entry) => includesTag(confirmed, entry)) &&
|
|
96
|
+
Arr.every(
|
|
97
|
+
remove,
|
|
98
|
+
(key) => !Arr.some(confirmed, ({ Key }) => key === Key),
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return { reconcile };
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
108
|
+
) {}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { awsClientLayer } from "@tradedal/aws-client-core";
|
|
2
|
+
import { awsClientConfigurationLayerLive } from "@tradedal/aws-credentials";
|
|
3
|
+
import { Layer } from "effect";
|
|
4
|
+
import { Digest } from "effect/crypto";
|
|
5
|
+
import { resourceModelLayer } from "../../src/core/resource/model.js";
|
|
6
|
+
import { resourceStabilizationLayer } from "../../src/core/resource/resourceStabilization.js";
|
|
7
|
+
import { resourceStackRuntimeLayer } from "../../src/core/runtime/stackRuntimeLayer.js";
|
|
8
|
+
import { providerResourceCommandPolicyLayerLive } from "../../src/providers/resourceCommandPolicyLayer.js";
|
|
9
|
+
import { AwsEnvironment } from "./awsEnvironment.js";
|
|
10
|
+
import { awsResourceManagementRegistryLayer } from "./management/resourceManagementRegistry.js";
|
|
11
|
+
import { awsResourceMappingLayer } from "./management/resourceMapping.js";
|
|
12
|
+
|
|
13
|
+
export { AwsClientConfig, AwsRegion } from "@tradedal/aws-client-core/config";
|
|
14
|
+
export { awsClientConfigLayer } from "@tradedal/aws-credentials";
|
|
15
|
+
export {
|
|
16
|
+
AwsEnvironment,
|
|
17
|
+
type AwsResolvedEnvironment,
|
|
18
|
+
} from "./awsEnvironment.js";
|
|
19
|
+
|
|
20
|
+
export const awsServiceResourceCommandLayer =
|
|
21
|
+
awsResourceManagementRegistryLayer.pipe(
|
|
22
|
+
Layer.provide([
|
|
23
|
+
resourceModelLayer,
|
|
24
|
+
resourceStabilizationLayer,
|
|
25
|
+
awsResourceMappingLayer.pipe(Layer.provide(Digest.layerWebCrypto)),
|
|
26
|
+
]),
|
|
27
|
+
Layer.provideMerge(awsClientLayer),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const AwsProviderLive = providerResourceCommandPolicyLayerLive.pipe(
|
|
31
|
+
Layer.provideMerge(awsServiceResourceCommandLayer),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The awsNativeStackLayer Layer connects native command execution to core's
|
|
36
|
+
* stack runtime. Applications supply state storage, the secret policy, AWS
|
|
37
|
+
* configuration, and HTTP transport in the same graph as their declarations.
|
|
38
|
+
*/
|
|
39
|
+
export const awsNativeStackLayer = AwsEnvironment.layer.pipe(
|
|
40
|
+
Layer.provideMerge(
|
|
41
|
+
resourceStackRuntimeLayer.pipe(Layer.provideMerge(AwsProviderLive)),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The awsNativeStackLayerLive Layer lets a stack execute native AWS commands
|
|
47
|
+
* with environment credentials and fetch transport. The application supplies
|
|
48
|
+
* state storage and its secret policy through the same runtime.
|
|
49
|
+
*/
|
|
50
|
+
export const awsNativeStackLayerLive = awsNativeStackLayer.pipe(
|
|
51
|
+
Layer.provide(awsClientConfigurationLayerLive),
|
|
52
|
+
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Context, Data, Effect, Option } from "effect";
|
|
2
|
+
import type { ResourceStateStore } from "../state/stateStore.js";
|
|
2
3
|
import type { ResourceCommand, ResourceCommandResult } from "./lifecycle.js";
|
|
4
|
+
import type { ResourceNode } from "./model.js";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* The ResourceCommandStackName reference supplies the stack that owns a provider
|
|
@@ -13,6 +15,24 @@ export const ResourceCommandStackName = Context.Reference<
|
|
|
13
15
|
defaultValue: Option.none,
|
|
14
16
|
});
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The ResourceCommandCreation reference lets a provider lifecycle resume a
|
|
20
|
+
* submitted create during stack apply. The lifecycle can save one-time
|
|
21
|
+
* outputs before confirmation so the next apply can recover them.
|
|
22
|
+
*
|
|
23
|
+
* @see ../../../node_modules/effect/src/Context.ts (Reference)
|
|
24
|
+
*/
|
|
25
|
+
export const ResourceCommandCreation = Context.Reference<
|
|
26
|
+
Option.Option<{
|
|
27
|
+
readonly submitted: Option.Option<ResourceNode>;
|
|
28
|
+
readonly record: (
|
|
29
|
+
node: ResourceNode,
|
|
30
|
+
) => ReturnType<ResourceStateStore["Service"]["recordResourceCreation"]>;
|
|
31
|
+
}>
|
|
32
|
+
>("nomoss/core/resource/resourceCommandPolicy/creation", {
|
|
33
|
+
defaultValue: Option.none,
|
|
34
|
+
});
|
|
35
|
+
|
|
16
36
|
/**
|
|
17
37
|
* The ResourceCommandProgress reference reports a provider status message
|
|
18
38
|
* for the current command. It returns false when no display is subscribed,
|