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,418 +0,0 @@
|
|
|
1
|
-
import { resolveEndpoint } from "@aws-sdk/core/client";
|
|
2
|
-
import {
|
|
3
|
-
Array as Arr,
|
|
4
|
-
Context,
|
|
5
|
-
Effect,
|
|
6
|
-
Layer,
|
|
7
|
-
Match,
|
|
8
|
-
Option,
|
|
9
|
-
Record,
|
|
10
|
-
Ref,
|
|
11
|
-
Schema,
|
|
12
|
-
} from "effect";
|
|
13
|
-
import { SecureRandom } from "effect/crypto";
|
|
14
|
-
import {
|
|
15
|
-
FetchHttpClient,
|
|
16
|
-
Headers,
|
|
17
|
-
HttpClient,
|
|
18
|
-
HttpClientRequest,
|
|
19
|
-
type HttpClientResponse,
|
|
20
|
-
} from "effect/http";
|
|
21
|
-
import { HttpApi, HttpApiClient, HttpApiGroup } from "effect/http-api";
|
|
22
|
-
import { ResourceCommandProgress } from "../../../core/resource/resourceCommandPolicy.js";
|
|
23
|
-
import {
|
|
24
|
-
AwsClientConfig,
|
|
25
|
-
type AwsClientConfiguration,
|
|
26
|
-
awsClientConfigLayer,
|
|
27
|
-
} from "./awsClientConfig.js";
|
|
28
|
-
import {
|
|
29
|
-
type AwsJsonRpcPayload,
|
|
30
|
-
type AwsOperation,
|
|
31
|
-
type AwsQueryOperation,
|
|
32
|
-
AwsRequestError,
|
|
33
|
-
type AwsServiceDefinition,
|
|
34
|
-
} from "./awsClientModel.js";
|
|
35
|
-
import { awsHttpEndpoint, awsHttpRequest } from "./awsHttpOperation.js";
|
|
36
|
-
import { awsQueryOutput, awsQueryRequest } from "./awsQueryOperation.js";
|
|
37
|
-
import { AwsRequestSigner } from "./awsRequestSigner.js";
|
|
38
|
-
import { AwsResponseDecoder } from "./awsResponseDecoder.js";
|
|
39
|
-
import { AwsRetryPolicy } from "./awsRetryPolicy.js";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The AwsClient service executes generated AWS operations through their input, output, and
|
|
43
|
-
* invocation contracts. Generated clients share its request preparation and
|
|
44
|
-
* retry behavior, while applications provide credentials, signing, transport,
|
|
45
|
-
* and error decoding through the same service graph.
|
|
46
|
-
*/
|
|
47
|
-
export class AwsClient extends Context.Service<AwsClient>()(
|
|
48
|
-
"nomoss/providers/aws/client/awsClient",
|
|
49
|
-
{
|
|
50
|
-
make: Effect.gen(function* () {
|
|
51
|
-
const config = yield* AwsClientConfig;
|
|
52
|
-
const signer = yield* AwsRequestSigner;
|
|
53
|
-
const decoder = yield* AwsResponseDecoder;
|
|
54
|
-
const retryPolicy = yield* AwsRetryPolicy;
|
|
55
|
-
const random = yield* SecureRandom.SecureRandom;
|
|
56
|
-
const transport = yield* HttpClient.HttpClient;
|
|
57
|
-
const redactedHeaderNames = yield* Headers.CurrentRedactedNames;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* preparePayload supplies missing modeled idempotency tokens for one
|
|
61
|
-
* logical invocation. Retries that use its encoded result retain the
|
|
62
|
-
* mutation's identity when AWS receives another attempt.
|
|
63
|
-
*/
|
|
64
|
-
const preparePayload = Effect.fn("AwsClient.preparePayload")(function* (
|
|
65
|
-
operation: AwsOperation,
|
|
66
|
-
payload: AwsJsonRpcPayload,
|
|
67
|
-
) {
|
|
68
|
-
const missingTokens = Arr.filter(
|
|
69
|
-
operation.idempotencyTokens,
|
|
70
|
-
(token) => !Record.has(payload, token),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const prepared: AwsJsonRpcPayload = yield* Effect.reduce(
|
|
74
|
-
missingTokens,
|
|
75
|
-
() => payload,
|
|
76
|
-
(current, token) =>
|
|
77
|
-
random
|
|
78
|
-
.uuidV4()
|
|
79
|
-
.pipe(Effect.map((value) => Record.set(current, token, value))),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
return prepared;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* sendRequest executes one prepared HTTP request with credentials
|
|
87
|
-
* resolved for this attempt. Signing covers the serialized request. An
|
|
88
|
-
* unsuccessful response preserves modeled provider details so the caller
|
|
89
|
-
* can decide whether the operation can be retried.
|
|
90
|
-
*/
|
|
91
|
-
const sendRequest = Effect.fn("AwsClient.sendRequest")(function* (
|
|
92
|
-
service: AwsServiceDefinition,
|
|
93
|
-
operation: AwsOperation,
|
|
94
|
-
configuration: AwsClientConfiguration,
|
|
95
|
-
request: HttpClientRequest.HttpClientRequest,
|
|
96
|
-
) {
|
|
97
|
-
yield* Effect.annotateCurrentSpan({
|
|
98
|
-
"aws.service": service.service,
|
|
99
|
-
"aws.operation": operation.name,
|
|
100
|
-
"aws.region": configuration.Region,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const credentials = yield* config.resolveCredentials();
|
|
104
|
-
|
|
105
|
-
const signed = yield* signer.signRequest(request, {
|
|
106
|
-
credentials,
|
|
107
|
-
region: configuration.Region,
|
|
108
|
-
signingName: service.signingName,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const received = yield* transport
|
|
112
|
-
.postprocess(Effect.succeed(signed))
|
|
113
|
-
.pipe(
|
|
114
|
-
Effect.provideService(Headers.CurrentRedactedNames, [
|
|
115
|
-
...redactedHeaderNames,
|
|
116
|
-
"x-amz-security-token",
|
|
117
|
-
]),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
yield* Effect.annotateCurrentSpan({
|
|
121
|
-
"http.response.status_code": received.status,
|
|
122
|
-
"aws.request_id": received.headers["x-amzn-requestid"],
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
yield* Effect.when(
|
|
126
|
-
decoder
|
|
127
|
-
.decodeError(service, operation, received)
|
|
128
|
-
.pipe(Effect.flatMap(Effect.fail)),
|
|
129
|
-
Effect.succeed(received.status < 200 || received.status >= 300),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const response: HttpClientResponse.HttpClientResponse = received;
|
|
133
|
-
|
|
134
|
-
return response;
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* execute retries a prepared operation up to the configured attempt
|
|
139
|
-
* limit. Attempts retain the payload and token but use fresh credentials
|
|
140
|
-
* and signatures. Interruption stops local HTTP work and backoff waits.
|
|
141
|
-
*/
|
|
142
|
-
const execute = Effect.fn("AwsClient.execute")(function* (
|
|
143
|
-
service: AwsServiceDefinition,
|
|
144
|
-
operation: AwsOperation,
|
|
145
|
-
configuration: AwsClientConfiguration,
|
|
146
|
-
request: HttpClientRequest.HttpClientRequest,
|
|
147
|
-
) {
|
|
148
|
-
const attempts = yield* Ref.make(0);
|
|
149
|
-
|
|
150
|
-
const response: HttpClientResponse.HttpClientResponse =
|
|
151
|
-
yield* sendRequest(service, operation, configuration, request).pipe(
|
|
152
|
-
Effect.retry({
|
|
153
|
-
times: configuration.maxAttempts - 1,
|
|
154
|
-
while: (failure) =>
|
|
155
|
-
Effect.gen(function* () {
|
|
156
|
-
const retryable = Match.value(failure).pipe(
|
|
157
|
-
Match.tag("AwsServiceError", (error) => error.retryable),
|
|
158
|
-
Match.tag("HttpClientError", () => true),
|
|
159
|
-
Match.orElse(() => false),
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const attempt = yield* Ref.updateAndGet(
|
|
163
|
-
attempts,
|
|
164
|
-
(count) => count + 1,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
const retryAfter = Match.value(failure).pipe(
|
|
168
|
-
Match.tag("AwsServiceError", (error) => error.retryAfter),
|
|
169
|
-
Match.orElse(() => undefined),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
yield* retryPolicy.retryDelay({ attempt, retryAfter }).pipe(
|
|
173
|
-
Effect.flatMap((delay) =>
|
|
174
|
-
ResourceCommandProgress.pipe(
|
|
175
|
-
Effect.flatMap((report) =>
|
|
176
|
-
report(
|
|
177
|
-
`Retrying ${operation.name} in ${Math.round(delay)}ms`,
|
|
178
|
-
),
|
|
179
|
-
),
|
|
180
|
-
Effect.flatMap((reported) =>
|
|
181
|
-
Effect.logInfo("Retrying AWS request").pipe(
|
|
182
|
-
Effect.annotateLogs({
|
|
183
|
-
"aws.operation": operation.name,
|
|
184
|
-
"aws.retry.attempt": attempt,
|
|
185
|
-
"aws.retry.delay_ms": delay,
|
|
186
|
-
"aws.retry.reason": failure._tag,
|
|
187
|
-
}),
|
|
188
|
-
Effect.when(Effect.succeed(!reported)),
|
|
189
|
-
),
|
|
190
|
-
),
|
|
191
|
-
Effect.andThen(() => Effect.sleep(delay)),
|
|
192
|
-
),
|
|
193
|
-
),
|
|
194
|
-
Effect.when(Effect.succeed(retryable)),
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
const shouldRetry: boolean = retryable;
|
|
198
|
-
|
|
199
|
-
return shouldRetry;
|
|
200
|
-
}),
|
|
201
|
-
}),
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
return response;
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* The createHttpClient service method applies the resolved AWS address
|
|
209
|
-
* to the operation path before signing. The generated path and query
|
|
210
|
-
* parameters must reach the signer and transport together.
|
|
211
|
-
*
|
|
212
|
-
* @see ../../../../../command-options-fund/refs/effect/packages/effect/src/http/HttpClientRequest.ts (prependUrl)
|
|
213
|
-
*/
|
|
214
|
-
const createHttpClient = Effect.fn("AwsClient.createHttpClient")(
|
|
215
|
-
function* (service: AwsServiceDefinition, operation: AwsOperation) {
|
|
216
|
-
const configuration = yield* config.resolveConfiguration();
|
|
217
|
-
|
|
218
|
-
const address = yield* Effect.try({
|
|
219
|
-
try: () =>
|
|
220
|
-
resolveEndpoint(service.endpointRules, {
|
|
221
|
-
endpointParams: Record.filter(
|
|
222
|
-
{
|
|
223
|
-
Region: configuration.Region,
|
|
224
|
-
UseFIPS: configuration.UseFIPS,
|
|
225
|
-
UseDualStack: configuration.UseDualStack,
|
|
226
|
-
Endpoint: configuration.Endpoint,
|
|
227
|
-
},
|
|
228
|
-
(value) => value !== undefined,
|
|
229
|
-
),
|
|
230
|
-
}),
|
|
231
|
-
catch: (error) =>
|
|
232
|
-
new AwsRequestError({
|
|
233
|
-
message: `AWS address resolution failed: ${String(error)}`,
|
|
234
|
-
}),
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
const client = HttpClient.transform(
|
|
238
|
-
HttpClient.mapRequest(transport, (request) =>
|
|
239
|
-
request.pipe(
|
|
240
|
-
HttpClientRequest.prependUrl(address.url.toString()),
|
|
241
|
-
HttpClientRequest.setHeaders(operation.headers),
|
|
242
|
-
),
|
|
243
|
-
),
|
|
244
|
-
(_send, request) => {
|
|
245
|
-
const signing = Arr.findFirst(
|
|
246
|
-
address.properties?.authSchemes ?? [],
|
|
247
|
-
(scheme) => scheme.name === "sigv4",
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
const context = Option.map(signing, (scheme) => ({
|
|
251
|
-
...configuration,
|
|
252
|
-
Region: scheme.signingRegion ?? configuration.Region,
|
|
253
|
-
})).pipe(Option.getOrElse(() => configuration));
|
|
254
|
-
|
|
255
|
-
return execute(service, operation, context, request);
|
|
256
|
-
},
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
return client;
|
|
260
|
-
},
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* The executeJson method gives HttpApiClient the modeled request and
|
|
265
|
-
* expected response status for JSON operations. The supplied HTTP
|
|
266
|
-
* client signs and sends the request after it has been encoded.
|
|
267
|
-
*
|
|
268
|
-
* @see ../../../../../command-options-fund/refs/effect/packages/effect/src/http-api/HttpApiClient.ts (makeWith)
|
|
269
|
-
*/
|
|
270
|
-
const executeJson = <Output, Encoded>(
|
|
271
|
-
operation: AwsOperation & {
|
|
272
|
-
readonly output: Schema.Codec<Output, Encoded>;
|
|
273
|
-
},
|
|
274
|
-
httpClient: Effect.Success<ReturnType<typeof createHttpClient>>,
|
|
275
|
-
payload: AwsJsonRpcPayload,
|
|
276
|
-
) => {
|
|
277
|
-
const api = HttpApi.make("AwsJsonOperation").add(
|
|
278
|
-
HttpApiGroup.make("operation", { topLevel: true }).add(
|
|
279
|
-
awsHttpEndpoint("execute", operation),
|
|
280
|
-
),
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
return HttpApiClient.makeWith(api, { httpClient }).pipe(
|
|
284
|
-
Effect.flatMap((client) =>
|
|
285
|
-
client.execute(awsHttpRequest(operation, payload)),
|
|
286
|
-
),
|
|
287
|
-
);
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* The executeQuery method uses the Smithy wire shapes for the form
|
|
292
|
-
* request and XML reply. It validates the decoded reply against the
|
|
293
|
-
* same Effect schema that the generated IAM client exposes.
|
|
294
|
-
*
|
|
295
|
-
* @see ../../../../refs/smithy/docs/source-2.0/aws/protocols/aws-query-protocol.rst (Overview)
|
|
296
|
-
*/
|
|
297
|
-
const executeQuery = <Output, Encoded>(
|
|
298
|
-
service: AwsServiceDefinition,
|
|
299
|
-
operation: AwsQueryOperation & {
|
|
300
|
-
readonly output: Schema.Codec<Output, Encoded>;
|
|
301
|
-
},
|
|
302
|
-
httpClient: Effect.Success<ReturnType<typeof createHttpClient>>,
|
|
303
|
-
payload: AwsJsonRpcPayload,
|
|
304
|
-
) =>
|
|
305
|
-
awsQueryRequest(service, operation, payload).pipe(
|
|
306
|
-
Effect.flatMap(httpClient.execute),
|
|
307
|
-
Effect.flatMap((response) =>
|
|
308
|
-
awsQueryOutput(service, operation, response),
|
|
309
|
-
),
|
|
310
|
-
Effect.flatMap(Schema.decodeUnknownEffect(operation.output)),
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* The bindOperation service method turns a generated AWS operation into
|
|
315
|
-
* a callable Effect. It encodes inputs before signing and uses the
|
|
316
|
-
* operation's success schema and HTTP status to decode the response.
|
|
317
|
-
*
|
|
318
|
-
* @see ../../../../../command-options-fund/refs/effect/packages/effect/src/http-api/HttpApiClient.ts (makeWith)
|
|
319
|
-
*/
|
|
320
|
-
const bindOperation =
|
|
321
|
-
(service: AwsServiceDefinition) =>
|
|
322
|
-
<Input, Output, Encoded>(
|
|
323
|
-
operation: AwsOperation & {
|
|
324
|
-
readonly input: Schema.Codec<Input, AwsJsonRpcPayload>;
|
|
325
|
-
readonly output: Schema.Codec<Output, Encoded>;
|
|
326
|
-
},
|
|
327
|
-
) => {
|
|
328
|
-
const invoke = Effect.fn(`${service.signingName}.${operation.name}`, {
|
|
329
|
-
attributes: {
|
|
330
|
-
"aws.service": service.service,
|
|
331
|
-
"aws.operation": operation.name,
|
|
332
|
-
},
|
|
333
|
-
})(
|
|
334
|
-
function* (input: Input) {
|
|
335
|
-
const payload: AwsJsonRpcPayload = yield* Schema.encodeEffect(
|
|
336
|
-
operation.input,
|
|
337
|
-
)(input);
|
|
338
|
-
|
|
339
|
-
const prepared: AwsJsonRpcPayload = yield* preparePayload(
|
|
340
|
-
operation,
|
|
341
|
-
payload,
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
yield* Effect.annotateCurrentSpan(
|
|
345
|
-
Record.filter(
|
|
346
|
-
{ "aws.cloudcontrol.type_name": prepared.TypeName },
|
|
347
|
-
(value) => value !== undefined,
|
|
348
|
-
),
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
const httpClient = yield* createHttpClient(service, operation);
|
|
352
|
-
|
|
353
|
-
const result: Output = yield* Match.value(operation).pipe(
|
|
354
|
-
Match.when(
|
|
355
|
-
(
|
|
356
|
-
operation,
|
|
357
|
-
): operation is typeof operation & AwsQueryOperation =>
|
|
358
|
-
operation.query !== undefined,
|
|
359
|
-
(query) => executeQuery(service, query, httpClient, prepared),
|
|
360
|
-
),
|
|
361
|
-
Match.orElse((operation) =>
|
|
362
|
-
executeJson(operation, httpClient, prepared),
|
|
363
|
-
),
|
|
364
|
-
);
|
|
365
|
-
return result;
|
|
366
|
-
},
|
|
367
|
-
Effect.annotateSpans({
|
|
368
|
-
"aws.service": service.service,
|
|
369
|
-
"aws.operation": operation.name,
|
|
370
|
-
}),
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
return invoke;
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
return {
|
|
377
|
-
preparePayload,
|
|
378
|
-
sendRequest,
|
|
379
|
-
execute,
|
|
380
|
-
createHttpClient,
|
|
381
|
-
bindOperation,
|
|
382
|
-
};
|
|
383
|
-
}),
|
|
384
|
-
},
|
|
385
|
-
) {}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* The awsClientLayer Layer supplies the common signing, response decoding, and
|
|
389
|
-
* retry services used by generated AWS operations. Native resource commands and
|
|
390
|
-
* Cloud Control commands share this client without a dependency on either
|
|
391
|
-
* resource lifecycle implementation. Callers supply configuration and transport.
|
|
392
|
-
*/
|
|
393
|
-
export const awsClientLayer = Layer.effect(AwsClient, AwsClient.make).pipe(
|
|
394
|
-
Layer.provide([
|
|
395
|
-
Layer.effect(AwsRequestSigner, AwsRequestSigner.make),
|
|
396
|
-
Layer.effect(AwsResponseDecoder, AwsResponseDecoder.make),
|
|
397
|
-
Layer.effect(AwsRetryPolicy, AwsRetryPolicy.make),
|
|
398
|
-
SecureRandom.layerWebCrypto,
|
|
399
|
-
]),
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* The awsClientConfigurationLayerLive Layer supplies environment credentials and
|
|
404
|
-
* fetch transport to an AWS application. Sharing this value lets resource and
|
|
405
|
-
* operation clients use the same configuration within one application graph.
|
|
406
|
-
*/
|
|
407
|
-
export const awsClientConfigurationLayerLive = Layer.merge(
|
|
408
|
-
awsClientConfigLayer,
|
|
409
|
-
FetchHttpClient.layer,
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* The awsClientLayerLive Layer lets a generated operation client execute with
|
|
414
|
-
* environment configuration and fetch transport in its caller's Effect scope.
|
|
415
|
-
*/
|
|
416
|
-
export const awsClientLayerLive = awsClientLayer.pipe(
|
|
417
|
-
Layer.provide(awsClientConfigurationLayerLive),
|
|
418
|
-
);
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
|
2
|
-
import {
|
|
3
|
-
loadConfig,
|
|
4
|
-
NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
5
|
-
NODE_REGION_CONFIG_OPTIONS,
|
|
6
|
-
NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS,
|
|
7
|
-
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
|
|
8
|
-
} from "@smithy/core/config";
|
|
9
|
-
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS } from "@smithy/core/retry";
|
|
10
|
-
import { Context, Data, Effect, Layer, Option } from "effect";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The AwsRegion reference overrides environment and shared-profile region selection for
|
|
14
|
-
* both request addresses and signing. Applications can leave it absent to use
|
|
15
|
-
* their existing AWS configuration.
|
|
16
|
-
*/
|
|
17
|
-
export const AwsRegion = Context.Reference<Option.Option<string>>(
|
|
18
|
-
"nomoss/providers/aws/client/region",
|
|
19
|
-
{ defaultValue: Option.none },
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export interface AwsCredentials {
|
|
23
|
-
readonly accessKeyId: string;
|
|
24
|
-
readonly secretAccessKey: string;
|
|
25
|
-
readonly sessionToken?: string;
|
|
26
|
-
readonly expiration?: Date;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface AwsClientConfiguration {
|
|
30
|
-
readonly Region: string;
|
|
31
|
-
readonly UseFIPS: boolean;
|
|
32
|
-
readonly UseDualStack: boolean;
|
|
33
|
-
readonly Endpoint: string | undefined;
|
|
34
|
-
readonly maxAttempts: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class AwsClientConfigurationError extends Data.TaggedError(
|
|
38
|
-
"AwsClientConfigurationError",
|
|
39
|
-
)<{ readonly message: string }> {}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* AwsClientConfig resolves AWS execution settings and credentials from the
|
|
43
|
-
* application's configuration. Credential resolution is available separately
|
|
44
|
-
* so retries can use a refreshed session and reuse the prepared request unchanged.
|
|
45
|
-
*/
|
|
46
|
-
export class AwsClientConfig extends Context.Service<AwsClientConfig>()(
|
|
47
|
-
"nomoss/providers/aws/client/awsClientConfig",
|
|
48
|
-
{
|
|
49
|
-
make: Effect.gen(function* () {
|
|
50
|
-
const configuredRegion = yield* AwsRegion;
|
|
51
|
-
const credentials = defaultProvider();
|
|
52
|
-
const region = loadConfig(
|
|
53
|
-
NODE_REGION_CONFIG_OPTIONS,
|
|
54
|
-
NODE_REGION_CONFIG_FILE_OPTIONS,
|
|
55
|
-
);
|
|
56
|
-
const useFips = loadConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS);
|
|
57
|
-
const useDualStack = loadConfig(
|
|
58
|
-
NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS,
|
|
59
|
-
);
|
|
60
|
-
const maxAttempts = loadConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS);
|
|
61
|
-
const endpoint = loadConfig({
|
|
62
|
-
environmentVariableSelector: (env) => env.AWS_ENDPOINT_URL,
|
|
63
|
-
configFileSelector: (profile) => profile.endpoint_url,
|
|
64
|
-
default: () => undefined,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The resolveCredentials service method asks the credential provider for
|
|
69
|
-
* credentials at each signing attempt so it can refresh an expired session.
|
|
70
|
-
* Resolution failures produce a typed configuration error.
|
|
71
|
-
*/
|
|
72
|
-
const resolveCredentials = Effect.fn(
|
|
73
|
-
"AwsClientConfig.resolveCredentials",
|
|
74
|
-
)(function* () {
|
|
75
|
-
const resolved: AwsCredentials = yield* Effect.tryPromise({
|
|
76
|
-
try: () => credentials(),
|
|
77
|
-
catch: (error) =>
|
|
78
|
-
new AwsClientConfigurationError({
|
|
79
|
-
message: `AWS credential resolution failed: ${String(error)}. Check the selected profile and refresh its credentials before retrying.`,
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return resolved;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* resolveConfiguration returns regional settings and the retry limit
|
|
88
|
-
* used to execute an operation.
|
|
89
|
-
* The application region override takes precedence over environment and
|
|
90
|
-
* profile selection for both requests and signing.
|
|
91
|
-
*/
|
|
92
|
-
const resolveConfiguration = Effect.fn(
|
|
93
|
-
"AwsClientConfig.resolveConfiguration",
|
|
94
|
-
)(function* () {
|
|
95
|
-
const resolved: AwsClientConfiguration = yield* Effect.tryPromise({
|
|
96
|
-
try: async () => {
|
|
97
|
-
const [Region, UseFIPS, UseDualStack, Endpoint, attempts] =
|
|
98
|
-
await Promise.all([
|
|
99
|
-
Option.getOrElse(configuredRegion, region),
|
|
100
|
-
useFips(),
|
|
101
|
-
useDualStack(),
|
|
102
|
-
endpoint(),
|
|
103
|
-
maxAttempts(),
|
|
104
|
-
]);
|
|
105
|
-
|
|
106
|
-
const configuration: AwsClientConfiguration = {
|
|
107
|
-
Region,
|
|
108
|
-
UseFIPS,
|
|
109
|
-
UseDualStack,
|
|
110
|
-
Endpoint,
|
|
111
|
-
maxAttempts: attempts,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return configuration;
|
|
115
|
-
},
|
|
116
|
-
catch: (error) =>
|
|
117
|
-
new AwsClientConfigurationError({
|
|
118
|
-
message: `AWS configuration resolution failed: ${String(error)}`,
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
return resolved;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return { resolveCredentials, resolveConfiguration };
|
|
126
|
-
}),
|
|
127
|
-
},
|
|
128
|
-
) {}
|
|
129
|
-
|
|
130
|
-
export const awsClientConfigLayer = Layer.effect(
|
|
131
|
-
AwsClientConfig,
|
|
132
|
-
AwsClientConfig.make,
|
|
133
|
-
);
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type { RuleSetObject } from "@smithy/core/endpoints";
|
|
2
|
-
import type { Schema as SmithySchema } from "@smithy/types";
|
|
3
|
-
import { Data, Schema } from "effect";
|
|
4
|
-
import type { HttpMethod } from "effect/http";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The AwsServiceDefinition interface carries the protocol and regional rules
|
|
8
|
-
* the generated client uses to find and sign requests for an AWS service.
|
|
9
|
-
*/
|
|
10
|
-
export interface AwsServiceDefinition {
|
|
11
|
-
readonly service: string;
|
|
12
|
-
readonly version: string;
|
|
13
|
-
readonly protocol: "awsJson1_0" | "restJson1" | "awsQuery";
|
|
14
|
-
readonly xmlNamespace?: string;
|
|
15
|
-
readonly signingName: string;
|
|
16
|
-
readonly endpointRules: RuleSetObject;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The AwsHttpOperation interface carries the HTTP request and failure
|
|
21
|
-
* metadata the client needs to execute an operation and decide whether to retry.
|
|
22
|
-
*/
|
|
23
|
-
export interface AwsHttpOperation {
|
|
24
|
-
readonly name: string;
|
|
25
|
-
readonly method: HttpMethod.HttpMethod;
|
|
26
|
-
readonly path: `/${string}`;
|
|
27
|
-
readonly headers: Readonly<Record<string, string>>;
|
|
28
|
-
readonly idempotencyTokens: ReadonlyArray<string>;
|
|
29
|
-
readonly pagination: Readonly<Record<string, Schema.Json>>;
|
|
30
|
-
readonly waiters: Readonly<Record<string, Schema.Json>>;
|
|
31
|
-
readonly errors: ReadonlyArray<{
|
|
32
|
-
readonly name: string;
|
|
33
|
-
readonly code?: string;
|
|
34
|
-
readonly schema: Schema.Decoder<Schema.Json>;
|
|
35
|
-
readonly retryable: Readonly<Record<string, Schema.Json>> | null;
|
|
36
|
-
}>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The AwsJsonRpcOperation interface describes an AWS JSON 1.0 request. The
|
|
41
|
-
* generated target header identifies the operation on the shared POST path.
|
|
42
|
-
*/
|
|
43
|
-
export interface AwsJsonRpcOperation extends AwsHttpOperation {
|
|
44
|
-
readonly method: "POST";
|
|
45
|
-
readonly rest?: never;
|
|
46
|
-
readonly query?: never;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The AwsRestJsonOperation interface retains Smithy's HTTP bindings and
|
|
51
|
-
* accepted success statuses. Input members without a binding form the JSON
|
|
52
|
-
* body when the operation accepts one. A registration may accept an additional
|
|
53
|
-
* observed success status while retaining the generated response schema.
|
|
54
|
-
*
|
|
55
|
-
* @see ../../../../refs/smithy/docs/source-2.0/spec/http-bindings.rst (HTTP message bindings)
|
|
56
|
-
*/
|
|
57
|
-
export interface AwsRestJsonOperation extends AwsHttpOperation {
|
|
58
|
-
readonly query?: never;
|
|
59
|
-
readonly rest: {
|
|
60
|
-
readonly bindings: Readonly<
|
|
61
|
-
Record<
|
|
62
|
-
string,
|
|
63
|
-
{
|
|
64
|
-
readonly location: "LABEL" | "QUERY" | "HEADER";
|
|
65
|
-
readonly name: string;
|
|
66
|
-
}
|
|
67
|
-
>
|
|
68
|
-
>;
|
|
69
|
-
readonly status: number | readonly number[];
|
|
70
|
-
readonly body: boolean;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The AwsQueryOperation interface carries the Smithy shapes used by the SDK
|
|
76
|
-
* to form Query requests and decode XML results for the same operation.
|
|
77
|
-
*/
|
|
78
|
-
export interface AwsQueryOperation extends AwsHttpOperation {
|
|
79
|
-
readonly method: "POST";
|
|
80
|
-
readonly rest?: never;
|
|
81
|
-
readonly query: {
|
|
82
|
-
readonly input: SmithySchema;
|
|
83
|
-
readonly output: SmithySchema;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The AwsOperation type connects generated protocol contracts to the shared
|
|
89
|
-
* AWS client used by resource registrations.
|
|
90
|
-
*/
|
|
91
|
-
export type AwsOperation =
|
|
92
|
-
| AwsJsonRpcOperation
|
|
93
|
-
| AwsRestJsonOperation
|
|
94
|
-
| AwsQueryOperation;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* AwsClient prepares this encoded AWS JSON payload before HTTP serialization.
|
|
98
|
-
* Retries use the prepared payload to preserve the operation's generated
|
|
99
|
-
* idempotency tokens.
|
|
100
|
-
*/
|
|
101
|
-
export const AwsJsonRpcPayload = Schema.Record(Schema.String, Schema.Json);
|
|
102
|
-
|
|
103
|
-
export type AwsJsonRpcPayload = typeof AwsJsonRpcPayload.Type;
|
|
104
|
-
|
|
105
|
-
export class AwsRequestError extends Data.TaggedError("AwsRequestError")<{
|
|
106
|
-
readonly message: string;
|
|
107
|
-
}> {}
|
|
108
|
-
|
|
109
|
-
export class AwsServiceError extends Data.TaggedError("AwsServiceError")<{
|
|
110
|
-
readonly service: string;
|
|
111
|
-
readonly operation: string;
|
|
112
|
-
readonly code: string;
|
|
113
|
-
readonly statusCode: number;
|
|
114
|
-
readonly message: string;
|
|
115
|
-
readonly requestId: string | undefined;
|
|
116
|
-
readonly retryAfter: string | undefined;
|
|
117
|
-
readonly retryable: boolean;
|
|
118
|
-
readonly details: Schema.Json;
|
|
119
|
-
}> {}
|