nomoss 0.0.1
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/LICENSE +19 -0
- package/README.md +45 -0
- package/bin/nomoss +13 -0
- package/docs/code-documentation.md +36 -0
- package/docs/effect-native-development.md +55 -0
- package/docs/engine-design.md +93 -0
- package/docs/linting.md +88 -0
- package/docs/releasing.md +13 -0
- package/docs/resource-command-policy-stage.md +71 -0
- package/docs/resource-graph-mvp.md +31 -0
- package/docs/resource-graph-testing-approach.md +11 -0
- package/docs/resource-lifecycle-tracker.md +93 -0
- package/docs/testing.md +86 -0
- package/examples/upload-events/README.md +41 -0
- package/media/nomoss.gif +0 -0
- package/package.json +64 -0
- package/src/cli.ts +18 -0
- package/src/cliCommand.ts +186 -0
- package/src/cliRuntimeLayer.ts +49 -0
- package/src/core/index.ts +17 -0
- package/src/core/lifecycle.ts +127 -0
- package/src/core/model.ts +229 -0
- package/src/core/physicalNameStore.ts +226 -0
- package/src/core/planner.ts +645 -0
- package/src/core/resourceCommandPolicy.ts +79 -0
- package/src/core/resourceGraphBuilder.ts +167 -0
- package/src/core/resourceGraphStore.ts +288 -0
- package/src/core/resourceOutputResolver.ts +185 -0
- package/src/core/resourcePolicy.ts +77 -0
- package/src/core/resourceStackDefinition.ts +17 -0
- package/src/core/resourceStackLifecycle.ts +456 -0
- package/src/core/resourceStackOperations.ts +129 -0
- package/src/core/runtimeLayer.ts +73 -0
- package/src/core/stackWorkflowRenderer.ts +239 -0
- package/src/core/stateSecretService.ts +553 -0
- package/src/core/stateStore.ts +652 -0
- package/src/core/tracing.ts +26 -0
- package/src/index.ts +2 -0
- package/src/providers/aws/awsApply.ts +132 -0
- package/src/providers/aws/awsBucket.ts +329 -0
- package/src/providers/aws/awsBucketNotification.ts +351 -0
- package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
- package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
- package/src/providers/aws/awsProviderLayer.ts +274 -0
- package/src/providers/aws/awsQueue.ts +346 -0
- package/src/providers/aws/awsQueuePolicy.ts +419 -0
- package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
- package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
- package/src/providers/aws/awsReconciliation.ts +92 -0
- package/src/providers/aws/awsRefresh.ts +50 -0
- package/src/providers/aws/awsResourceLifecycle.ts +118 -0
- package/src/providers/aws/awsResourcePolicy.ts +83 -0
- package/src/providers/aws/awsResources.ts +274 -0
- package/src/providers/aws/awsRuntimeLayer.ts +21 -0
- package/src/providers/aws/awsSqsTransport.ts +33 -0
- package/src/providers/aws/awsStackLifecycle.ts +272 -0
- package/src/providers/aws/awsTagging.ts +186 -0
- package/src/providers/aws/constants.ts +3 -0
- package/src/providers/aws/index.ts +22 -0
- package/src/providers/aws/sampleStack.ts +65 -0
- package/src/providers/aws/stackWorkflow.ts +443 -0
- package/src/providers/index.ts +5 -0
- package/src/providers/provider.ts +5 -0
- package/src/providers/providerRuntimeLayer.ts +121 -0
- package/src/providers/resourceCommandPolicyLayer.ts +240 -0
- package/src/providers/stripe/index.ts +15 -0
- package/src/providers/stripe/stripeAccount.ts +139 -0
- package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
- package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
- package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
- package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
- package/src/providers/stripe/stripeCustomer.ts +148 -0
- package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
- package/src/providers/stripe/stripePrice.ts +218 -0
- package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
- package/src/providers/stripe/stripeProduct.ts +171 -0
- package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
- package/src/providers/stripe/stripeResources.ts +454 -0
- package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
- package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
- package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import type * as SQS from "@distilled.cloud/aws/sqs";
|
|
2
|
+
import * as sqs from "@distilled.cloud/aws/sqs";
|
|
3
|
+
import {
|
|
4
|
+
Context,
|
|
5
|
+
Data,
|
|
6
|
+
Effect,
|
|
7
|
+
Equal,
|
|
8
|
+
Match,
|
|
9
|
+
Option,
|
|
10
|
+
Schedule,
|
|
11
|
+
Schema,
|
|
12
|
+
Struct,
|
|
13
|
+
} from "effect";
|
|
14
|
+
|
|
15
|
+
import { annotateResourceSchema } from "../../core/model.js";
|
|
16
|
+
import {
|
|
17
|
+
decodePendingQueueArnPlaceholder,
|
|
18
|
+
decodePendingQueueUrlPlaceholder,
|
|
19
|
+
encodePendingQueuePlaceholder,
|
|
20
|
+
PendingQueuePlaceholder,
|
|
21
|
+
} from "./awsQueue.js";
|
|
22
|
+
|
|
23
|
+
export const QueuePolicyPropsSchema = annotateResourceSchema(
|
|
24
|
+
sqs.SetQueueAttributesRequest,
|
|
25
|
+
{
|
|
26
|
+
provider: "aws",
|
|
27
|
+
service: "sqs",
|
|
28
|
+
resource: "queue-policy",
|
|
29
|
+
operation: "create",
|
|
30
|
+
stateSecretOutputKeys: [],
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type QueuePolicyProps = Schema.Schema.Type<
|
|
35
|
+
typeof QueuePolicyPropsSchema
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
export const QueuePolicyObservedStateSchema = annotateResourceSchema(
|
|
39
|
+
Schema.Struct({
|
|
40
|
+
attributes: sqs.GetQueueAttributesResult,
|
|
41
|
+
}),
|
|
42
|
+
{
|
|
43
|
+
provider: "aws",
|
|
44
|
+
service: "sqs",
|
|
45
|
+
resource: "queue-policy",
|
|
46
|
+
operation: "read",
|
|
47
|
+
stateSecretOutputKeys: [],
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export type QueuePolicyObservedState = Schema.Schema.Type<
|
|
52
|
+
typeof QueuePolicyObservedStateSchema
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
export type QueuePolicyState = {
|
|
56
|
+
readonly queueUrl: string;
|
|
57
|
+
readonly policy: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const QueuePolicyOutputsSchema = sqs.SetQueueAttributesResponse;
|
|
61
|
+
|
|
62
|
+
export type QueuePolicyOutputs = Schema.Schema.Type<
|
|
63
|
+
typeof QueuePolicyOutputsSchema
|
|
64
|
+
>;
|
|
65
|
+
|
|
66
|
+
export const QueuePolicyDocumentStatementSchema = Schema.Struct({
|
|
67
|
+
Sid: Schema.String,
|
|
68
|
+
Effect: Schema.Literal("Allow"),
|
|
69
|
+
Principal: Schema.Struct({
|
|
70
|
+
Service: Schema.Literal("s3.amazonaws.com"),
|
|
71
|
+
}),
|
|
72
|
+
Action: Schema.Literal("sqs:SendMessage"),
|
|
73
|
+
Resource: Schema.String,
|
|
74
|
+
Condition: Schema.Struct({
|
|
75
|
+
ArnLike: Schema.Struct({
|
|
76
|
+
"aws:SourceArn": Schema.String,
|
|
77
|
+
}),
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export type QueuePolicyDocumentStatement = Schema.Schema.Type<
|
|
82
|
+
typeof QueuePolicyDocumentStatementSchema
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
export const QueuePolicyDocumentSchema = Schema.Struct({
|
|
86
|
+
Version: Schema.Literal("2012-10-17"),
|
|
87
|
+
Statement: Schema.Array(QueuePolicyDocumentStatementSchema),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export type QueuePolicyDocument = Schema.Schema.Type<
|
|
91
|
+
typeof QueuePolicyDocumentSchema
|
|
92
|
+
>;
|
|
93
|
+
|
|
94
|
+
const QueuePolicyDocumentStringSchema = Schema.fromJsonString(
|
|
95
|
+
QueuePolicyDocumentSchema,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export class QueuePolicySetFailed extends Data.TaggedError(
|
|
99
|
+
"QueuePolicySetFailed",
|
|
100
|
+
)<{
|
|
101
|
+
readonly cause: SQS.SetQueueAttributesError;
|
|
102
|
+
}> {}
|
|
103
|
+
|
|
104
|
+
export class QueuePolicyReadFailed extends Data.TaggedError(
|
|
105
|
+
"QueuePolicyReadFailed",
|
|
106
|
+
)<{
|
|
107
|
+
readonly cause: SQS.GetQueueAttributesError | SQS.GetQueueUrlError;
|
|
108
|
+
}> {}
|
|
109
|
+
|
|
110
|
+
export class QueuePolicyQueueArnMissing extends Data.TaggedError(
|
|
111
|
+
"QueuePolicyQueueArnMissing",
|
|
112
|
+
)<{
|
|
113
|
+
readonly queueUrl: string;
|
|
114
|
+
}> {}
|
|
115
|
+
|
|
116
|
+
export type QueuePolicyError =
|
|
117
|
+
| QueuePolicySetFailed
|
|
118
|
+
| QueuePolicyReadFailed
|
|
119
|
+
| QueuePolicyQueueArnMissing;
|
|
120
|
+
|
|
121
|
+
const normalizePolicy = (policy: string | undefined) =>
|
|
122
|
+
Option.fromUndefinedOr(policy).pipe(
|
|
123
|
+
Option.flatMap((encoded) =>
|
|
124
|
+
Schema.decodeUnknownOption(QueuePolicyDocumentStringSchema)(encoded),
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
export const queuePoliciesEqual = (
|
|
129
|
+
left: string | undefined,
|
|
130
|
+
right: string | undefined,
|
|
131
|
+
) =>
|
|
132
|
+
Option.all({
|
|
133
|
+
left: normalizePolicy(left),
|
|
134
|
+
right: normalizePolicy(right),
|
|
135
|
+
}).pipe(
|
|
136
|
+
Option.match({
|
|
137
|
+
onNone: () => left === right,
|
|
138
|
+
onSome: ({ left: leftPolicy, right: rightPolicy }) =>
|
|
139
|
+
Equal.equals(leftPolicy, rightPolicy),
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export const s3SendMessageQueuePolicy = (
|
|
144
|
+
bucketArn: string,
|
|
145
|
+
queueArn: string,
|
|
146
|
+
) => {
|
|
147
|
+
const statement: QueuePolicyDocumentStatement = {
|
|
148
|
+
Sid: "AllowS3BucketNotifications",
|
|
149
|
+
Effect: "Allow",
|
|
150
|
+
Principal: {
|
|
151
|
+
Service: "s3.amazonaws.com",
|
|
152
|
+
},
|
|
153
|
+
Action: "sqs:SendMessage",
|
|
154
|
+
Resource: queueArn,
|
|
155
|
+
Condition: {
|
|
156
|
+
ArnLike: {
|
|
157
|
+
"aws:SourceArn": bucketArn,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
const policyDocument: QueuePolicyDocument = {
|
|
162
|
+
Version: "2012-10-17",
|
|
163
|
+
Statement: [statement],
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return Schema.encodeUnknownEffect(QueuePolicyDocumentStringSchema)(
|
|
167
|
+
policyDocument,
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Queue policy resources use this adapter so pending queue refs and policy
|
|
173
|
+
* normalization stay inside the SQS provider path.
|
|
174
|
+
*/
|
|
175
|
+
export class QueuePolicyLifecycleService extends Context.Service<QueuePolicyLifecycleService>()(
|
|
176
|
+
"nomoss/providers/aws/awsQueuePolicy/QueuePolicyLifecycleService",
|
|
177
|
+
{
|
|
178
|
+
make: Effect.gen(function* () {
|
|
179
|
+
const queueLookupRetryPolicy = Schedule.recurs(20);
|
|
180
|
+
const getQueueUrl = yield* sqs.getQueueUrl;
|
|
181
|
+
const getQueueAttributes = yield* sqs.getQueueAttributes;
|
|
182
|
+
const setQueueAttributes = yield* sqs.setQueueAttributes;
|
|
183
|
+
const queuePolicyStateFromProps = (
|
|
184
|
+
props: QueuePolicyProps,
|
|
185
|
+
): QueuePolicyState => ({
|
|
186
|
+
queueUrl: props.QueueUrl,
|
|
187
|
+
policy: props.Attributes.Policy ?? "",
|
|
188
|
+
});
|
|
189
|
+
const queuePolicyObservedState = (
|
|
190
|
+
attributes: SQS.GetQueueAttributesResult,
|
|
191
|
+
): QueuePolicyObservedState =>
|
|
192
|
+
QueuePolicyObservedStateSchema.make({
|
|
193
|
+
attributes,
|
|
194
|
+
});
|
|
195
|
+
const queueUrlOptionFromUnknown = (value: unknown) =>
|
|
196
|
+
Schema.decodeUnknownOption(Schema.String)(value);
|
|
197
|
+
const queueArnFromAttributes = (
|
|
198
|
+
queueUrl: string,
|
|
199
|
+
output: SQS.GetQueueAttributesResult,
|
|
200
|
+
) =>
|
|
201
|
+
Option.fromUndefinedOr(output.Attributes).pipe(
|
|
202
|
+
Option.flatMap((attributes) =>
|
|
203
|
+
Option.fromUndefinedOr(attributes.QueueArn),
|
|
204
|
+
),
|
|
205
|
+
Option.match({
|
|
206
|
+
onNone: () =>
|
|
207
|
+
Effect.fail(new QueuePolicyQueueArnMissing({ queueUrl })),
|
|
208
|
+
onSome: Effect.succeed,
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
const queueUrlOrPending = (
|
|
212
|
+
queueName: string,
|
|
213
|
+
output: SQS.GetQueueUrlResult,
|
|
214
|
+
) =>
|
|
215
|
+
Match.value(queueUrlOptionFromUnknown(output.QueueUrl)).pipe(
|
|
216
|
+
Match.when({ _tag: "None" }, () =>
|
|
217
|
+
encodePendingQueuePlaceholder(
|
|
218
|
+
PendingQueuePlaceholder.Url({ queueName }),
|
|
219
|
+
),
|
|
220
|
+
),
|
|
221
|
+
Match.when({ _tag: "Some" }, ({ value }) => value),
|
|
222
|
+
Match.exhaustive,
|
|
223
|
+
);
|
|
224
|
+
const pendingQueueUrlEffect = (queueName: string) =>
|
|
225
|
+
getQueueUrl({ QueueName: queueName }).pipe(
|
|
226
|
+
Effect.retry(queueLookupRetryPolicy),
|
|
227
|
+
Effect.mapError((cause) => new QueuePolicyReadFailed({ cause })),
|
|
228
|
+
Effect.map((output) => queueUrlOrPending(queueName, output)),
|
|
229
|
+
);
|
|
230
|
+
const pendingQueueUrlOptionEffect = (queueName: string) =>
|
|
231
|
+
getQueueUrl({ QueueName: queueName }).pipe(
|
|
232
|
+
Effect.map((output) => queueUrlOptionFromUnknown(output.QueueUrl)),
|
|
233
|
+
Effect.catchTag("QueueDoesNotExist", () =>
|
|
234
|
+
Effect.succeed(Option.none<string>()),
|
|
235
|
+
),
|
|
236
|
+
Effect.mapError((cause) => new QueuePolicyReadFailed({ cause })),
|
|
237
|
+
Effect.catchCause(() => Effect.succeed(Option.none<string>())),
|
|
238
|
+
);
|
|
239
|
+
const resolveQueueUrl = Effect.fn(
|
|
240
|
+
"QueuePolicyLifecycleService.resolveQueueUrl",
|
|
241
|
+
)(function* (queueUrl: string) {
|
|
242
|
+
const pendingQueueName = decodePendingQueueUrlPlaceholder(queueUrl);
|
|
243
|
+
|
|
244
|
+
return yield* Match.value(pendingQueueName).pipe(
|
|
245
|
+
Match.when({ _tag: "None" }, () => Effect.succeed(queueUrl)),
|
|
246
|
+
Match.when({ _tag: "Some" }, ({ value: queueName }) =>
|
|
247
|
+
pendingQueueUrlEffect(queueName),
|
|
248
|
+
),
|
|
249
|
+
Match.exhaustive,
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
const pendingQueueArnEffect = (queueUrl: string) =>
|
|
253
|
+
getQueueAttributes({
|
|
254
|
+
QueueUrl: queueUrl,
|
|
255
|
+
AttributeNames: ["QueueArn"],
|
|
256
|
+
}).pipe(
|
|
257
|
+
Effect.retry(queueLookupRetryPolicy),
|
|
258
|
+
Effect.mapError((cause) => new QueuePolicyReadFailed({ cause })),
|
|
259
|
+
Effect.flatMap((attributes) =>
|
|
260
|
+
queueArnFromAttributes(queueUrl, attributes),
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
const resolveQueuePolicyAttributes = Effect.fn(
|
|
264
|
+
"QueuePolicyLifecycleService.resolveQueuePolicyAttributes",
|
|
265
|
+
)(function* (props: QueuePolicyProps) {
|
|
266
|
+
const encodedPolicy = props.Attributes.Policy ?? "";
|
|
267
|
+
|
|
268
|
+
const policy = yield* Schema.decodeUnknownEffect(
|
|
269
|
+
QueuePolicyDocumentStringSchema,
|
|
270
|
+
)(encodedPolicy);
|
|
271
|
+
|
|
272
|
+
const queueUrl = yield* resolveQueueUrl(props.QueueUrl);
|
|
273
|
+
const currentResource = policy.Statement[0]?.Resource;
|
|
274
|
+
|
|
275
|
+
const queueArn = yield* Match.value(
|
|
276
|
+
Option.fromUndefinedOr(currentResource).pipe(
|
|
277
|
+
Option.flatMap(decodePendingQueueArnPlaceholder),
|
|
278
|
+
),
|
|
279
|
+
).pipe(
|
|
280
|
+
Match.when({ _tag: "None" }, () => Effect.succeed(currentResource)),
|
|
281
|
+
Match.when({ _tag: "Some" }, () => pendingQueueArnEffect(queueUrl)),
|
|
282
|
+
Match.exhaustive,
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const sourceArn =
|
|
286
|
+
policy.Statement[0]?.Condition.ArnLike["aws:SourceArn"];
|
|
287
|
+
|
|
288
|
+
const statement = QueuePolicyDocumentStatementSchema.make({
|
|
289
|
+
Sid: policy.Statement[0]?.Sid ?? "AllowS3BucketNotifications",
|
|
290
|
+
Effect: "Allow",
|
|
291
|
+
Principal: {
|
|
292
|
+
Service: "s3.amazonaws.com",
|
|
293
|
+
},
|
|
294
|
+
Action: "sqs:SendMessage",
|
|
295
|
+
Resource: queueArn,
|
|
296
|
+
Condition: {
|
|
297
|
+
ArnLike: {
|
|
298
|
+
"aws:SourceArn": sourceArn ?? "",
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
const resolvedPolicy = QueuePolicyDocumentSchema.make({
|
|
303
|
+
Version: policy.Version,
|
|
304
|
+
Statement: [statement],
|
|
305
|
+
});
|
|
306
|
+
const policyDocument = yield* Schema.encodeUnknownEffect(
|
|
307
|
+
QueuePolicyDocumentStringSchema,
|
|
308
|
+
)(resolvedPolicy);
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
queueUrl,
|
|
312
|
+
policy: policyDocument,
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
const resolveQueueUrlOption = Effect.fn(
|
|
316
|
+
"QueuePolicyLifecycleService.resolveQueueUrlOption",
|
|
317
|
+
)(function* (queueUrl: string) {
|
|
318
|
+
const pendingQueueName = decodePendingQueueUrlPlaceholder(queueUrl);
|
|
319
|
+
|
|
320
|
+
return yield* Match.value(pendingQueueName).pipe(
|
|
321
|
+
Match.when({ _tag: "None" }, () =>
|
|
322
|
+
Effect.succeed(Option.some(queueUrl)),
|
|
323
|
+
),
|
|
324
|
+
Match.when({ _tag: "Some" }, ({ value: queueName }) =>
|
|
325
|
+
pendingQueueUrlOptionEffect(queueName),
|
|
326
|
+
),
|
|
327
|
+
Match.exhaustive,
|
|
328
|
+
);
|
|
329
|
+
});
|
|
330
|
+
const readPolicyAttributes = Effect.fn(
|
|
331
|
+
"QueuePolicyLifecycleService.readPolicyAttributes",
|
|
332
|
+
)(function* (queueUrl: string) {
|
|
333
|
+
const attributes = yield* getQueueAttributes({
|
|
334
|
+
QueueUrl: queueUrl,
|
|
335
|
+
AttributeNames: ["Policy"],
|
|
336
|
+
}).pipe(
|
|
337
|
+
Effect.catchTag("QueueDoesNotExist", () =>
|
|
338
|
+
Effect.succeed<SQS.GetQueueAttributesResult>({}),
|
|
339
|
+
),
|
|
340
|
+
Effect.mapError((cause) => new QueuePolicyReadFailed({ cause })),
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
return Option.some(queuePolicyObservedState(attributes));
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return {
|
|
347
|
+
create: Effect.fn("QueuePolicyLifecycleService.create")(function* (
|
|
348
|
+
props: QueuePolicyProps,
|
|
349
|
+
) {
|
|
350
|
+
const resolved = yield* resolveQueuePolicyAttributes(props);
|
|
351
|
+
|
|
352
|
+
yield* setQueueAttributes({
|
|
353
|
+
QueueUrl: resolved.queueUrl,
|
|
354
|
+
Attributes: {
|
|
355
|
+
Policy: resolved.policy,
|
|
356
|
+
},
|
|
357
|
+
}).pipe(
|
|
358
|
+
Effect.mapError((cause) => new QueuePolicySetFailed({ cause })),
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
return queuePolicyStateFromProps(
|
|
362
|
+
Struct.assign(props, {
|
|
363
|
+
QueueUrl: resolved.queueUrl,
|
|
364
|
+
Attributes: Struct.assign(props.Attributes ?? {}, {
|
|
365
|
+
Policy: resolved.policy,
|
|
366
|
+
}),
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
}),
|
|
370
|
+
|
|
371
|
+
read: Effect.fn("QueuePolicyLifecycleService.read")(function* (
|
|
372
|
+
props: QueuePolicyProps,
|
|
373
|
+
) {
|
|
374
|
+
const decodedQueueUrl = queueUrlOptionFromUnknown(props.QueueUrl);
|
|
375
|
+
const queueUrlOption = yield* Option.match(decodedQueueUrl, {
|
|
376
|
+
onNone: () => Effect.succeed(Option.none<string>()),
|
|
377
|
+
onSome: resolveQueueUrlOption,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
return yield* Option.match(queueUrlOption, {
|
|
381
|
+
onNone: () =>
|
|
382
|
+
Effect.succeed(Option.none<QueuePolicyObservedState>()),
|
|
383
|
+
onSome: readPolicyAttributes,
|
|
384
|
+
});
|
|
385
|
+
}),
|
|
386
|
+
|
|
387
|
+
destroy: Effect.fn("QueuePolicyLifecycleService.destroy")(function* (
|
|
388
|
+
props: QueuePolicyProps,
|
|
389
|
+
) {
|
|
390
|
+
const decodedQueueUrl = queueUrlOptionFromUnknown(props.QueueUrl);
|
|
391
|
+
const queueUrlOption = yield* Option.match(decodedQueueUrl, {
|
|
392
|
+
onNone: () => Effect.succeed(Option.none<string>()),
|
|
393
|
+
onSome: resolveQueueUrlOption,
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
yield* Option.match(queueUrlOption, {
|
|
397
|
+
onNone: () => Effect.void,
|
|
398
|
+
onSome: (queueUrl) =>
|
|
399
|
+
setQueueAttributes({
|
|
400
|
+
QueueUrl: queueUrl,
|
|
401
|
+
Attributes: {
|
|
402
|
+
Policy: "",
|
|
403
|
+
},
|
|
404
|
+
}).pipe(
|
|
405
|
+
Effect.catchTag("QueueDoesNotExist", () => Effect.void),
|
|
406
|
+
Effect.mapError((cause) => new QueuePolicySetFailed({ cause })),
|
|
407
|
+
),
|
|
408
|
+
});
|
|
409
|
+
}),
|
|
410
|
+
|
|
411
|
+
resolve: Effect.fn("QueuePolicyLifecycleService.resolve")(function* (
|
|
412
|
+
props: QueuePolicyProps,
|
|
413
|
+
) {
|
|
414
|
+
return yield* resolveQueuePolicyAttributes(props);
|
|
415
|
+
}),
|
|
416
|
+
};
|
|
417
|
+
}),
|
|
418
|
+
},
|
|
419
|
+
) {}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Context, Effect, Match, Option, type Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PlanDecision,
|
|
5
|
+
type PlanDecision as PlanDecisionValue,
|
|
6
|
+
PlanRepairChange,
|
|
7
|
+
ResourceCommand,
|
|
8
|
+
ResourceCommandResult,
|
|
9
|
+
ResourceCommandUnsupported,
|
|
10
|
+
type ResourceObservation,
|
|
11
|
+
} from "../../core/lifecycle.js";
|
|
12
|
+
import { ResourceModel, type ResourceNode } from "../../core/model.js";
|
|
13
|
+
import { ResourcePolicy } from "../../core/resourcePolicy.js";
|
|
14
|
+
import {
|
|
15
|
+
QueuePolicyLifecycleService,
|
|
16
|
+
type QueuePolicyObservedState,
|
|
17
|
+
QueuePolicyObservedStateSchema,
|
|
18
|
+
QueuePolicyPropsSchema,
|
|
19
|
+
queuePoliciesEqual,
|
|
20
|
+
} from "./awsQueuePolicy.js";
|
|
21
|
+
|
|
22
|
+
const queuePolicyDecision = (
|
|
23
|
+
node: ResourceNode,
|
|
24
|
+
desiredPolicy: string,
|
|
25
|
+
observedPolicy: string | undefined,
|
|
26
|
+
) => {
|
|
27
|
+
const policyChanges = Option.match(Option.fromUndefinedOr(observedPolicy), {
|
|
28
|
+
onNone: () => [
|
|
29
|
+
PlanRepairChange.Added({
|
|
30
|
+
path: ["aws", "sqs", "queue-policy", "attributes", "Policy"],
|
|
31
|
+
after: desiredPolicy,
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
onSome: (policy) => [
|
|
35
|
+
PlanRepairChange.Updated({
|
|
36
|
+
path: ["aws", "sqs", "queue-policy", "attributes", "Policy"],
|
|
37
|
+
before: policy,
|
|
38
|
+
after: desiredPolicy,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return Match.value(queuePoliciesEqual(desiredPolicy, observedPolicy)).pipe(
|
|
44
|
+
Match.when(true, () => PlanDecision.NoOp({ node })),
|
|
45
|
+
Match.orElse(() =>
|
|
46
|
+
PlanDecision.Repair({
|
|
47
|
+
node,
|
|
48
|
+
reason: "queue policy differs from desired state",
|
|
49
|
+
changes: policyChanges,
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The AWS resource dispatcher reaches queue policy behavior through this
|
|
57
|
+
* policy, keeping graph commands separate from SQS policy attributes.
|
|
58
|
+
*/
|
|
59
|
+
export class QueuePolicyResourcePolicy extends Context.Service<QueuePolicyResourcePolicy>()(
|
|
60
|
+
"nomoss/providers/aws/awsQueuePolicyResourcePolicy/QueuePolicyResourcePolicy",
|
|
61
|
+
{
|
|
62
|
+
make: Effect.gen(function* () {
|
|
63
|
+
const lifecycle = yield* QueuePolicyLifecycleService;
|
|
64
|
+
const model = yield* ResourceModel;
|
|
65
|
+
const resourcePolicy = yield* ResourcePolicy;
|
|
66
|
+
|
|
67
|
+
const decidePresent = (node: ResourceNode, observed: Schema.Json) =>
|
|
68
|
+
model
|
|
69
|
+
.decodeProps(node, QueuePolicyPropsSchema)
|
|
70
|
+
.pipe(
|
|
71
|
+
Effect.flatMap((props) =>
|
|
72
|
+
Effect.flatMap(
|
|
73
|
+
model.decodeJson(QueuePolicyObservedStateSchema, observed),
|
|
74
|
+
(state) =>
|
|
75
|
+
Effect.map(lifecycle.resolve(props), (resolved) =>
|
|
76
|
+
queuePolicyDecision(
|
|
77
|
+
node,
|
|
78
|
+
resolved.policy,
|
|
79
|
+
state.attributes.Attributes?.Policy,
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
const read = Effect.fn("QueuePolicyResourcePolicy.read")(function* (
|
|
86
|
+
node: ResourceNode,
|
|
87
|
+
) {
|
|
88
|
+
const props = yield* model.decodeProps(node, QueuePolicyPropsSchema);
|
|
89
|
+
const output = yield* lifecycle
|
|
90
|
+
.read(props)
|
|
91
|
+
.pipe(
|
|
92
|
+
Effect.catchTag("QueuePolicyReadFailed", () =>
|
|
93
|
+
Effect.succeed(Option.none<QueuePolicyObservedState>()),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
const result = yield* Effect.fromOption(output).pipe(
|
|
97
|
+
Effect.flatMap((state: QueuePolicyObservedState) =>
|
|
98
|
+
Effect.map(
|
|
99
|
+
model.encodeJson(QueuePolicyObservedStateSchema, state),
|
|
100
|
+
(observed) => resourcePolicy.present(node, observed),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
Effect.catchNoSuchElement,
|
|
104
|
+
Effect.map(Option.getOrElse(() => resourcePolicy.missing(node))),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const diff = Effect.fn("QueuePolicyResourcePolicy.diff")(function* (
|
|
111
|
+
node: ResourceNode,
|
|
112
|
+
observation: ResourceObservation,
|
|
113
|
+
) {
|
|
114
|
+
const decision = yield* Match.value(observation).pipe(
|
|
115
|
+
Match.tagsExhaustive({
|
|
116
|
+
Missing: () => Effect.succeed(PlanDecision.Create({ node })),
|
|
117
|
+
Unreadable: ({ reason }) =>
|
|
118
|
+
Effect.succeed(PlanDecision.Repair({ node, reason })),
|
|
119
|
+
Drifted: ({ reason }) =>
|
|
120
|
+
Effect.succeed(PlanDecision.Repair({ node, reason })),
|
|
121
|
+
Present: ({ observed }) => decidePresent(node, observed),
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return ResourceCommandResult.Decided({ decision });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const create = Effect.fn("QueuePolicyResourcePolicy.create")(function* (
|
|
129
|
+
node: ResourceNode,
|
|
130
|
+
) {
|
|
131
|
+
const props = yield* model.decodeProps(node, QueuePolicyPropsSchema);
|
|
132
|
+
yield* lifecycle.create(props);
|
|
133
|
+
|
|
134
|
+
return ResourceCommandResult.Created({ node });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const repair = Effect.fn("QueuePolicyResourcePolicy.repair")(function* (
|
|
138
|
+
node: ResourceNode,
|
|
139
|
+
) {
|
|
140
|
+
const props = yield* model.decodeProps(node, QueuePolicyPropsSchema);
|
|
141
|
+
yield* lifecycle.create(props);
|
|
142
|
+
|
|
143
|
+
return ResourceCommandResult.Updated({ node });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const destroy = Effect.fn("QueuePolicyResourcePolicy.destroy")(function* (
|
|
147
|
+
node: ResourceNode,
|
|
148
|
+
) {
|
|
149
|
+
const props = yield* model.decodeProps(node, QueuePolicyPropsSchema);
|
|
150
|
+
yield* lifecycle.destroy(props);
|
|
151
|
+
|
|
152
|
+
return ResourceCommandResult.Destroyed({ node });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const apply = Effect.fn("QueuePolicyResourcePolicy.apply")(function* (
|
|
156
|
+
decision: PlanDecisionValue,
|
|
157
|
+
) {
|
|
158
|
+
return yield* Match.value(decision).pipe(
|
|
159
|
+
Match.tagsExhaustive({
|
|
160
|
+
Create: ({ node }) => create(node),
|
|
161
|
+
Repair: ({ node }) => repair(node),
|
|
162
|
+
Destroy: ({ node }) => destroy(node),
|
|
163
|
+
NoOp: () =>
|
|
164
|
+
Effect.fail(
|
|
165
|
+
new ResourceCommandUnsupported({
|
|
166
|
+
command: ResourceCommand.Apply({ decision }),
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
Update: () =>
|
|
170
|
+
Effect.fail(
|
|
171
|
+
new ResourceCommandUnsupported({
|
|
172
|
+
command: ResourceCommand.Apply({ decision }),
|
|
173
|
+
}),
|
|
174
|
+
),
|
|
175
|
+
Delete: () =>
|
|
176
|
+
Effect.fail(
|
|
177
|
+
new ResourceCommandUnsupported({
|
|
178
|
+
command: ResourceCommand.Apply({ decision }),
|
|
179
|
+
}),
|
|
180
|
+
),
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const execute = Effect.fn("QueuePolicyResourcePolicy.execute")(function* (
|
|
186
|
+
command: ResourceCommand,
|
|
187
|
+
) {
|
|
188
|
+
return yield* Match.value(command).pipe(
|
|
189
|
+
Match.tagsExhaustive({
|
|
190
|
+
Read: ({ node }) => read(node),
|
|
191
|
+
Diff: ({ node, observation }) => diff(node, observation),
|
|
192
|
+
Apply: ({ decision }) => apply(decision),
|
|
193
|
+
Create: ({ node }) => create(node),
|
|
194
|
+
Update: () =>
|
|
195
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
196
|
+
Delete: () =>
|
|
197
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
198
|
+
Destroy: () =>
|
|
199
|
+
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
200
|
+
}),
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
read,
|
|
206
|
+
diff,
|
|
207
|
+
create,
|
|
208
|
+
repair,
|
|
209
|
+
destroy,
|
|
210
|
+
apply,
|
|
211
|
+
execute,
|
|
212
|
+
};
|
|
213
|
+
}),
|
|
214
|
+
},
|
|
215
|
+
) {}
|