@geekmidas/cloud 10.0.0-alpha.17 → 10.0.0-alpha.171
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/README.md +26 -6
- package/package.json +9 -8
- package/src/sst/__tests__/api.spec.ts +0 -46
- package/src/sst/__tests__/bootstrap.spec.ts +15 -0
- package/src/sst/__tests__/encryption.spec.ts +90 -0
- package/src/sst/__tests__/fromManifest.inbox.spec.ts +157 -0
- package/src/sst/__tests__/fromManifest.integration.spec.ts +87 -3
- package/src/sst/__tests__/fromManifest.secret.spec.ts +79 -0
- package/src/sst/__tests__/fromManifest.spec.ts +412 -18
- package/src/sst/__tests__/function.spec.ts +0 -71
- package/src/sst/__tests__/hostLabels.spec.ts +74 -0
- package/src/sst/__tests__/surfaces.spec.ts +68 -5
- package/src/sst/__tests__/websocket.spec.ts +207 -0
- package/src/sst/__tests__/wildcardSite.spec.ts +195 -0
- package/src/sst/__type-tests__/overrides.type-test.ts +152 -0
- package/src/sst/aws/Api.ts +0 -43
- package/src/sst/aws/Credential.ts +42 -9
- package/src/sst/aws/Cron.ts +5 -45
- package/src/sst/aws/DatabaseBootstrap.ts +6 -0
- package/src/sst/aws/Encryption.ts +91 -0
- package/src/sst/aws/ExternalApi.ts +58 -0
- package/src/sst/aws/Function.ts +9 -38
- package/src/sst/aws/Inbox.ts +141 -0
- package/src/sst/aws/ObjectStorage.ts +3 -3
- package/src/sst/aws/Queue.ts +34 -1
- package/src/sst/aws/RestApiSurface.ts +36 -14
- package/src/sst/aws/Secret.ts +6 -4
- package/src/sst/aws/StaticSite.ts +44 -1
- package/src/sst/aws/WebSocketApiSurface.ts +160 -0
- package/src/sst/aws/bootstrap/handler.ts +12 -1
- package/src/sst/errors.ts +37 -0
- package/src/sst/fromManifest.ts +624 -71
- package/src/sst/index.ts +21 -1
- package/src/sst/overrides.ts +149 -0
- package/src/sst/__type-tests__/manifest.type-test.ts +0 -77
package/README.md
CHANGED
|
@@ -105,17 +105,25 @@ const cron = new Cron(stack, 'Nightly', { processor: fn, schedule: 'rate(1 day)'
|
|
|
105
105
|
|
|
106
106
|
### From a `gkm build` manifest
|
|
107
107
|
|
|
108
|
-
`gkm build`
|
|
109
|
-
|
|
108
|
+
The root `gkm build` writes the application's manifest to
|
|
109
|
+
`.gkm/manifest/aws.ts` (types in `@geekmidas/manifest`), and `fromManifest`
|
|
110
|
+
maps it straight into infra:
|
|
110
111
|
|
|
111
112
|
```ts
|
|
112
|
-
|
|
113
|
+
// sst.config.ts
|
|
114
|
+
const { App, fromManifest, Stack } = await import('@geekmidas/cloud/sst');
|
|
115
|
+
const { backends, constructs } = await import('./.gkm/manifest/aws.js');
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
const workers = Function.fromManifest(stack, functionsManifest, { links: [db] });
|
|
116
|
-
const crons = Cron.fromManifest(stack, cronsManifest, { links: [db] });
|
|
117
|
+
fromManifest(new Stack(app, 'Shop'), constructs, { Database: { vpc } }, backends);
|
|
117
118
|
```
|
|
118
119
|
|
|
120
|
+
`constructs` is every declared construct keyed by id; the overrides are keyed
|
|
121
|
+
by the same ids. One call provisions the resources, each `RestApi`'s endpoints
|
|
122
|
+
(each a Lambda linked only to its own dependencies, placed in the database's
|
|
123
|
+
VPC when it reaches one, with the `iam` authorizer enforced by the gateway),
|
|
124
|
+
queue consumers, every function (a Lambda with an IAM-authorized URL) and every
|
|
125
|
+
cron (a Lambda on its schedule).
|
|
126
|
+
|
|
119
127
|
## `@geekmidas/cloud/utils` (runtime)
|
|
120
128
|
|
|
121
129
|
```ts
|
|
@@ -124,3 +132,15 @@ import { buildResourceEnv } from '@geekmidas/cloud';
|
|
|
124
132
|
|
|
125
133
|
`buildResourceEnv` turns a record of SST `Resource` links into flat environment
|
|
126
134
|
variables at runtime, using the shared `ResourceType` vocabulary.
|
|
135
|
+
|
|
136
|
+
## Optional peers
|
|
137
|
+
|
|
138
|
+
<!-- optional-peers:start -->
|
|
139
|
+
|
|
140
|
+
<!-- Generated by `node scripts/check-optional-peers.mjs --write-docs`; CI fails when it drifts. -->
|
|
141
|
+
|
|
142
|
+
No entry imports an optional peer when it loads. `@geekmidas/db`, `@geekmidas/events`, `@geekmidas/manifest`, `@geekmidas/storage`, `@pulumi/aws`, `@pulumi/pulumi`, `@pulumi/random`, `pg` are loaded only when a feature that uses one runs (an `import()` inside a `try`, whose error names the package to install), or named only in types.
|
|
143
|
+
|
|
144
|
+
`@geekmidas/cloud/sst`, `@geekmidas/cloud/dokploy` ship as TypeScript source for SST's loader, which provides the `@pulumi/*` packages, so they are not covered by the statement above.
|
|
145
|
+
|
|
146
|
+
<!-- optional-peers:end -->
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/cloud",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.171",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"lodash.snakecase": "~4.1.1",
|
|
44
|
-
"@geekmidas/envkit": "10.0.0-alpha.
|
|
45
|
-
"@geekmidas/manifest": "10.0.0-alpha.
|
|
44
|
+
"@geekmidas/envkit": "10.0.0-alpha.171",
|
|
45
|
+
"@geekmidas/manifest": "10.0.0-alpha.171"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/lodash.get": "~4.4.9",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"@pulumi/aws": ">=7.47.0",
|
|
59
59
|
"@pulumi/random": ">=4.21.2",
|
|
60
60
|
"@pulumi/pulumi": ">=3.263.0",
|
|
61
|
-
"@geekmidas/manifest": "
|
|
62
|
-
"@geekmidas/storage": "
|
|
63
|
-
"@geekmidas/events": "
|
|
64
|
-
"@geekmidas/db": "
|
|
61
|
+
"@geekmidas/manifest": ">=10.0.0-alpha.171 <10.0.0",
|
|
62
|
+
"@geekmidas/storage": ">=10.0.0-alpha.171 <10.0.0",
|
|
63
|
+
"@geekmidas/events": ">=10.0.0-alpha.171 <10.0.0",
|
|
64
|
+
"@geekmidas/db": ">=10.0.0-alpha.171 <10.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@geekmidas/manifest": {
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"scripts": {
|
|
93
93
|
"sst:install": "node -e \"process.exit(require('fs').existsSync('sst.config.ts')?0:1)\" && sst install || true",
|
|
94
|
-
"ts:check:sst": "tsc --noEmit -p src/sst/tsconfig.json 2>&1 | grep -E 'src/sst/.*error TS' && exit 1 || exit 0"
|
|
94
|
+
"ts:check:sst": "tsc --noEmit -p src/sst/tsconfig.json 2>&1 | grep -E 'src/sst/.*error TS' && exit 1 || exit 0",
|
|
95
|
+
"build": "tsdown --config ../../tsdown.config.ts --filter ."
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -183,49 +183,3 @@ describe('Api', () => {
|
|
|
183
183
|
expect(recorded(api).authorizers).toEqual([]);
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
|
-
|
|
187
|
-
describe('Api.fromManifest', () => {
|
|
188
|
-
it('turns built routes, flat or partitioned, into the route table', () => {
|
|
189
|
-
const routes = {
|
|
190
|
-
public: [
|
|
191
|
-
{
|
|
192
|
-
method: 'GET',
|
|
193
|
-
path: '/orders',
|
|
194
|
-
handler: '.gkm/aws-lambda/routes/orders.handler',
|
|
195
|
-
environment: ['DB_URL'],
|
|
196
|
-
authorizer: 'iam',
|
|
197
|
-
timeout: 30,
|
|
198
|
-
memorySize: 1024,
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
internal: [
|
|
202
|
-
{
|
|
203
|
-
method: 'POST',
|
|
204
|
-
path: '/jobs',
|
|
205
|
-
handler: '.gkm/aws-lambda/routes/jobs.handler',
|
|
206
|
-
environment: [],
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const api = Api.fromManifest(stack, 'Http', routes as never, {
|
|
212
|
-
links: [db],
|
|
213
|
-
});
|
|
214
|
-
const { routes: recordedRoutes } = recorded(api);
|
|
215
|
-
|
|
216
|
-
expect(recordedRoutes.map((r) => r.key)).toEqual([
|
|
217
|
-
'GET /orders',
|
|
218
|
-
'POST /jobs',
|
|
219
|
-
]);
|
|
220
|
-
expect(recordedRoutes[0]!.handler).toMatchObject({
|
|
221
|
-
timeout: '30 seconds',
|
|
222
|
-
memory: '1024 MB',
|
|
223
|
-
link: [db],
|
|
224
|
-
});
|
|
225
|
-
expect(recordedRoutes[0]!.args).toEqual({ auth: { iam: true } });
|
|
226
|
-
expect(recordedRoutes[1]!.handler).toMatchObject({
|
|
227
|
-
timeout: undefined,
|
|
228
|
-
memory: undefined,
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
@@ -113,6 +113,21 @@ describe('bootstrapEvent', () => {
|
|
|
113
113
|
expect(roleStatements(event.tenants[0]).length).toBeGreaterThan(0);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
it('carries a declared extension through to the DDL the master runs', () => {
|
|
117
|
+
// RDS ships PostGIS, but only the master may create it.
|
|
118
|
+
const event = JSON.parse(
|
|
119
|
+
bootstrapEvent(
|
|
120
|
+
master,
|
|
121
|
+
[{ ...tenant, extensions: ['postgis'] }],
|
|
122
|
+
passwords,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(roleStatements(event.tenants[0]).map((s) => s.sql)).toContain(
|
|
127
|
+
'CREATE EXTENSION IF NOT EXISTS "postgis" SCHEMA public',
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
116
131
|
it('carries a reader password only where a reader was named', () => {
|
|
117
132
|
const withReader = { ...tenant, reader: 'authdb_reader' };
|
|
118
133
|
const event = JSON.parse(
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ResourceType } from '@geekmidas/envkit/sst';
|
|
2
|
+
import { providedKeyFor } from '@geekmidas/manifest';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { Encryption } from '../aws/Encryption';
|
|
5
|
+
import { provisionerFor, resolveEdges } from '../fromManifest';
|
|
6
|
+
|
|
7
|
+
// A KMS key, as far as the component reads one: what it was created with, and
|
|
8
|
+
// an ARN. The SST globals are stubbed the same way for every component.
|
|
9
|
+
vi.mock('@pulumi/aws', () => ({
|
|
10
|
+
kms: {
|
|
11
|
+
Key: class {
|
|
12
|
+
readonly arn: string;
|
|
13
|
+
constructor(
|
|
14
|
+
readonly name: string,
|
|
15
|
+
readonly args: Record<string, unknown>,
|
|
16
|
+
) {
|
|
17
|
+
this.arn = `arn:aws:kms:eu-west-1:123456789012:key/${name}`;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const stack = {} as never;
|
|
24
|
+
|
|
25
|
+
describe('Encryption on AWS', () => {
|
|
26
|
+
it('is two KMS keys: one that rotates for data, one HMAC key for the index', () => {
|
|
27
|
+
const pii = new Encryption(stack, 'Pii', { region: 'eu-west-1' });
|
|
28
|
+
|
|
29
|
+
expect(pii.key).toMatchObject({
|
|
30
|
+
name: 'PiiKey',
|
|
31
|
+
args: { enableKeyRotation: true, deletionWindowInDays: 30 },
|
|
32
|
+
});
|
|
33
|
+
expect(pii.indexKey).toMatchObject({
|
|
34
|
+
name: 'PiiIndexKey',
|
|
35
|
+
args: {
|
|
36
|
+
keyUsage: 'GENERATE_VERIFY_MAC',
|
|
37
|
+
customerMasterKeySpec: 'HMAC_256',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('provides one kms:// URL, under the key the construct declared', () => {
|
|
43
|
+
const pii = new Encryption(stack, 'Pii', { region: 'eu-west-1' });
|
|
44
|
+
const url = new URL(pii.provides().url as string);
|
|
45
|
+
|
|
46
|
+
expect(url.protocol).toBe('kms:');
|
|
47
|
+
expect(url.hostname).toBe('eu-west-1');
|
|
48
|
+
expect(url.searchParams.get('key')).toBe(pii.key.arn);
|
|
49
|
+
expect(url.searchParams.get('index')).toBe(pii.indexKey.arn);
|
|
50
|
+
expect(
|
|
51
|
+
Object.keys(pii.provides()).map((role) =>
|
|
52
|
+
providedKeyFor('Pii', 'encryption', role),
|
|
53
|
+
),
|
|
54
|
+
).toEqual([providedKeyFor('Pii', 'encryption', 'url')]);
|
|
55
|
+
expect(pii._type).toBe(ResourceType.Encryption);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('grants a linked function the calls the cipher makes, on these keys only', () => {
|
|
59
|
+
const pii = new Encryption(stack, 'Pii', { region: 'eu-west-1' });
|
|
60
|
+
|
|
61
|
+
expect(pii.getSSTLink().include).toEqual([
|
|
62
|
+
{
|
|
63
|
+
permission: {
|
|
64
|
+
actions: ['kms:GenerateDataKey', 'kms:Decrypt'],
|
|
65
|
+
resources: [pii.key.arn],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
permission: {
|
|
70
|
+
actions: ['kms:GenerateMac'],
|
|
71
|
+
resources: [pii.indexKey.arn],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('is provisioned from the manifest in the stage’s region, and links its URL', () => {
|
|
78
|
+
const pii = provisionerFor('encryption')(
|
|
79
|
+
stack,
|
|
80
|
+
{ kind: 'encryption', id: 'Pii', provides: ['PII_URL'] },
|
|
81
|
+
{},
|
|
82
|
+
{} as never,
|
|
83
|
+
) as Encryption;
|
|
84
|
+
|
|
85
|
+
expect(new URL(pii.provides().url as string).hostname).toBe('eu-west-1');
|
|
86
|
+
expect(
|
|
87
|
+
resolveEdges([{ target: 'Pii', kind: 'encryption' }], { Pii: pii }),
|
|
88
|
+
).toEqual({ link: [pii], envKeys: ['PII_URL'] });
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { resolveEnvKeys } from '@geekmidas/envkit/sst';
|
|
2
|
+
import * as snsUrl from '@geekmidas/events/sns/url';
|
|
3
|
+
import { type ConstructManifest, providedKeyFor } from '@geekmidas/manifest';
|
|
4
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { type Inbox, InboxNotProvisioned, InboxTopic } from '../aws/Inbox';
|
|
6
|
+
import { Topic } from '../aws/Topic';
|
|
7
|
+
import { fromManifest } from '../fromManifest';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An inbox on SST: what receives the mail is its provider's, made before SST
|
|
11
|
+
* runs — so SST creates no topic for it, subscribes the inbox's Lambda to the
|
|
12
|
+
* provider's topic, and links the inbox's values the deploy handed it.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const stack = {} as never;
|
|
16
|
+
const TOPIC_ARN =
|
|
17
|
+
'arn:aws:sns:eu-west-1:123456789012:gkm-shop-production-requests';
|
|
18
|
+
const URL = 's3://AKIA:secret@shop-production-requests-mail?region=eu-west-1';
|
|
19
|
+
|
|
20
|
+
const external = (
|
|
21
|
+
globalThis as unknown as {
|
|
22
|
+
sst: {
|
|
23
|
+
aws: {
|
|
24
|
+
SnsTopic: {
|
|
25
|
+
external: {
|
|
26
|
+
name: string;
|
|
27
|
+
topicArn: unknown;
|
|
28
|
+
subscriber: { handler: string; link: unknown[] };
|
|
29
|
+
args: unknown;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
).sst.aws.SnsTopic.external;
|
|
36
|
+
|
|
37
|
+
function manifest(): ConstructManifest {
|
|
38
|
+
return {
|
|
39
|
+
Requests: {
|
|
40
|
+
kind: 'inbox',
|
|
41
|
+
id: 'Requests',
|
|
42
|
+
addresses: ['requests'],
|
|
43
|
+
subdomains: true,
|
|
44
|
+
topic: 'RequestsMail',
|
|
45
|
+
provides: ['REQUESTS_URL', 'REQUESTS_DOMAIN'],
|
|
46
|
+
},
|
|
47
|
+
RequestsMail: {
|
|
48
|
+
kind: 'topic',
|
|
49
|
+
id: 'RequestsMail',
|
|
50
|
+
events: ['email.received'],
|
|
51
|
+
provides: [
|
|
52
|
+
providedKeyFor('RequestsMail', 'topic', 'publisherConnectionString'),
|
|
53
|
+
],
|
|
54
|
+
subscribers: [
|
|
55
|
+
{
|
|
56
|
+
id: 'OnRequest',
|
|
57
|
+
handler: '.gkm/aws-lambda/subscribers/onRequest.handler',
|
|
58
|
+
dependencies: [{ target: 'Requests', kind: 'inbox' }],
|
|
59
|
+
events: [],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
// A topic of the app's own, beside it: still SST's to create.
|
|
64
|
+
Users: {
|
|
65
|
+
kind: 'topic',
|
|
66
|
+
id: 'Users',
|
|
67
|
+
events: ['user.created'],
|
|
68
|
+
provides: [providedKeyFor('Users', 'topic', 'publisherConnectionString')],
|
|
69
|
+
subscribers: [],
|
|
70
|
+
},
|
|
71
|
+
} as unknown as ConstructManifest;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const env = {
|
|
75
|
+
REQUESTS_URL: URL,
|
|
76
|
+
REQUESTS_DOMAIN: 'shop.example',
|
|
77
|
+
[providedKeyFor('RequestsMail', 'topic', 'publisherConnectionString')]:
|
|
78
|
+
snsUrl.build({
|
|
79
|
+
topicArn: TOPIC_ARN,
|
|
80
|
+
region: 'eu-west-1',
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
external.length = 0;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('an inbox on SST', () => {
|
|
89
|
+
it('references the provider’s topic instead of creating one', () => {
|
|
90
|
+
const provisioned = fromManifest(stack, manifest(), {
|
|
91
|
+
Requests: { env },
|
|
92
|
+
} as never);
|
|
93
|
+
|
|
94
|
+
expect(provisioned.RequestsMail).toBeInstanceOf(InboxTopic);
|
|
95
|
+
expect((provisioned.RequestsMail as unknown as InboxTopic).arn).toBe(
|
|
96
|
+
TOPIC_ARN,
|
|
97
|
+
);
|
|
98
|
+
expect(provisioned.Users).toBeInstanceOf(Topic);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('subscribes the inbox’s Lambda to that topic, unfiltered, linked to its inbox', () => {
|
|
102
|
+
const provisioned = fromManifest(stack, manifest(), {
|
|
103
|
+
Requests: { env },
|
|
104
|
+
} as never);
|
|
105
|
+
|
|
106
|
+
expect(external).toHaveLength(1);
|
|
107
|
+
const [subscription] = external;
|
|
108
|
+
expect(subscription).toMatchObject({
|
|
109
|
+
name: 'OnRequestSubscription',
|
|
110
|
+
topicArn: TOPIC_ARN,
|
|
111
|
+
subscriber: {
|
|
112
|
+
handler: '.gkm/aws-lambda/subscribers/onRequest.handler',
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
// No filter policy: SES's notification has no `type` to filter on.
|
|
116
|
+
expect(subscription!.args).toBeUndefined();
|
|
117
|
+
expect(subscription!.subscriber.link).toEqual([provisioned.Requests]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('hands the Lambda the inbox’s keys, with the deploy’s values', () => {
|
|
121
|
+
const provisioned = fromManifest(stack, manifest(), {
|
|
122
|
+
Requests: { env },
|
|
123
|
+
} as never);
|
|
124
|
+
const inbox = provisioned.Requests as unknown as Inbox;
|
|
125
|
+
|
|
126
|
+
expect(inbox.getSSTLink().properties).toEqual({
|
|
127
|
+
url: URL,
|
|
128
|
+
domain: 'shop.example',
|
|
129
|
+
});
|
|
130
|
+
expect(
|
|
131
|
+
resolveEnvKeys({ Requests: { type: inbox._type as string } }),
|
|
132
|
+
).toEqual(['REQUESTS_URL', 'REQUESTS_DOMAIN']);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('takes the values passed to it over the deploy’s', () => {
|
|
136
|
+
const provisioned = fromManifest(stack, manifest(), {
|
|
137
|
+
Requests: { env, domain: 'mail.shop.example' },
|
|
138
|
+
} as never);
|
|
139
|
+
|
|
140
|
+
expect((provisioned.Requests as unknown as Inbox).provides().domain).toBe(
|
|
141
|
+
'mail.shop.example',
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('fails naming the key when the provider has not made it', () => {
|
|
146
|
+
const partial = { ...env, REQUESTS_URL: undefined };
|
|
147
|
+
|
|
148
|
+
expect(() =>
|
|
149
|
+
fromManifest(stack, manifest(), { Requests: { env: partial } } as never),
|
|
150
|
+
).toThrow(InboxNotProvisioned);
|
|
151
|
+
try {
|
|
152
|
+
fromManifest(stack, manifest(), { Requests: { env: partial } } as never);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
expect((error as InboxNotProvisioned).key).toBe('REQUESTS_URL');
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
PUBLIC,
|
|
4
4
|
PUBLIC_PREFIX,
|
|
5
5
|
providedKeyFor,
|
|
6
|
+
schemeBase,
|
|
6
7
|
} from '@geekmidas/manifest';
|
|
7
8
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
8
9
|
import { DatabaseNeedsVpc } from '../aws/Database';
|
|
@@ -30,7 +31,7 @@ function manifest(): ConstructManifest {
|
|
|
30
31
|
kind: 'objects',
|
|
31
32
|
id: 'Uploads',
|
|
32
33
|
versioned: true,
|
|
33
|
-
provides: keys('Uploads', 'objects', ['
|
|
34
|
+
provides: keys('Uploads', 'objects', ['connectionString']),
|
|
34
35
|
},
|
|
35
36
|
Files: {
|
|
36
37
|
kind: 'file-server',
|
|
@@ -43,6 +44,12 @@ function manifest(): ConstructManifest {
|
|
|
43
44
|
id: 'Emails',
|
|
44
45
|
fifo: true,
|
|
45
46
|
provides: keys('Emails', 'queue', ['publisherConnectionString']),
|
|
47
|
+
// The queue's one consumer, as the build folds it in.
|
|
48
|
+
worker: {
|
|
49
|
+
id: 'EmailsWorker',
|
|
50
|
+
handler: '.gkm/aws-lambda/queues/emails.handler',
|
|
51
|
+
dependencies: [{ target: 'Uploads', kind: 'objects' }],
|
|
52
|
+
},
|
|
46
53
|
},
|
|
47
54
|
Users: {
|
|
48
55
|
kind: 'topic',
|
|
@@ -86,7 +93,7 @@ function manifest(): ConstructManifest {
|
|
|
86
93
|
dependencies: [],
|
|
87
94
|
},
|
|
88
95
|
],
|
|
89
|
-
|
|
96
|
+
auth: { target: 'Auth', kind: 'rest-api' },
|
|
90
97
|
provides: keys('Api', 'rest-api', SURFACE),
|
|
91
98
|
},
|
|
92
99
|
Auth: {
|
|
@@ -171,6 +178,27 @@ describe('fromManifest', () => {
|
|
|
171
178
|
expect(argsOf(provisioned.Orders)).toMatchObject({ vpc, version: '18' });
|
|
172
179
|
});
|
|
173
180
|
|
|
181
|
+
it('subscribes each queue’s one consumer, linked to the queue and what it reaches', () => {
|
|
182
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
183
|
+
|
|
184
|
+
const provisioned = fromManifest(stack, manifest(), overrides, {
|
|
185
|
+
cache: 'db',
|
|
186
|
+
email: 'smtp',
|
|
187
|
+
});
|
|
188
|
+
const { subscribed } = provisioned.Emails as unknown as {
|
|
189
|
+
subscribed: { subscriber: { handler: string; link: unknown[] } }[];
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
expect(subscribed).toHaveLength(1);
|
|
193
|
+
expect(subscribed[0]?.subscriber.handler).toBe(
|
|
194
|
+
'.gkm/aws-lambda/queues/emails.handler',
|
|
195
|
+
);
|
|
196
|
+
expect(subscribed[0]?.subscriber.link).toEqual([
|
|
197
|
+
provisioned.Emails,
|
|
198
|
+
provisioned.Uploads,
|
|
199
|
+
]);
|
|
200
|
+
});
|
|
201
|
+
|
|
174
202
|
it('builds the site against the addresses its edges resolve to', () => {
|
|
175
203
|
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
176
204
|
|
|
@@ -217,6 +245,37 @@ describe('fromManifest', () => {
|
|
|
217
245
|
);
|
|
218
246
|
});
|
|
219
247
|
|
|
248
|
+
it('builds nothing for a mobile app, and has the surfaces it calls trust its scheme', async () => {
|
|
249
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
250
|
+
|
|
251
|
+
const provisioned = fromManifest(
|
|
252
|
+
stack,
|
|
253
|
+
{
|
|
254
|
+
...manifest(),
|
|
255
|
+
App: {
|
|
256
|
+
kind: 'mobile-app',
|
|
257
|
+
id: 'App',
|
|
258
|
+
variant: 'expo',
|
|
259
|
+
app: { path: 'apps/app' },
|
|
260
|
+
dependencies: [{ target: 'Auth', kind: 'rest-api' }],
|
|
261
|
+
provides: ['APP_SCHEME'],
|
|
262
|
+
},
|
|
263
|
+
} as ConstructManifest,
|
|
264
|
+
overrides,
|
|
265
|
+
{ cache: 'db' },
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// EAS and the stores ship it — this stack has nothing to create for it.
|
|
269
|
+
expect(provisioned.App).toBeUndefined();
|
|
270
|
+
const origins = String(
|
|
271
|
+
await settle(provisioned.Auth!.provides().trustedOrigins),
|
|
272
|
+
).split(',');
|
|
273
|
+
// The bare scheme deployed: the one the store build registers.
|
|
274
|
+
const scheme = `${schemeBase($app.name)}://`;
|
|
275
|
+
expect(origins).toContain(scheme);
|
|
276
|
+
expect(origins).toContain(`${scheme}*`);
|
|
277
|
+
});
|
|
278
|
+
|
|
220
279
|
it('prints every route and exactly what it can reach', () => {
|
|
221
280
|
const log = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
222
281
|
|
|
@@ -229,7 +288,7 @@ describe('fromManifest', () => {
|
|
|
229
288
|
'Api:',
|
|
230
289
|
' GET /orders → Orders (database)',
|
|
231
290
|
' GET /health → nothing',
|
|
232
|
-
'
|
|
291
|
+
' auth Auth (origin only; grants nothing)',
|
|
233
292
|
'Auth:',
|
|
234
293
|
' (no routes)',
|
|
235
294
|
]);
|
|
@@ -296,6 +355,31 @@ describe('fromManifest', () => {
|
|
|
296
355
|
});
|
|
297
356
|
});
|
|
298
357
|
|
|
358
|
+
it('generates a secret rather than waiting for one to be set', () => {
|
|
359
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
360
|
+
const provisioned = fromManifest(stack, manifest(), overrides, {
|
|
361
|
+
cache: 'db',
|
|
362
|
+
email: 'smtp',
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// Without a placeholder, the stub stands in for `SecretMissingError`.
|
|
366
|
+
expect(provisioned.AuthSecret!.provides().value).not.toBe(
|
|
367
|
+
'stub-secret-AuthSecret',
|
|
368
|
+
);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('keeps a secret’s placeholder over the generated one', () => {
|
|
372
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
373
|
+
const provisioned = fromManifest(
|
|
374
|
+
stack,
|
|
375
|
+
manifest(),
|
|
376
|
+
{ ...overrides, AuthSecret: { placeholder: 'chosen' } },
|
|
377
|
+
{ cache: 'db', email: 'smtp' },
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
expect(provisioned.AuthSecret!.provides().value).toBe('chosen');
|
|
381
|
+
});
|
|
382
|
+
|
|
299
383
|
it('takes an existing cache and mailer rather than creating them', async () => {
|
|
300
384
|
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
301
385
|
const provisioned = fromManifest(
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ConstructManifest } from '@geekmidas/manifest';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { fromManifest } from '../fromManifest';
|
|
4
|
+
|
|
5
|
+
/** What each `RandomPassword` was asked for, by name. */
|
|
6
|
+
const drawn = vi.hoisted(() => new Map<string, unknown[]>());
|
|
7
|
+
|
|
8
|
+
vi.mock('@pulumi/random', () => ({
|
|
9
|
+
RandomPassword: class {
|
|
10
|
+
readonly result: string;
|
|
11
|
+
constructor(name: string, ...rest: unknown[]) {
|
|
12
|
+
drawn.set(name, rest);
|
|
13
|
+
this.result = `generated-${name}`;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const provision = (manifest: ConstructManifest) => {
|
|
19
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
20
|
+
return fromManifest({} as never, manifest, {}, {});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('a secret on AWS', () => {
|
|
24
|
+
it('is generated in the format it declares, kept when the format changes', () => {
|
|
25
|
+
const provisioned = provision({
|
|
26
|
+
RouterPassword: {
|
|
27
|
+
kind: 'secret',
|
|
28
|
+
id: 'RouterPassword',
|
|
29
|
+
provides: ['ROUTER_PASSWORD'],
|
|
30
|
+
length: 24,
|
|
31
|
+
symbols: '!@#',
|
|
32
|
+
},
|
|
33
|
+
} as unknown as ConstructManifest);
|
|
34
|
+
|
|
35
|
+
expect(provisioned.RouterPassword!.provides().value).toBe(
|
|
36
|
+
'generated-RouterPasswordGenerated',
|
|
37
|
+
);
|
|
38
|
+
expect(drawn.get('RouterPasswordGenerated')).toEqual([
|
|
39
|
+
{ length: 24, special: true, overrideSpecial: '!@#', minSpecial: 1 },
|
|
40
|
+
{
|
|
41
|
+
ignoreChanges: ['length', 'special', 'overrideSpecial', 'minSpecial'],
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('is 43 letters, digits, - and _ by default', () => {
|
|
47
|
+
provision({
|
|
48
|
+
AuthSecret: {
|
|
49
|
+
kind: 'secret',
|
|
50
|
+
id: 'AuthSecret',
|
|
51
|
+
provides: ['AUTH_SECRET'],
|
|
52
|
+
},
|
|
53
|
+
} as unknown as ConstructManifest);
|
|
54
|
+
|
|
55
|
+
expect(drawn.get('AuthSecretGenerated')?.[0]).toEqual({
|
|
56
|
+
length: 43,
|
|
57
|
+
special: true,
|
|
58
|
+
overrideSpecial: '-_',
|
|
59
|
+
minSpecial: 1,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('draws no symbols when told none', () => {
|
|
64
|
+
provision({
|
|
65
|
+
Token: {
|
|
66
|
+
kind: 'secret',
|
|
67
|
+
id: 'Token',
|
|
68
|
+
provides: ['TOKEN'],
|
|
69
|
+
length: 6,
|
|
70
|
+
symbols: '',
|
|
71
|
+
},
|
|
72
|
+
} as unknown as ConstructManifest);
|
|
73
|
+
|
|
74
|
+
expect(drawn.get('TokenGenerated')?.[0]).toEqual({
|
|
75
|
+
length: 6,
|
|
76
|
+
special: false,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|