@toa.io/extensions.configuration 1.0.0-alpha.28 → 1.0.0-alpha.281
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 +340 -0
- package/components/configuration.values/manifest.toa.yaml +158 -0
- package/components/configuration.values/operations/create.d.ts +16 -0
- package/components/configuration.values/operations/create.js +31 -0
- package/components/configuration.values/operations/create.js.map +1 -0
- package/components/configuration.values/operations/fetch.d.ts +11 -0
- package/components/configuration.values/operations/fetch.js +13 -0
- package/components/configuration.values/operations/fetch.js.map +1 -0
- package/components/configuration.values/operations/get.d.ts +17 -0
- package/components/configuration.values/operations/get.js +19 -0
- package/components/configuration.values/operations/get.js.map +1 -0
- package/components/configuration.values/operations/lib/map.d.ts +11 -0
- package/components/configuration.values/operations/lib/map.js +21 -0
- package/components/configuration.values/operations/lib/map.js.map +1 -0
- package/components/configuration.values/operations/lib/map.test.d.ts +1 -0
- package/components/configuration.values/operations/lib/map.test.js +26 -0
- package/components/configuration.values/operations/lib/map.test.js.map +1 -0
- package/components/configuration.values/operations/lib/resolve.d.ts +27 -0
- package/components/configuration.values/operations/lib/resolve.js +24 -0
- package/components/configuration.values/operations/lib/resolve.js.map +1 -0
- package/components/configuration.values/operations/list.d.ts +10 -0
- package/components/configuration.values/operations/list.js +11 -0
- package/components/configuration.values/operations/list.js.map +1 -0
- package/components/configuration.values/source/create.ts +56 -0
- package/components/configuration.values/source/fetch.ts +24 -0
- package/components/configuration.values/source/get.ts +33 -0
- package/components/configuration.values/source/lib/map.test.ts +37 -0
- package/components/configuration.values/source/lib/map.ts +34 -0
- package/components/configuration.values/source/lib/resolve.ts +54 -0
- package/components/configuration.values/source/list.ts +19 -0
- package/components/configuration.values/tsconfig.json +10 -0
- package/components/configuration.values/tsconfig.tsbuildinfo +1 -0
- package/cucumber.mjs +5 -0
- package/features/site/_app/immutable/asset.js +1 -0
- package/features/site/favicon.ico +0 -0
- package/features/site/index.html +6 -0
- package/features/steps/UI.ts +91 -0
- package/features/steps/tsconfig.json +9 -0
- package/features/ui.feature +93 -0
- package/package.json +11 -10
- package/readme.md +160 -47
- package/schemas/annotation.cos.yaml +29 -1
- package/schemas/manifest.cos.yaml +9 -2
- package/source/Aspect.test.ts +89 -9
- package/source/Aspect.ts +64 -5
- package/source/Client.test.ts +108 -0
- package/source/Client.ts +258 -0
- package/source/Composition.ts +57 -0
- package/source/Factory.ts +29 -6
- package/source/Secret.test.ts +32 -0
- package/source/Secret.ts +29 -0
- package/source/UI.ts +212 -0
- package/source/configuration.test.ts +96 -40
- package/source/configuration.ts +30 -11
- package/source/const.ts +17 -0
- package/source/deployment.test.ts +78 -12
- package/source/deployment.ts +75 -27
- package/source/epoch.test.ts +29 -0
- package/source/epoch.ts +21 -0
- package/source/index.ts +4 -3
- package/source/manifest.test.ts +8 -5
- package/source/manifest.ts +2 -4
- package/source/schemas.ts +1 -1
- package/transpiled/Aspect.d.ts +18 -4
- package/transpiled/Aspect.js +50 -9
- package/transpiled/Aspect.js.map +1 -1
- package/transpiled/Aspect.test.js +63 -12
- package/transpiled/Aspect.test.js.map +1 -1
- package/transpiled/Client.d.ts +61 -0
- package/transpiled/Client.js +169 -0
- package/transpiled/Client.js.map +1 -0
- package/transpiled/Client.test.d.ts +1 -0
- package/transpiled/Client.test.js +78 -0
- package/transpiled/Client.test.js.map +1 -0
- package/transpiled/Composition.d.ts +14 -0
- package/transpiled/Composition.js +38 -0
- package/transpiled/Composition.js.map +1 -0
- package/transpiled/Factory.d.ts +8 -2
- package/transpiled/Factory.js +20 -9
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Secret.d.ts +12 -0
- package/transpiled/Secret.js +22 -0
- package/transpiled/Secret.js.map +1 -0
- package/transpiled/Secret.test.d.ts +1 -0
- package/transpiled/Secret.test.js +26 -0
- package/transpiled/Secret.test.js.map +1 -0
- package/transpiled/UI.d.ts +25 -0
- package/transpiled/UI.js +172 -0
- package/transpiled/UI.js.map +1 -0
- package/transpiled/configuration.d.ts +7 -2
- package/transpiled/configuration.js +30 -41
- package/transpiled/configuration.js.map +1 -1
- package/transpiled/configuration.test.js +90 -43
- package/transpiled/configuration.test.js.map +1 -1
- package/transpiled/const.d.ts +11 -0
- package/transpiled/const.js +11 -0
- package/transpiled/const.js.map +1 -0
- package/transpiled/deployment.d.ts +9 -3
- package/transpiled/deployment.js +62 -57
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/deployment.test.js +61 -13
- package/transpiled/deployment.test.js.map +1 -1
- package/transpiled/epoch.d.ts +2 -0
- package/transpiled/epoch.js +17 -0
- package/transpiled/epoch.js.map +1 -0
- package/transpiled/epoch.test.d.ts +1 -0
- package/transpiled/epoch.test.js +22 -0
- package/transpiled/epoch.test.js.map +1 -0
- package/transpiled/index.d.ts +4 -3
- package/transpiled/index.js +4 -9
- package/transpiled/index.js.map +1 -1
- package/transpiled/manifest.d.ts +1 -1
- package/transpiled/manifest.js +2 -31
- package/transpiled/manifest.js.map +1 -1
- package/transpiled/manifest.test.js +9 -9
- package/transpiled/manifest.test.js.map +1 -1
- package/transpiled/schemas.js +5 -31
- package/transpiled/schemas.js.map +1 -1
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -0
- package/ui/dist/_app/env.js +1 -0
- package/ui/dist/_app/immutable/assets/0.CNS8Cqhc.css +2 -0
- package/ui/dist/_app/immutable/assets/inter-cyrillic-ext-wght-normal.BOeWTOD4.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-cyrillic-wght-normal.DqGufNeO.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-greek-ext-wght-normal.DlzME5K_.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-greek-wght-normal.CkhJZR-_.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-latin-ext-wght-normal.DO1Apj_S.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-latin-wght-normal.Dx4kXJAl.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/inter-vietnamese-wght-normal.CBcvBZtf.woff2 +0 -0
- package/ui/dist/_app/immutable/assets/ui.BghF56l_.css +1 -0
- package/ui/dist/_app/immutable/chunks/BBRsRBKl.js +6 -0
- package/ui/dist/_app/immutable/chunks/BBjoSbGn.js +8 -0
- package/ui/dist/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/ui/dist/_app/immutable/chunks/Bzfl3Xp_.js +1 -0
- package/ui/dist/_app/immutable/chunks/C6nSKt5F.js +50 -0
- package/ui/dist/_app/immutable/chunks/CcD_ISxM.js +3 -0
- package/ui/dist/_app/immutable/chunks/DWNBcI-9.js +1 -0
- package/ui/dist/_app/immutable/chunks/xihTtKlq.js +1 -0
- package/ui/dist/_app/immutable/entry/app.Dr8IgX3r.js +2 -0
- package/ui/dist/_app/immutable/entry/start.Dy9qIspC.js +1 -0
- package/ui/dist/_app/immutable/nodes/0.zxJ_VvIF.js +1 -0
- package/ui/dist/_app/immutable/nodes/1.DasPjSN2.js +1 -0
- package/ui/dist/_app/immutable/nodes/2.9VqQT6jB.js +1 -0
- package/ui/dist/_app/immutable/nodes/3.D8a8RCsW.js +1 -0
- package/ui/dist/_app/immutable/nodes/4.y19mXraP.js +1 -0
- package/ui/dist/_app/version.json +1 -0
- package/ui/dist/apple-touch-icon.png +0 -0
- package/ui/dist/favicon-96x96.png +0 -0
- package/ui/dist/favicon.ico +0 -0
- package/ui/dist/index.html +52 -0
- package/ui/dist/robots.txt +3 -0
- package/transpiled/tsconfig.tsbuildinfo +0 -1
package/transpiled/UI.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as http from 'node:http';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { Connector } from '@toa.io/core';
|
|
5
|
+
import { console } from 'openspan';
|
|
6
|
+
import { UI_PATH } from './const.js';
|
|
7
|
+
/**
|
|
8
|
+
* Serves the configuration UI: the directory `ui` builds, and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* The page is a single-page application whose mount path is baked into the bundle,
|
|
11
|
+
* so this server routes relative to `UI_PATH` — which is also what the ingress
|
|
12
|
+
* forwards. `/configuration/*` is left alone: that is the component's own API.
|
|
13
|
+
*/
|
|
14
|
+
export class UI extends Connector {
|
|
15
|
+
server = http.createServer();
|
|
16
|
+
port;
|
|
17
|
+
root;
|
|
18
|
+
constructor(port, root = SITE) {
|
|
19
|
+
super();
|
|
20
|
+
this.port = port;
|
|
21
|
+
this.root = root;
|
|
22
|
+
this.server.on('request', (request, response) => {
|
|
23
|
+
this.listen(request, response);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async open() {
|
|
27
|
+
/*
|
|
28
|
+
* A taken port is a real error: uniqueness across services is settled at export
|
|
29
|
+
* time, so nothing here has to negotiate for one.
|
|
30
|
+
*/
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const failed = (error) => {
|
|
33
|
+
this.server.off('listening', listening);
|
|
34
|
+
reject(error);
|
|
35
|
+
};
|
|
36
|
+
const listening = () => {
|
|
37
|
+
this.server.off('error', failed);
|
|
38
|
+
resolve();
|
|
39
|
+
};
|
|
40
|
+
this.server.once('error', failed);
|
|
41
|
+
this.server.once('listening', listening);
|
|
42
|
+
this.server.listen(this.port);
|
|
43
|
+
});
|
|
44
|
+
if (!isFile(path.join(this.root, 'index.html')))
|
|
45
|
+
console.warn('Configuration UI is not built', { root: this.root });
|
|
46
|
+
console.info('Configuration UI started', { port: this.port, path: UI_PATH + '/' });
|
|
47
|
+
}
|
|
48
|
+
async close() {
|
|
49
|
+
const closed = new Promise((resolve) => this.server.once('close', () => {
|
|
50
|
+
resolve();
|
|
51
|
+
}));
|
|
52
|
+
this.server.close();
|
|
53
|
+
this.server.closeAllConnections();
|
|
54
|
+
await closed;
|
|
55
|
+
}
|
|
56
|
+
listen(request, response) {
|
|
57
|
+
void this.respond(request, response).catch((error) => {
|
|
58
|
+
console.error('Configuration UI failure', { message: error.message });
|
|
59
|
+
if (!response.writableEnded)
|
|
60
|
+
response.writeHead(500).end();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async respond(request, response) {
|
|
64
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
65
|
+
response.writeHead(405, { allow: 'GET, HEAD' }).end();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const pathname = decode(request.url ?? '/');
|
|
69
|
+
if (pathname === null) {
|
|
70
|
+
response.writeHead(400).end();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// the port is the explorer's alone, so the root is the way in
|
|
74
|
+
if (pathname === '/') {
|
|
75
|
+
response.writeHead(302, { location: UI_PATH + '/' }).end();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const file = this.resolve(pathname);
|
|
79
|
+
if (file === null)
|
|
80
|
+
response.writeHead(404).end();
|
|
81
|
+
else
|
|
82
|
+
await this.send(file, request, response);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The file a request lands on, or `null` when nothing does. A path that exists is
|
|
86
|
+
* served as it is; anything else that could be a route falls back to the page,
|
|
87
|
+
* because the client router — not this server — knows what routes there are.
|
|
88
|
+
*/
|
|
89
|
+
resolve(pathname) {
|
|
90
|
+
if (!pathname.startsWith(UI_PATH))
|
|
91
|
+
return null;
|
|
92
|
+
const relative = pathname.slice(UI_PATH.length);
|
|
93
|
+
if (relative !== '' && !relative.startsWith('/'))
|
|
94
|
+
return null;
|
|
95
|
+
const file = path.join(this.root, relative);
|
|
96
|
+
if (file !== this.root && !file.startsWith(this.root + path.sep))
|
|
97
|
+
return null;
|
|
98
|
+
if (isFile(file))
|
|
99
|
+
return file;
|
|
100
|
+
/*
|
|
101
|
+
* A missing asset is missing, but a route can look like one: `identity.passkeys` is a
|
|
102
|
+
* component, not a file with an extension. What this server would have served is what
|
|
103
|
+
* it knows how to serve, so anything else is a route and falls back to the page — as
|
|
104
|
+
* does anything ending in a slash, which is no name for a file at all.
|
|
105
|
+
*/
|
|
106
|
+
const asset = !relative.endsWith('/') && path.extname(relative) in TYPES;
|
|
107
|
+
return asset ? null : path.join(this.root, 'index.html');
|
|
108
|
+
}
|
|
109
|
+
async send(file, request, response) {
|
|
110
|
+
const stats = await fs.promises.stat(file).catch(() => null);
|
|
111
|
+
if (stats === null) {
|
|
112
|
+
response.writeHead(503, { 'content-type': 'text/plain' })
|
|
113
|
+
.end('The configuration UI is not built. Run `npm run build:ui`.\n');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
response.writeHead(200, {
|
|
117
|
+
'content-type': TYPES[path.extname(file)] ?? 'application/octet-stream',
|
|
118
|
+
'content-length': stats.size,
|
|
119
|
+
'cache-control': caching(path.relative(this.root, file))
|
|
120
|
+
});
|
|
121
|
+
if (request.method === 'HEAD')
|
|
122
|
+
response.end();
|
|
123
|
+
else
|
|
124
|
+
fs.createReadStream(file).pipe(response);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function decode(url) {
|
|
128
|
+
try {
|
|
129
|
+
return decodeURIComponent(url.split('?')[0]);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function isFile(file) {
|
|
136
|
+
return fs.existsSync(file) && fs.statSync(file).isFile();
|
|
137
|
+
}
|
|
138
|
+
/** Where `npm run build:ui` puts the page, from both `source` and `transpiled`. */
|
|
139
|
+
const SITE = path.resolve(import.meta.dirname, '..', 'ui', 'dist');
|
|
140
|
+
/** Assets under this prefix carry their build hash in the name. */
|
|
141
|
+
const IMMUTABLE = path.join('_app', 'immutable');
|
|
142
|
+
const FOREVER = 'public, max-age=31536000, immutable';
|
|
143
|
+
/** The icons: named without a hash, so they are re-read, but rarely. */
|
|
144
|
+
const ICONS = new Set(['favicon.ico', 'favicon-96x96.png', 'apple-touch-icon.png']);
|
|
145
|
+
const DAY = 'public, max-age=86400';
|
|
146
|
+
/**
|
|
147
|
+
* How long what is served may be held. The page is never cached — it names the assets,
|
|
148
|
+
* and their names carry the build. An icon is named for what it is rather than for its
|
|
149
|
+
* content, so it is asked about again, but not on every page load.
|
|
150
|
+
*/
|
|
151
|
+
function caching(relative) {
|
|
152
|
+
if (relative.startsWith(IMMUTABLE))
|
|
153
|
+
return FOREVER;
|
|
154
|
+
return ICONS.has(relative) ? DAY : 'no-cache';
|
|
155
|
+
}
|
|
156
|
+
const TYPES = {
|
|
157
|
+
'.css': 'text/css; charset=utf-8',
|
|
158
|
+
'.html': 'text/html; charset=utf-8',
|
|
159
|
+
'.ico': 'image/x-icon',
|
|
160
|
+
'.jpg': 'image/jpeg',
|
|
161
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
162
|
+
'.json': 'application/json; charset=utf-8',
|
|
163
|
+
'.map': 'application/json; charset=utf-8',
|
|
164
|
+
'.png': 'image/png',
|
|
165
|
+
'.svg': 'image/svg+xml',
|
|
166
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
167
|
+
'.webmanifest': 'application/manifest+json',
|
|
168
|
+
'.webp': 'image/webp',
|
|
169
|
+
'.woff': 'font/woff',
|
|
170
|
+
'.woff2': 'font/woff2'
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=UI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UI.js","sourceRoot":"","sources":["../source/UI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC;;;;;;GAMG;AACH,MAAM,OAAO,EAAG,SAAQ,SAAS;IACd,MAAM,GAAgB,IAAI,CA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Ac,EAAE,2BAA2B;IAC3C,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,WAAW;IACpB,QAAQ,EAAE,YAAY;CACvB,CAAA"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type Locator } from '@toa.io/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { Manifest } from './manifest.js';
|
|
3
|
+
/** The variable is set, so the values service is not consulted. */
|
|
4
|
+
export declare function overridden(locator: Locator): boolean;
|
|
5
|
+
/** The variable, the manifest defaults, then the schema. */
|
|
6
|
+
export declare function local(locator: Locator, manifest: Manifest): Node;
|
|
7
|
+
/** A copy of the value with the schema applied and the secrets substituted. */
|
|
8
|
+
export declare function fit(raw: object, manifest: Manifest): Node;
|
|
4
9
|
export type Node = Record<string, unknown>;
|
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.get = void 0;
|
|
27
|
-
const generic_1 = require("@toa.io/generic");
|
|
28
|
-
const schemas = __importStar(require("@toa.io/schemas"));
|
|
29
|
-
const deployment_1 = require("./deployment");
|
|
30
|
-
function get(locator, manifest) {
|
|
31
|
-
const values = getConfiguration(locator.uppercase);
|
|
32
|
-
substituteSecrets(values);
|
|
1
|
+
import { add } from '@toa.io/generic';
|
|
2
|
+
import * as schemas from '@toa.io/schemas';
|
|
3
|
+
import { PREFIX, SECRET_RX } from './const.js';
|
|
4
|
+
import { Secret } from './Secret.js';
|
|
5
|
+
/** The variable is set, so the values service is not consulted. */
|
|
6
|
+
export function overridden(locator) {
|
|
7
|
+
return process.env[PREFIX + locator.uppercase] !== undefined;
|
|
8
|
+
}
|
|
9
|
+
/** The variable, the manifest defaults, then the schema. */
|
|
10
|
+
export function local(locator, manifest) {
|
|
11
|
+
const values = read(locator.uppercase);
|
|
33
12
|
if (manifest.defaults !== undefined)
|
|
34
|
-
|
|
13
|
+
add(values, manifest.defaults);
|
|
14
|
+
return fit(values, manifest);
|
|
15
|
+
}
|
|
16
|
+
/** A copy of the value with the schema applied and the secrets substituted. */
|
|
17
|
+
export function fit(raw, manifest) {
|
|
18
|
+
// a copy of the caller's, and one of this realm: what came over the wire is JSON anyway
|
|
19
|
+
const values = JSON.parse(JSON.stringify(raw));
|
|
20
|
+
// the schema sees the references, which are the strings it declares
|
|
21
|
+
validate(values, manifest);
|
|
22
|
+
substituteSecrets(values);
|
|
23
|
+
return values;
|
|
24
|
+
}
|
|
25
|
+
function validate(values, manifest) {
|
|
35
26
|
const schema = schemas.schema(manifest.schema);
|
|
36
27
|
schema.validate(values);
|
|
37
|
-
return values;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const variable = deployment_1.PREFIX + suffix;
|
|
29
|
+
function read(suffix) {
|
|
30
|
+
const variable = PREFIX + suffix;
|
|
42
31
|
const string = process.env[variable];
|
|
43
32
|
if (string === undefined)
|
|
44
33
|
return {};
|
|
45
34
|
else
|
|
46
|
-
return
|
|
35
|
+
return JSON.parse(string);
|
|
47
36
|
}
|
|
48
37
|
function substituteSecrets(configuration) {
|
|
49
38
|
for (const [key, value] of Object.entries(configuration)) {
|
|
@@ -51,15 +40,15 @@ function substituteSecrets(configuration) {
|
|
|
51
40
|
substituteSecrets(value);
|
|
52
41
|
if (typeof value !== 'string')
|
|
53
42
|
continue;
|
|
54
|
-
const match = value.match(
|
|
43
|
+
const match = value.match(SECRET_RX);
|
|
55
44
|
if (match === null)
|
|
56
45
|
continue;
|
|
57
46
|
const name = match.groups?.variable;
|
|
58
|
-
configuration[key] = getSecret(name);
|
|
47
|
+
configuration[key] = new Secret(getSecret(name));
|
|
59
48
|
}
|
|
60
49
|
}
|
|
61
50
|
function getSecret(name) {
|
|
62
|
-
const variable =
|
|
51
|
+
const variable = PREFIX + '_' + name;
|
|
63
52
|
const value = process.env[variable];
|
|
64
53
|
if (value === undefined)
|
|
65
54
|
throw new Error(`${variable} is not set.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../source/configuration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../source/configuration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIpC,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAE,OAAgB;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,KAAK,SAAS,CAAA;AAC9D,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,KAAK,CAAE,OAAgB,EAAE,QAAkB;IACzD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IAEtC,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS;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AK,CAAC,SAAS,CAAC,CAAA;QAEpC,IAAI,KAAK,KAAK,IAAI;YAAE,SAAQ;QAE5B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAA;QAEnC,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,IAAK,CAAC,CAAC,CAAA;IACnD,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAE,IAAY;IAC9B,MAAM,QAAQ,GAAG,MAAM,GAAG,GAAG,GAAG,IAAI,CAAA;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAEnC,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,cAAc,CAAC,CAAA;IAEnE,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,61 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { Locator } from '@toa.io/core';
|
|
4
|
+
import { generate } from 'randomstring';
|
|
5
|
+
import { fit, local, overridden } from './configuration.js';
|
|
6
|
+
import { Secret } from './Secret.js';
|
|
7
7
|
let locator;
|
|
8
8
|
let manifest;
|
|
9
9
|
beforeEach(() => {
|
|
10
|
-
locator = new
|
|
11
|
-
manifest = {
|
|
10
|
+
locator = new Locator(generate(), generate());
|
|
11
|
+
manifest = {
|
|
12
|
+
schema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: { foo: { type: 'string' } }
|
|
15
|
+
}
|
|
16
|
+
};
|
|
12
17
|
});
|
|
13
18
|
afterEach(() => {
|
|
14
19
|
for (const name of used)
|
|
15
20
|
delete process.env[name];
|
|
16
21
|
used = [];
|
|
17
22
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect((0, configuration_1.get)(locator, manifest)).toStrictEqual({});
|
|
27
|
-
});
|
|
28
|
-
it('should substitute secrets', async () => {
|
|
29
|
-
const value = { foo: '$BAR' };
|
|
30
|
-
set(value);
|
|
31
|
-
set('bar', '_BAR');
|
|
32
|
-
const result = (0, configuration_1.get)(locator, manifest);
|
|
33
|
-
expect(result).toStrictEqual({ foo: 'bar' });
|
|
23
|
+
describe('overridden', () => {
|
|
24
|
+
it('should be false without the variable', async () => {
|
|
25
|
+
assert.deepStrictEqual(overridden(locator), false);
|
|
26
|
+
});
|
|
27
|
+
it('should be true with the variable', async () => {
|
|
28
|
+
set({});
|
|
29
|
+
assert.deepStrictEqual(overridden(locator), true);
|
|
30
|
+
});
|
|
34
31
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
describe('local', () => {
|
|
33
|
+
it('should read value', async () => {
|
|
34
|
+
const value = { foo: generate() };
|
|
35
|
+
set(value);
|
|
36
|
+
assert.deepStrictEqual(local(locator, manifest), value);
|
|
37
|
+
});
|
|
38
|
+
it('should return empty object if no value set', async () => {
|
|
39
|
+
assert.deepStrictEqual(local(locator, manifest), {});
|
|
40
|
+
});
|
|
41
|
+
it('should substitute secrets', async () => {
|
|
42
|
+
set({ foo: '$BAR' });
|
|
43
|
+
set('bar', '_BAR');
|
|
44
|
+
const { foo } = local(locator, manifest);
|
|
45
|
+
assert.ok(foo instanceof Secret);
|
|
46
|
+
assert.deepStrictEqual(foo.unwrap(), 'bar');
|
|
47
|
+
assert.deepStrictEqual(String(foo), '<REDACTED>');
|
|
48
|
+
});
|
|
49
|
+
it('should substitute secrets in defaults', async () => {
|
|
50
|
+
manifest.defaults = { foo: '$BAR' };
|
|
51
|
+
set('bar', '_BAR');
|
|
52
|
+
assert.deepStrictEqual(local(locator, manifest).foo.unwrap(), 'bar');
|
|
53
|
+
});
|
|
54
|
+
it('should use defaults', async () => {
|
|
55
|
+
manifest.schema = {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
foo: { type: 'string' },
|
|
59
|
+
bar: { type: 'array', items: { type: 'number' } },
|
|
60
|
+
baz: { type: 'string' }
|
|
61
|
+
},
|
|
62
|
+
required: ['foo', 'bar']
|
|
63
|
+
};
|
|
64
|
+
manifest.defaults = { foo: 'bar', bar: [1] };
|
|
65
|
+
set({ bar: [2], baz: 'foo' });
|
|
66
|
+
assert.deepStrictEqual(local(locator, manifest), { foo: 'bar', bar: [2], baz: 'foo' });
|
|
67
|
+
});
|
|
68
|
+
it('should validate', async () => {
|
|
69
|
+
manifest.schema = {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
foo: { type: 'string', default: 'hello' },
|
|
73
|
+
bar: { type: 'number' }
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
set({ bar: 5 });
|
|
77
|
+
assert.deepStrictEqual(local(locator, manifest), { foo: 'hello', bar: 5 });
|
|
45
78
|
});
|
|
46
79
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
80
|
+
describe('fit', () => {
|
|
81
|
+
it('should substitute secrets and apply the schema', async () => {
|
|
82
|
+
manifest.schema = {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
foo: { type: 'string' },
|
|
86
|
+
bar: { type: 'number', default: 1 }
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
set('secret', '_FOO');
|
|
90
|
+
const raw = { foo: '$FOO' };
|
|
91
|
+
const values = fit(raw, manifest);
|
|
92
|
+
assert.deepStrictEqual(values.foo.unwrap(), 'secret');
|
|
93
|
+
assert.deepStrictEqual(values.bar, 1);
|
|
94
|
+
assert.deepStrictEqual(raw, { foo: '$FOO' }); // untouched
|
|
95
|
+
});
|
|
96
|
+
it('should not apply the manifest defaults', async () => {
|
|
97
|
+
manifest.defaults = { foo: 'hello' };
|
|
98
|
+
assert.deepStrictEqual(fit({}, manifest), {});
|
|
99
|
+
});
|
|
100
|
+
it('should throw on a value not fitting the schema', async () => {
|
|
101
|
+
assert.throws(() => fit({ foo: { nested: true } }, manifest));
|
|
55
102
|
});
|
|
56
103
|
});
|
|
57
104
|
function set(value, key = locator.uppercase) {
|
|
58
|
-
const string = typeof value === 'string' ? value :
|
|
105
|
+
const string = typeof value === 'string' ? value : JSON.stringify(value);
|
|
59
106
|
const name = 'TOA_CONFIGURATION_' + key;
|
|
60
107
|
process.env[name] = string;
|
|
61
108
|
used.push(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.test.js","sourceRoot":"","sources":["../source/configuration.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configuration.test.js","sourceRoot":"","sources":["../source/configuration.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC/D,OAAO,MAAM,MAAM,oBAAoB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,IAAI,OAAgB,CAAA;AACpB,IAAI,QAAkB,CAAA;AAEtB,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC7C,QAAQ,GAAG;QACT,MAAM,EA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AAC;AAED,IAAI,IAAI,GAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Source } from '@toa.io/core';
|
|
2
|
+
/** Per-component variables: the local override and the secrets. */
|
|
3
|
+
export declare const PREFIX = "TOA_CONFIGURATION_";
|
|
4
|
+
/** The map of every configured component, on the values service. */
|
|
5
|
+
export declare const VALUES = "TOA_CONFIGURATION_VALUES";
|
|
6
|
+
export declare const SECRET_RX: RegExp;
|
|
7
|
+
/** Where the UI is mounted; `/configuration/*` belongs to the component's own API. */
|
|
8
|
+
export declare const UI_PATH = "/.configuration";
|
|
9
|
+
export declare const UI_PORT = 8003;
|
|
10
|
+
export declare const EVENT = "configuration.values.created";
|
|
11
|
+
export declare const SOURCE: Source;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Per-component variables: the local override and the secrets. */
|
|
2
|
+
export const PREFIX = 'TOA_CONFIGURATION_';
|
|
3
|
+
/** The map of every configured component, on the values service. */
|
|
4
|
+
export const VALUES = 'TOA_CONFIGURATION_VALUES';
|
|
5
|
+
export const SECRET_RX = /^\$(?<variable>[A-Z0-9_]{1,32})$/;
|
|
6
|
+
/** Where the UI is mounted; `/configuration/*` belongs to the component's own API. */
|
|
7
|
+
export const UI_PATH = '/.configuration';
|
|
8
|
+
export const UI_PORT = 8003;
|
|
9
|
+
export const EVENT = 'configuration.values.created';
|
|
10
|
+
export const SOURCE = { service: 'configuration' };
|
|
11
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["../source/const.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,oBAAoB,CAAA;AAE1C,oEAAoE;AACpE,MAAM,CAAC,MAAM,MAAM,GAAG,0BAA0B,CAAA;AAEhD,MAAM,CAAC,MAAM,SAAS,GAAG,kCAAkC,CAAA;AAE3D,sFAAsF;AACtF,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA;AACxC,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAA;AAE3B,MAAM,CAAC,MAAM,KAAK,GAAG,8BAA8B,CAAA;AAEnD,MAAM,CAAC,MAAM,MAAM,GAAW,EAAE,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { type Dependency } from '@toa.io/operations';
|
|
2
|
-
import {
|
|
2
|
+
import type { Manifest } from './manifest.js';
|
|
3
3
|
import type { context } from '@toa.io/norm';
|
|
4
4
|
export declare function deployment(instances: Instance[], annotation?: Annotation): Dependency;
|
|
5
|
-
|
|
6
|
-
export declare
|
|
5
|
+
/** What the values service is given: the epoch, the schema and the defaults of every component. */
|
|
6
|
+
export declare function describe(instances: Instance[], annotation?: Annotation): Values;
|
|
7
7
|
export type Annotation = Record<string, object>;
|
|
8
8
|
export type Instance = context.Dependency<Manifest>;
|
|
9
|
+
export type Values = Record<string, Entry>;
|
|
10
|
+
export interface Entry {
|
|
11
|
+
epoch: string;
|
|
12
|
+
schema: object;
|
|
13
|
+
defaults?: object;
|
|
14
|
+
}
|