@geekmidas/cloud 10.0.0-alpha.13 → 10.0.0-alpha.131
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 +14 -6
- package/package.json +9 -8
- package/src/dokploy/Application.ts +45 -5
- package/src/dokploy/__tests__/Application.provider.spec.ts +62 -4
- package/src/sst/__tests__/api.spec.ts +2 -47
- package/src/sst/__tests__/bootstrap.spec.ts +15 -0
- package/src/sst/__tests__/encryption.spec.ts +90 -0
- package/src/sst/__tests__/fromManifest.integration.spec.ts +84 -0
- package/src/sst/__tests__/fromManifest.secret.spec.ts +79 -0
- package/src/sst/__tests__/fromManifest.spec.ts +379 -5
- package/src/sst/__tests__/function.spec.ts +0 -71
- package/src/sst/__tests__/surfaces.spec.ts +17 -0
- package/src/sst/__type-tests__/overrides.type-test.ts +152 -0
- package/src/sst/aws/Api.ts +16 -44
- 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/Queue.ts +34 -1
- package/src/sst/aws/RestApiSurface.ts +36 -14
- package/src/sst/aws/Secret.ts +5 -3
- package/src/sst/aws/bootstrap/handler.ts +12 -1
- package/src/sst/fromManifest.ts +352 -43
- package/src/sst/index.ts +6 -1
- package/src/sst/overrides.ts +133 -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
|
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.131",
|
|
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/
|
|
45
|
-
"@geekmidas/
|
|
44
|
+
"@geekmidas/manifest": "10.0.0-alpha.131",
|
|
45
|
+
"@geekmidas/envkit": "10.0.0-alpha.131"
|
|
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": "^10.0.0-alpha.
|
|
62
|
-
"@geekmidas/storage": "^10.0.0-alpha.
|
|
63
|
-
"@geekmidas/events": "^10.0.0-alpha.
|
|
64
|
-
"@geekmidas/db": "^10.0.0-alpha.
|
|
61
|
+
"@geekmidas/manifest": "^10.0.0-alpha.131",
|
|
62
|
+
"@geekmidas/storage": "^10.0.0-alpha.131",
|
|
63
|
+
"@geekmidas/events": "^10.0.0-alpha.131",
|
|
64
|
+
"@geekmidas/db": "^10.0.0-alpha.131"
|
|
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
|
}
|
|
@@ -195,6 +195,45 @@ const provider: dynamic.ResourceProvider<
|
|
|
195
195
|
},
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* A Dokploy API call that answered with an error status.
|
|
200
|
+
*
|
|
201
|
+
* Defined here, beside the provider, rather than imported: the provider's
|
|
202
|
+
* functions are serialised into state, and Pulumi's closure serialiser
|
|
203
|
+
* captures a class declared in the same module by value — once, shared by
|
|
204
|
+
* every function that refers to it, so `instanceof` still holds in the
|
|
205
|
+
* deployed provider. An imported class would have to be resolvable as a
|
|
206
|
+
* module where the provider runs, which is the obscure failure the note on
|
|
207
|
+
* `call` below is about.
|
|
208
|
+
*
|
|
209
|
+
* Serialisation rewrites the class into a plain function and drops its link to
|
|
210
|
+
* `Error.prototype`, so the constructor sets `message` and `stack` itself and
|
|
211
|
+
* the class says how to print itself. `Application.provider.spec.ts` runs the
|
|
212
|
+
* serialised provider to keep all of this true.
|
|
213
|
+
*/
|
|
214
|
+
export class DokployCallFailed extends Error {
|
|
215
|
+
constructor(
|
|
216
|
+
readonly path: string,
|
|
217
|
+
readonly status: number,
|
|
218
|
+
readonly statusText: string,
|
|
219
|
+
readonly detail: string,
|
|
220
|
+
) {
|
|
221
|
+
const message = `Dokploy ${path} failed: ${status} ${statusText}${detail ? ` — ${detail}` : ''}. Check the endpoint and API token, and Dokploy's own logs for the request.`;
|
|
222
|
+
super(message);
|
|
223
|
+
// Serialised, this constructor becomes a plain function whose super call
|
|
224
|
+
// does not initialise `this`: without these the provider host, which
|
|
225
|
+
// reports `e.message` and logs `${e}: ${e.stack}`, would show nothing.
|
|
226
|
+
this.message = message;
|
|
227
|
+
Error.captureStackTrace?.(this, DokployCallFailed);
|
|
228
|
+
this.name = 'DokployCallFailed';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** What `${error}` prints once serialisation has dropped Error's own. */
|
|
232
|
+
override toString(): string {
|
|
233
|
+
return `${this.name}: ${this.message}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
198
237
|
/**
|
|
199
238
|
* One call to Dokploy.
|
|
200
239
|
*
|
|
@@ -218,10 +257,11 @@ async function call<T>(
|
|
|
218
257
|
|
|
219
258
|
if (!response.ok) {
|
|
220
259
|
const detail = await response.text().catch(() => '');
|
|
221
|
-
throw new
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
260
|
+
throw new DokployCallFailed(
|
|
261
|
+
path,
|
|
262
|
+
response.status,
|
|
263
|
+
response.statusText,
|
|
264
|
+
detail,
|
|
225
265
|
);
|
|
226
266
|
}
|
|
227
267
|
|
|
@@ -230,7 +270,7 @@ async function call<T>(
|
|
|
230
270
|
|
|
231
271
|
/** Whether an error means the thing is already absent. */
|
|
232
272
|
function isNotFound(error: unknown): boolean {
|
|
233
|
-
return error instanceof
|
|
273
|
+
return error instanceof DokployCallFailed && error.status === 404;
|
|
234
274
|
}
|
|
235
275
|
|
|
236
276
|
export interface ApplicationArgs {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { runtime } from '@pulumi/pulumi';
|
|
1
3
|
import { HttpResponse, http } from 'msw';
|
|
2
4
|
import { setupServer } from 'msw/node';
|
|
3
5
|
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
DokployCallFailed,
|
|
8
|
+
applicationProvider as provider,
|
|
9
|
+
} from '../Application';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* The provider against Dokploy's tRPC API, served by MSW: what each lifecycle
|
|
@@ -132,8 +137,13 @@ describe('Dokploy application provider', () => {
|
|
|
132
137
|
}),
|
|
133
138
|
);
|
|
134
139
|
await expect(provider.delete!('app-1', outs)).rejects.toThrow(
|
|
135
|
-
|
|
140
|
+
DokployCallFailed,
|
|
136
141
|
);
|
|
142
|
+
await expect(provider.delete!('app-1', outs)).rejects.toMatchObject({
|
|
143
|
+
path: 'application.remove',
|
|
144
|
+
status: 500,
|
|
145
|
+
detail: 'database is locked',
|
|
146
|
+
});
|
|
137
147
|
|
|
138
148
|
server.resetHandlers();
|
|
139
149
|
answer(
|
|
@@ -141,8 +151,56 @@ describe('Dokploy application provider', () => {
|
|
|
141
151
|
'application.create',
|
|
142
152
|
() => new HttpResponse(null, { status: 401, statusText: 'Unauthorized' }),
|
|
143
153
|
);
|
|
144
|
-
await expect(provider.create!(inputs)).rejects.
|
|
145
|
-
|
|
154
|
+
await expect(provider.create!(inputs)).rejects.toMatchObject({
|
|
155
|
+
name: 'DokployCallFailed',
|
|
156
|
+
status: 401,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* What actually runs: Pulumi serialises the provider into state and the
|
|
162
|
+
* deploy runs that text, not this module. Serialisation rewrites
|
|
163
|
+
* `DokployCallFailed` into a plain function that drops `Error.prototype` and
|
|
164
|
+
* never initialises `message` — which the provider host reports — so this
|
|
165
|
+
* runs the serialised provider and checks the error still says something.
|
|
166
|
+
*/
|
|
167
|
+
it('still recognises a 404, and reports a failure, once serialised', async () => {
|
|
168
|
+
const serialised = await runtime.serializeFunction(() => provider, {
|
|
169
|
+
isFactoryFunction: true,
|
|
170
|
+
});
|
|
171
|
+
const module = { exports: {} as Record<string, typeof provider> };
|
|
172
|
+
runInNewContext(serialised.text, {
|
|
173
|
+
module,
|
|
174
|
+
exports: module.exports,
|
|
175
|
+
require,
|
|
176
|
+
global: globalThis,
|
|
177
|
+
fetch: (...args: Parameters<typeof fetch>) => fetch(...args),
|
|
178
|
+
Error,
|
|
179
|
+
});
|
|
180
|
+
const deployed = module.exports[serialised.exportName]!;
|
|
181
|
+
|
|
182
|
+
answer('post', 'application.remove', () =>
|
|
183
|
+
HttpResponse.json({}, { status: 404, statusText: 'Not Found' }),
|
|
184
|
+
);
|
|
185
|
+
await expect(deployed.delete!('app-1', outs)).resolves.toBeUndefined();
|
|
186
|
+
|
|
187
|
+
server.resetHandlers();
|
|
188
|
+
answer('post', 'application.remove', () =>
|
|
189
|
+
HttpResponse.text('database is locked', {
|
|
190
|
+
status: 500,
|
|
191
|
+
statusText: 'Internal Server Error',
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
const failure = await deployed.delete!('app-1', outs).catch(
|
|
195
|
+
(error: unknown) => error as Error & { status: number },
|
|
196
|
+
);
|
|
197
|
+
expect(failure).toMatchObject({ name: 'DokployCallFailed', status: 500 });
|
|
198
|
+
expect(failure?.message).toContain(
|
|
199
|
+
'Dokploy application.remove failed: 500 Internal Server Error — database is locked',
|
|
200
|
+
);
|
|
201
|
+
expect(failure?.stack).toBeTruthy();
|
|
202
|
+
expect(`${failure}`).toMatch(
|
|
203
|
+
/^DokployCallFailed: Dokploy application\.remove failed/,
|
|
146
204
|
);
|
|
147
205
|
});
|
|
148
206
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { App } from '../App';
|
|
3
|
-
import { Api } from '../aws/Api';
|
|
3
|
+
import { Api, RoutesMissingEnvironment } from '../aws/Api';
|
|
4
4
|
import { type GkmLinkable, ResourceType } from '../Linkable';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -167,6 +167,7 @@ describe('Api', () => {
|
|
|
167
167
|
],
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
expect(build).toThrow(RoutesMissingEnvironment);
|
|
170
171
|
expect(build).toThrow(/Http POST \/pay[\s\S]*STRIPE_KEY/);
|
|
171
172
|
expect(build).toThrow(/Http GET \/mail[\s\S]*SMTP_URL/);
|
|
172
173
|
});
|
|
@@ -182,49 +183,3 @@ describe('Api', () => {
|
|
|
182
183
|
expect(recorded(api).authorizers).toEqual([]);
|
|
183
184
|
});
|
|
184
185
|
});
|
|
185
|
-
|
|
186
|
-
describe('Api.fromManifest', () => {
|
|
187
|
-
it('turns built routes, flat or partitioned, into the route table', () => {
|
|
188
|
-
const routes = {
|
|
189
|
-
public: [
|
|
190
|
-
{
|
|
191
|
-
method: 'GET',
|
|
192
|
-
path: '/orders',
|
|
193
|
-
handler: '.gkm/aws-lambda/routes/orders.handler',
|
|
194
|
-
environment: ['DB_URL'],
|
|
195
|
-
authorizer: 'iam',
|
|
196
|
-
timeout: 30,
|
|
197
|
-
memorySize: 1024,
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
internal: [
|
|
201
|
-
{
|
|
202
|
-
method: 'POST',
|
|
203
|
-
path: '/jobs',
|
|
204
|
-
handler: '.gkm/aws-lambda/routes/jobs.handler',
|
|
205
|
-
environment: [],
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const api = Api.fromManifest(stack, 'Http', routes as never, {
|
|
211
|
-
links: [db],
|
|
212
|
-
});
|
|
213
|
-
const { routes: recordedRoutes } = recorded(api);
|
|
214
|
-
|
|
215
|
-
expect(recordedRoutes.map((r) => r.key)).toEqual([
|
|
216
|
-
'GET /orders',
|
|
217
|
-
'POST /jobs',
|
|
218
|
-
]);
|
|
219
|
-
expect(recordedRoutes[0]!.handler).toMatchObject({
|
|
220
|
-
timeout: '30 seconds',
|
|
221
|
-
memory: '1024 MB',
|
|
222
|
-
link: [db],
|
|
223
|
-
});
|
|
224
|
-
expect(recordedRoutes[0]!.args).toEqual({ auth: { iam: true } });
|
|
225
|
-
expect(recordedRoutes[1]!.handler).toMatchObject({
|
|
226
|
-
timeout: undefined,
|
|
227
|
-
memory: undefined,
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
});
|
|
@@ -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, provideKey } 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([provideKey('Pii', '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
|
+
});
|
|
@@ -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';
|
|
@@ -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',
|
|
@@ -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
|
|
|
@@ -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
|
+
});
|