@toa.io/extensions.configuration 1.0.0-alpha.291 → 1.0.0-alpha.293
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/package.json +16 -6
- package/transpiled/Aspect.d.ts +1 -1
- package/transpiled/Aspect.js +1 -1
- package/transpiled/Aspect.js.map +1 -1
- package/transpiled/Client.js +1 -1
- package/transpiled/Client.js.map +1 -1
- package/transpiled/Composition.js +1 -1
- package/transpiled/Composition.js.map +1 -1
- package/transpiled/Factory.d.ts +1 -1
- package/transpiled/UI.js +1 -1
- package/transpiled/UI.js.map +1 -1
- package/transpiled/configuration.d.ts +1 -1
- package/transpiled/configuration.js +1 -1
- package/transpiled/configuration.js.map +1 -1
- package/transpiled/index.d.ts +0 -3
- package/transpiled/index.js +0 -4
- package/transpiled/index.js.map +1 -1
- package/ui/dist/_app/immutable/chunks/BVp7FTPj.js +1 -0
- package/ui/dist/_app/immutable/chunks/{CNZAv2Es.js → Ba25-8aA.js} +1 -1
- package/ui/dist/_app/immutable/chunks/{BV5cDXGB.js → D5h0LnT-.js} +1 -1
- package/ui/dist/_app/immutable/chunks/{vl8APhvf.js → DJFe2eVw.js} +2 -2
- package/ui/dist/_app/immutable/chunks/{B_CH3nFk.js → iBEDxyKc.js} +1 -1
- package/ui/dist/_app/immutable/entry/{app.CK-db-gz.js → app.BaUwlvvj.js} +2 -2
- package/ui/dist/_app/immutable/entry/start.BQIMr3E0.js +1 -0
- package/ui/dist/_app/immutable/nodes/{0.vPwVABRs.js → 0.Bdnf_m1Q.js} +1 -1
- package/ui/dist/_app/immutable/nodes/{1.DS63PME5.js → 1.ChFvQfy2.js} +1 -1
- package/ui/dist/_app/immutable/nodes/{2.KRpWYBfz.js → 2.DoZuKZSw.js} +1 -1
- package/ui/dist/_app/immutable/nodes/3.BalX8tPE.js +1 -0
- package/ui/dist/_app/immutable/nodes/{4.D8lluH3u.js → 4.w2QdhCXS.js} +1 -1
- package/ui/dist/_app/version.json +1 -1
- package/ui/dist/index.html +10 -10
- package/CHANGELOG.md +0 -35
- package/components/configuration.values/source/lib/map.test.ts +0 -42
- package/components/configuration.values/tsconfig.tsbuildinfo +0 -1
- package/cucumber.mjs +0 -8
- package/features/site/_app/immutable/asset.js +0 -1
- package/features/site/favicon.ico +0 -0
- package/features/site/index.html +0 -10
- package/features/steps/UI.ts +0 -98
- package/features/steps/tsconfig.json +0 -9
- package/features/ui.feature +0 -93
- package/notes/consistency.md +0 -70
- package/schemas/annotation.cos.yaml +0 -29
- package/schemas/manifest.cos.yaml +0 -9
- package/source/Aspect.test.ts +0 -119
- package/source/Aspect.ts +0 -91
- package/source/Client.test.ts +0 -125
- package/source/Client.ts +0 -251
- package/source/Composition.ts +0 -57
- package/source/Factory.ts +0 -34
- package/source/Secret.test.ts +0 -32
- package/source/Secret.ts +0 -32
- package/source/UI.ts +0 -213
- package/source/configuration.test.ts +0 -152
- package/source/configuration.ts +0 -74
- package/source/const.ts +0 -30
- package/source/context.ts +0 -13
- package/source/deployment.test.ts +0 -112
- package/source/deployment.ts +0 -160
- package/source/epoch.test.ts +0 -35
- package/source/epoch.ts +0 -22
- package/source/index.ts +0 -10
- package/source/manifest.test.ts +0 -24
- package/source/manifest.ts +0 -13
- package/source/schemas.ts +0 -9
- package/transpiled/const.d.ts +0 -18
- package/transpiled/const.js +0 -22
- package/transpiled/const.js.map +0 -1
- package/transpiled/context.d.ts +0 -4
- package/transpiled/context.js +0 -9
- package/transpiled/context.js.map +0 -1
- package/transpiled/deployment.d.ts +0 -17
- package/transpiled/deployment.js +0 -107
- package/transpiled/deployment.js.map +0 -1
- package/transpiled/epoch.d.ts +0 -2
- package/transpiled/epoch.js +0 -19
- package/transpiled/epoch.js.map +0 -1
- package/transpiled/manifest.d.ts +0 -6
- package/transpiled/manifest.js +0 -6
- package/transpiled/manifest.js.map +0 -1
- package/transpiled/schemas.d.ts +0 -3
- package/transpiled/schemas.js +0 -7
- package/transpiled/schemas.js.map +0 -1
- package/tsconfig.json +0 -13
- package/tsconfig.tsbuildinfo +0 -1
- package/ui/dist/_app/immutable/chunks/3Kbn_1Vv.js +0 -1
- package/ui/dist/_app/immutable/entry/start.Bs7xr9Ne.js +0 -1
- package/ui/dist/_app/immutable/nodes/3.DCxORePS.js +0 -1
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { describe, it, beforeEach, afterEach } from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { Locator } from '@toa.io/core'
|
|
5
|
-
import { generate } from 'randomstring'
|
|
6
|
-
import { fit, local, overridden } from './configuration.js'
|
|
7
|
-
import { Secret } from './Secret.js'
|
|
8
|
-
import { type Manifest } from './manifest.js'
|
|
9
|
-
|
|
10
|
-
let locator: Locator
|
|
11
|
-
let manifest: Manifest
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
locator = new Locator(generate(), generate())
|
|
15
|
-
manifest = {
|
|
16
|
-
schema: {
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: { foo: { type: 'string' } }
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
for (const name of used) delete process.env[name]
|
|
25
|
-
|
|
26
|
-
used = []
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('overridden', () => {
|
|
30
|
-
it('should be false without the variable', async () => {
|
|
31
|
-
assert.deepStrictEqual(overridden(locator), false)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('should be true with the variable', async () => {
|
|
35
|
-
set({})
|
|
36
|
-
|
|
37
|
-
assert.deepStrictEqual(overridden(locator), true)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe('local', () => {
|
|
42
|
-
it('should read value', async () => {
|
|
43
|
-
const value: object = { foo: generate() }
|
|
44
|
-
|
|
45
|
-
set(value)
|
|
46
|
-
|
|
47
|
-
assert.deepStrictEqual(local(locator, manifest), value)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should return empty object if no value set', async () => {
|
|
51
|
-
assert.deepStrictEqual(local(locator, manifest), {})
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('should substitute secrets', async () => {
|
|
55
|
-
set({ foo: '$BAR' })
|
|
56
|
-
set('bar', '_BAR')
|
|
57
|
-
|
|
58
|
-
const { foo } = local(locator, manifest)
|
|
59
|
-
|
|
60
|
-
assert.ok(foo instanceof Secret)
|
|
61
|
-
assert.deepStrictEqual((foo as Secret).unwrap(), 'bar')
|
|
62
|
-
assert.deepStrictEqual(String(foo), '<REDACTED>')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should substitute secrets in defaults', async () => {
|
|
66
|
-
manifest.defaults = { foo: '$BAR' }
|
|
67
|
-
|
|
68
|
-
set('bar', '_BAR')
|
|
69
|
-
|
|
70
|
-
assert.deepStrictEqual((local(locator, manifest).foo as Secret).unwrap(), 'bar')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('should use defaults', async () => {
|
|
74
|
-
manifest.schema = {
|
|
75
|
-
type: 'object',
|
|
76
|
-
properties: {
|
|
77
|
-
foo: { type: 'string' },
|
|
78
|
-
bar: { type: 'array', items: { type: 'number' } },
|
|
79
|
-
baz: { type: 'string' }
|
|
80
|
-
},
|
|
81
|
-
required: ['foo', 'bar']
|
|
82
|
-
}
|
|
83
|
-
manifest.defaults = { foo: 'bar', bar: [1] }
|
|
84
|
-
|
|
85
|
-
set({ bar: [2], baz: 'foo' })
|
|
86
|
-
|
|
87
|
-
assert.deepStrictEqual(local(locator, manifest), { foo: 'bar', bar: [2], baz: 'foo' })
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('should validate', async () => {
|
|
91
|
-
manifest.schema = {
|
|
92
|
-
type: 'object',
|
|
93
|
-
properties: {
|
|
94
|
-
foo: { type: 'string' },
|
|
95
|
-
bar: { type: 'number' }
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
set({ bar: 5 })
|
|
100
|
-
|
|
101
|
-
assert.deepStrictEqual(local(locator, manifest), { bar: 5 })
|
|
102
|
-
|
|
103
|
-
set({ bar: 'five' })
|
|
104
|
-
|
|
105
|
-
assert.throws(
|
|
106
|
-
() => local(locator, manifest),
|
|
107
|
-
(error: Error) => /must be number/.test(error.message)
|
|
108
|
-
)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('fit', () => {
|
|
113
|
-
it('should substitute secrets and apply the schema', async () => {
|
|
114
|
-
manifest.schema = {
|
|
115
|
-
type: 'object',
|
|
116
|
-
properties: {
|
|
117
|
-
foo: { type: 'string' },
|
|
118
|
-
bar: { type: 'number' }
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
set('secret', '_FOO')
|
|
123
|
-
|
|
124
|
-
const raw = { foo: '$FOO', bar: 1 }
|
|
125
|
-
const values = fit(raw, manifest)
|
|
126
|
-
|
|
127
|
-
assert.deepStrictEqual((values.foo as Secret).unwrap(), 'secret')
|
|
128
|
-
assert.deepStrictEqual(values.bar, 1)
|
|
129
|
-
assert.deepStrictEqual(raw, { foo: '$FOO', bar: 1 }) // untouched
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('should not apply the manifest defaults', async () => {
|
|
133
|
-
manifest.defaults = { foo: 'hello' }
|
|
134
|
-
|
|
135
|
-
assert.deepStrictEqual(fit({}, manifest), {})
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('should throw on a value not fitting the schema', async () => {
|
|
139
|
-
assert.throws(() => fit({ foo: { nested: true } }, manifest))
|
|
140
|
-
})
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
function set(value: object | string, key = locator.uppercase): void {
|
|
144
|
-
const string = typeof value === 'string' ? value : JSON.stringify(value)
|
|
145
|
-
const name = 'TOA_CONFIGURATION_' + key
|
|
146
|
-
|
|
147
|
-
process.env[name] = string
|
|
148
|
-
|
|
149
|
-
used.push(name)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let used: string[] = []
|
package/source/configuration.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { type Locator } from '@toa.io/core'
|
|
2
|
-
import { add, environment } from '@toa.io/generic'
|
|
3
|
-
import * as schemas from '@toa.io/schemas'
|
|
4
|
-
import { PREFIX, SECRET_RX } from './const.js'
|
|
5
|
-
import { Secret } from './Secret.js'
|
|
6
|
-
import type { Schema } from '@toa.io/schemas'
|
|
7
|
-
import type { Manifest } from './manifest.js'
|
|
8
|
-
|
|
9
|
-
/** The variable is set, so the values service is not consulted. */
|
|
10
|
-
export function overridden(locator: Locator): boolean {
|
|
11
|
-
return environment.get(PREFIX + locator.uppercase) !== undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** The variable, the manifest defaults, then the schema. */
|
|
15
|
-
export function local(locator: Locator, manifest: Manifest): Node {
|
|
16
|
-
const values = read(locator.uppercase)
|
|
17
|
-
|
|
18
|
-
if (manifest.defaults !== undefined) add(values, manifest.defaults)
|
|
19
|
-
|
|
20
|
-
return fit(values, manifest)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** A copy of the value with the schema applied and the secrets substituted. */
|
|
24
|
-
export function fit(raw: object, manifest: Manifest): Node {
|
|
25
|
-
// a copy of the caller's, and one of this realm: what came over the wire is JSON anyway
|
|
26
|
-
const values = JSON.parse(JSON.stringify(raw)) as Node
|
|
27
|
-
|
|
28
|
-
// the schema sees the references, which are the strings it declares
|
|
29
|
-
validate(values, manifest)
|
|
30
|
-
substituteSecrets(values)
|
|
31
|
-
|
|
32
|
-
return values
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function validate(values: Node, manifest: Manifest): void {
|
|
36
|
-
const schema: Schema<any> = schemas.schema(manifest.schema)
|
|
37
|
-
|
|
38
|
-
schema.validate(values)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function read(suffix: string): Node {
|
|
42
|
-
const variable = PREFIX + suffix
|
|
43
|
-
const string = environment.get(variable)
|
|
44
|
-
|
|
45
|
-
if (string === undefined) return {}
|
|
46
|
-
else return JSON.parse(string)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function substituteSecrets(configuration: Node): void {
|
|
50
|
-
for (const [key, value] of Object.entries(configuration)) {
|
|
51
|
-
if (typeof value === 'object' && value !== null) substituteSecrets(value as Node)
|
|
52
|
-
|
|
53
|
-
if (typeof value !== 'string') continue
|
|
54
|
-
|
|
55
|
-
const match = value.match(SECRET_RX)
|
|
56
|
-
|
|
57
|
-
if (match === null) continue
|
|
58
|
-
|
|
59
|
-
const name = match.groups?.variable
|
|
60
|
-
|
|
61
|
-
configuration[key] = new Secret(getSecret(name!))
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getSecret(name: string): string {
|
|
66
|
-
const variable = PREFIX + '_' + name
|
|
67
|
-
const value = environment.get(variable)
|
|
68
|
-
|
|
69
|
-
if (value === undefined) throw new Error(`${variable} is not set.`)
|
|
70
|
-
|
|
71
|
-
return value
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type Node = Record<string, unknown>
|
package/source/const.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { environment } from '@toa.io/generic'
|
|
2
|
-
import type { Source } from '@toa.io/core/types'
|
|
3
|
-
|
|
4
|
-
/** Per-component variables: the local override and the secrets. */
|
|
5
|
-
export const PREFIX = 'TOA_CONFIGURATION_'
|
|
6
|
-
|
|
7
|
-
/** The map of every configured component, on the values service. */
|
|
8
|
-
export const VALUES = 'TOA_CONFIGURATION_VALUES'
|
|
9
|
-
|
|
10
|
-
export const SECRET_RX = /^\$(?<variable>[A-Z0-9_]{1,32})$/
|
|
11
|
-
|
|
12
|
-
/** Where the UI is mounted; `/configuration/*` belongs to the component's own API. */
|
|
13
|
-
export const UI_PATH = '/.configuration'
|
|
14
|
-
export const UI_PORT = 8003
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The port the UI is served on. `UI_PORT` is what a deployment publishes and what the chart
|
|
18
|
-
* renders; the variable is for a machine that runs more than one Toa process — a Toa checkout
|
|
19
|
-
* beside an application, or two applications — where one of them has to give it up.
|
|
20
|
-
*/
|
|
21
|
-
export const UI_PORT_ENV = 'TOA_CONFIGURATION_UI_PORT'
|
|
22
|
-
export function uiPort(): number {
|
|
23
|
-
const value = environment.get(UI_PORT_ENV)
|
|
24
|
-
|
|
25
|
-
return value === undefined ? UI_PORT : Number(value)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const EVENT = 'configuration.values.created'
|
|
29
|
-
|
|
30
|
-
export const SOURCE: Source = { service: 'configuration' }
|
package/source/context.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Manifest } from './manifest.js'
|
|
2
|
-
import type { Contribution } from '@toa.io/core/types'
|
|
3
|
-
|
|
4
|
-
/** What this extension puts on the context of a component that declares it. */
|
|
5
|
-
export function context(declaration: Manifest): Contribution {
|
|
6
|
-
const contribution: Contribution = { name: 'configuration', schema: declaration.schema }
|
|
7
|
-
|
|
8
|
-
// a value the schema declares a secret is one on the context, not a string
|
|
9
|
-
if (JSON.stringify(declaration.schema).includes('"secret"'))
|
|
10
|
-
contribution.imports = { '@toa.io/extensions.configuration': ['Secret'] }
|
|
11
|
-
|
|
12
|
-
return contribution
|
|
13
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { it } from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { Locator } from '@toa.io/core'
|
|
5
|
-
import {
|
|
6
|
-
type Annotation,
|
|
7
|
-
type Instance,
|
|
8
|
-
deployment,
|
|
9
|
-
describe as map
|
|
10
|
-
} from './deployment.js'
|
|
11
|
-
import { epoch } from './epoch.js'
|
|
12
|
-
import { EVENT, VALUES } from './const.js'
|
|
13
|
-
|
|
14
|
-
const schema = {
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: { foo: { type: 'string' }, key: { type: 'string' } }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function instance(name: string, defaults?: Record<string, unknown>): Instance {
|
|
20
|
-
return {
|
|
21
|
-
locator: new Locator(name, 'configuration'),
|
|
22
|
-
manifest: { schema, defaults },
|
|
23
|
-
component: {} as any
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
it('should validate annotation', async () => {
|
|
28
|
-
const wrongType = 'not ok' as unknown as Annotation
|
|
29
|
-
|
|
30
|
-
assert.throws(
|
|
31
|
-
() => deployment([], wrongType),
|
|
32
|
-
(error: any) => /object/.test(error.message)
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('should reject unknown components', async () => {
|
|
37
|
-
assert.throws(
|
|
38
|
-
() => deployment([instance('base')], { 'configuration.nope': {} }),
|
|
39
|
-
(error: any) =>
|
|
40
|
-
/Component 'configuration\.nope' does not request configuration/.test(error.message)
|
|
41
|
-
)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should deploy the values service with the map', async () => {
|
|
45
|
-
const instances = [instance('base', { foo: 'hello' }), instance('other')]
|
|
46
|
-
const annotation = { 'configuration.other': { foo: 'set' } }
|
|
47
|
-
|
|
48
|
-
const dependency = deployment(instances, annotation)
|
|
49
|
-
|
|
50
|
-
assert.deepStrictEqual(dependency.events, [EVENT])
|
|
51
|
-
assert.strictEqual(dependency.services?.length, 1)
|
|
52
|
-
|
|
53
|
-
const service = dependency.services![0]
|
|
54
|
-
|
|
55
|
-
assert.deepStrictEqual(service.group, 'configuration')
|
|
56
|
-
assert.deepStrictEqual(service.name, 'values')
|
|
57
|
-
assert.deepStrictEqual(service.components, ['configuration-values'])
|
|
58
|
-
|
|
59
|
-
const variable = service.variables!.find((variable) => variable.name === VALUES)
|
|
60
|
-
|
|
61
|
-
assert.notStrictEqual(variable, undefined)
|
|
62
|
-
assert.deepStrictEqual(JSON.parse(variable!.value!), map(instances, annotation))
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should describe every component', async () => {
|
|
66
|
-
const instances = [instance('base', { foo: 'hello' }), instance('other')]
|
|
67
|
-
const values = map(instances, { 'configuration.other': { foo: 'set' } })
|
|
68
|
-
|
|
69
|
-
assert.deepStrictEqual(values, {
|
|
70
|
-
'configuration.base': { epoch: epoch(schema), schema, defaults: { foo: 'hello' } },
|
|
71
|
-
'configuration.other': { epoch: epoch(schema), schema, defaults: { foo: 'set' } }
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should prefer the context over the manifest defaults', async () => {
|
|
76
|
-
const values = map([instance('base', { foo: 'hello' })], {
|
|
77
|
-
'configuration.base': { foo: 'bye' }
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
assert.deepStrictEqual(values['configuration.base'].defaults, { foo: 'bye' })
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should not map values to the component', async () => {
|
|
84
|
-
const dependency = deployment([instance('base')], {
|
|
85
|
-
'configuration.base': { foo: 'set' }
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
assert.deepStrictEqual(dependency.variables, {})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('should map secrets to the component', async () => {
|
|
92
|
-
const dependency = deployment([instance('base')], {
|
|
93
|
-
'configuration.base': { key: '$KEY' }
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
assert.deepStrictEqual(dependency.variables, {
|
|
97
|
-
'configuration-base': [
|
|
98
|
-
{
|
|
99
|
-
name: 'TOA_CONFIGURATION__KEY',
|
|
100
|
-
secret: { name: 'toa-configuration', key: 'KEY' }
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
// the service holds the reference, not the secret
|
|
106
|
-
assert.deepStrictEqual(
|
|
107
|
-
map([instance('base')], { 'configuration.base': { key: '$KEY' } })[
|
|
108
|
-
'configuration.base'
|
|
109
|
-
].defaults,
|
|
110
|
-
{ key: '$KEY' }
|
|
111
|
-
)
|
|
112
|
-
})
|
package/source/deployment.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
|
-
import assert from 'node:assert'
|
|
3
|
-
import {
|
|
4
|
-
type Dependency,
|
|
5
|
-
type Resources,
|
|
6
|
-
type Service,
|
|
7
|
-
type Variable,
|
|
8
|
-
type Variables
|
|
9
|
-
} from '@toa.io/operations'
|
|
10
|
-
import { add } from '@toa.io/generic'
|
|
11
|
-
import { components } from './Composition.js'
|
|
12
|
-
import { EVENT, PREFIX, SECRET_RX, UI_PATH, UI_PORT, VALUES } from './const.js'
|
|
13
|
-
import { epoch } from './epoch.js'
|
|
14
|
-
import * as validators from './schemas.js'
|
|
15
|
-
import type { Manifest } from './manifest.js'
|
|
16
|
-
import type { context } from '@toa.io/norm'
|
|
17
|
-
|
|
18
|
-
/** Where Toa's release publishes this service's image. An application takes it
|
|
19
|
-
* instead of building one when its context says `registry.services: published`. */
|
|
20
|
-
export const image = 'ghcr.io/toa-io/extension-configuration-values'
|
|
21
|
-
|
|
22
|
-
export function deployment(
|
|
23
|
-
instances: Instance[],
|
|
24
|
-
annotation: Annotation = {}
|
|
25
|
-
): Dependency {
|
|
26
|
-
const { resources, values } = split(annotation)
|
|
27
|
-
|
|
28
|
-
annotation = prepare(values, instances)
|
|
29
|
-
|
|
30
|
-
const variables: Variables = {}
|
|
31
|
-
|
|
32
|
-
for (const instance of instances) {
|
|
33
|
-
const values = annotation[instance.locator.id]
|
|
34
|
-
|
|
35
|
-
if (values === undefined) continue
|
|
36
|
-
|
|
37
|
-
const secrets = createSecrets(values)
|
|
38
|
-
|
|
39
|
-
if (secrets.length > 0) variables[instance.locator.label] = secrets
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const service: Service = {
|
|
43
|
-
group: 'configuration',
|
|
44
|
-
name: 'values',
|
|
45
|
-
image,
|
|
46
|
-
version: JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
|
|
47
|
-
.version,
|
|
48
|
-
components: components().labels,
|
|
49
|
-
resources,
|
|
50
|
-
// the service that holds the values also serves the page that reads them
|
|
51
|
-
port: UI_PORT,
|
|
52
|
-
ingress: { path: UI_PATH },
|
|
53
|
-
variables: [
|
|
54
|
-
{
|
|
55
|
-
name: VALUES,
|
|
56
|
-
value: JSON.stringify(describe(instances, annotation))
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { services: [service], variables, events: [EVENT] }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** What the values service is given: the epoch, the schema and the defaults of every component. */
|
|
65
|
-
export function describe(instances: Instance[], annotation: Annotation = {}): Values {
|
|
66
|
-
annotation = prepare(split(annotation).values, instances)
|
|
67
|
-
|
|
68
|
-
const values: Values = {}
|
|
69
|
-
|
|
70
|
-
for (const { locator, manifest } of instances) {
|
|
71
|
-
const deployed = annotation[locator.id]
|
|
72
|
-
|
|
73
|
-
values[locator.id] = {
|
|
74
|
-
epoch: epoch(manifest.schema),
|
|
75
|
-
schema: manifest.schema,
|
|
76
|
-
// what the Context says stands over what the manifest declares, value by value: a
|
|
77
|
-
// deployment that names one of them does not thereby unset the rest
|
|
78
|
-
defaults:
|
|
79
|
-
deployed === undefined
|
|
80
|
-
? manifest.defaults
|
|
81
|
-
: add(structuredClone(deployed), manifest.defaults ?? {})
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return values
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function createSecrets(values: object): Variable[] {
|
|
89
|
-
const secrets: Variable[] = []
|
|
90
|
-
|
|
91
|
-
for (const value of Object.values(values)) {
|
|
92
|
-
if (typeof value === 'object' && value !== null)
|
|
93
|
-
secrets.push(...createSecrets(value as object))
|
|
94
|
-
|
|
95
|
-
if (typeof value !== 'string') continue
|
|
96
|
-
|
|
97
|
-
const match = value.match(SECRET_RX)
|
|
98
|
-
|
|
99
|
-
if (match === null) continue
|
|
100
|
-
|
|
101
|
-
const name = match.groups?.variable
|
|
102
|
-
|
|
103
|
-
assert.ok(name !== undefined)
|
|
104
|
-
|
|
105
|
-
secrets.push({
|
|
106
|
-
name: PREFIX + '_' + name,
|
|
107
|
-
secret: {
|
|
108
|
-
name: 'toa-configuration',
|
|
109
|
-
key: name
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return secrets
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The service's own resources, and the component values that are the rest of the annotation.
|
|
119
|
-
*
|
|
120
|
-
* Every key here names a component, so the one option the service has of its own needs a
|
|
121
|
-
* name that cannot be mistaken for one. `resources` is reserved: a component actually
|
|
122
|
-
* called that is written with its namespace, `default.resources`, which is what an id is
|
|
123
|
-
* anyway — the bare form is the shorthand.
|
|
124
|
-
*/
|
|
125
|
-
function split(annotation: Annotation): { resources?: Resources; values: Annotation } {
|
|
126
|
-
validators.annotation.validate(annotation)
|
|
127
|
-
|
|
128
|
-
const { resources, ...values } = annotation as Annotation & { resources?: Resources }
|
|
129
|
-
|
|
130
|
-
return { resources, values }
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Validated, keyed by full component ids, and checked against the components that ask. */
|
|
134
|
-
function prepare(annotation: Annotation, instances: Instance[]): Annotation {
|
|
135
|
-
const normalized: Annotation = {}
|
|
136
|
-
const requested = instances.map((instance) => instance.locator.id)
|
|
137
|
-
|
|
138
|
-
for (const [key, values] of Object.entries(annotation)) {
|
|
139
|
-
const id = key.includes('.') ? key : 'default.' + key
|
|
140
|
-
|
|
141
|
-
assert.ok(
|
|
142
|
-
requested.includes(id),
|
|
143
|
-
`Component '${id}' does not request configuration or does not exist.`
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
normalized[id] = values
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return normalized
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export type Annotation = Record<string, object>
|
|
153
|
-
export type Instance = context.Dependency<Manifest>
|
|
154
|
-
export type Values = Record<string, Entry>
|
|
155
|
-
|
|
156
|
-
export interface Entry {
|
|
157
|
-
epoch: string
|
|
158
|
-
schema: object
|
|
159
|
-
defaults?: object
|
|
160
|
-
}
|
package/source/epoch.test.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { it } from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { epoch } from './epoch.js'
|
|
5
|
-
|
|
6
|
-
it('should be a sha256 hex', () => {
|
|
7
|
-
assert.match(epoch({ type: 'object' }), /^[a-f0-9]{64}$/)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('should not depend on key order', () => {
|
|
11
|
-
const a = {
|
|
12
|
-
type: 'object',
|
|
13
|
-
properties: { foo: { type: 'string', default: 'x' }, bar: { type: 'number' } }
|
|
14
|
-
}
|
|
15
|
-
const b = {
|
|
16
|
-
properties: { bar: { type: 'number' }, foo: { default: 'x', type: 'string' } },
|
|
17
|
-
type: 'object'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
assert.deepStrictEqual(epoch(a), epoch(b))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('should depend on values', () => {
|
|
24
|
-
const a = { type: 'object', properties: { foo: { type: 'string' } } }
|
|
25
|
-
const b = { type: 'object', properties: { foo: { type: 'number' } } }
|
|
26
|
-
|
|
27
|
-
assert.notDeepStrictEqual(epoch(a), epoch(b))
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should keep array order', () => {
|
|
31
|
-
const a = { enum: [1, 2] }
|
|
32
|
-
const b = { enum: [2, 1] }
|
|
33
|
-
|
|
34
|
-
assert.notDeepStrictEqual(epoch(a), epoch(b))
|
|
35
|
-
})
|
package/source/epoch.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
|
|
3
|
-
/** The same for the same schema, whatever the key order it was written in. */
|
|
4
|
-
export function epoch(schema: object): string {
|
|
5
|
-
return createHash('sha256').update(canonical(schema)).digest('hex')
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function canonical(value: unknown): string {
|
|
9
|
-
if (Array.isArray(value)) return '[' + value.map(canonical).join(',') + ']'
|
|
10
|
-
|
|
11
|
-
if (value !== null && typeof value === 'object') {
|
|
12
|
-
const object = value as Record<string, unknown>
|
|
13
|
-
const keys = Object.keys(object)
|
|
14
|
-
.filter((key) => object[key] !== undefined)
|
|
15
|
-
.sort()
|
|
16
|
-
const entries = keys.map((key) => JSON.stringify(key) + ':' + canonical(object[key]))
|
|
17
|
-
|
|
18
|
-
return '{' + entries.join(',') + '}'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return JSON.stringify(value) ?? 'null'
|
|
22
|
-
}
|
package/source/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { manifest } from './manifest.js'
|
|
2
|
-
export { deployment, describe, image } from './deployment.js'
|
|
3
|
-
export { components } from './Composition.js'
|
|
4
|
-
export { Factory } from './Factory.js'
|
|
5
|
-
|
|
6
|
-
// what a value declared `format: secret` is on a component's context
|
|
7
|
-
export { Secret } from './Secret.js'
|
|
8
|
-
|
|
9
|
-
// what this extension puts on a component's context
|
|
10
|
-
export { context } from './context.js'
|
package/source/manifest.test.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { it } from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
|
|
4
|
-
import { type Manifest, manifest } from './manifest.js'
|
|
5
|
-
|
|
6
|
-
it('should validate', async () => {
|
|
7
|
-
const additional = { schema: {}, foo: 'bar' } as unknown as Manifest
|
|
8
|
-
|
|
9
|
-
assert.throws(
|
|
10
|
-
() => {
|
|
11
|
-
manifest(additional)
|
|
12
|
-
},
|
|
13
|
-
(error: any) => /not expected/.test(error.message)
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const wrongType = { schema: 'not ok' } as unknown as Manifest
|
|
17
|
-
|
|
18
|
-
assert.throws(
|
|
19
|
-
() => {
|
|
20
|
-
manifest(wrongType)
|
|
21
|
-
},
|
|
22
|
-
(error: any) => /object/.test(error.message)
|
|
23
|
-
)
|
|
24
|
-
})
|
package/source/manifest.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as schemas from './schemas.js'
|
|
2
|
-
import { type Node } from './configuration.js'
|
|
3
|
-
|
|
4
|
-
export function manifest(manifest: Manifest): Manifest {
|
|
5
|
-
schemas.manifest.validate(manifest)
|
|
6
|
-
|
|
7
|
-
return manifest
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface Manifest {
|
|
11
|
-
schema: object
|
|
12
|
-
defaults?: Node
|
|
13
|
-
}
|
package/source/schemas.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path'
|
|
2
|
-
import * as schemas from '@toa.io/schemas'
|
|
3
|
-
import type { Schema } from '@toa.io/schemas'
|
|
4
|
-
|
|
5
|
-
const path = resolve(import.meta.dirname, '../schemas')
|
|
6
|
-
const namespace = schemas.namespace(path)
|
|
7
|
-
|
|
8
|
-
export const manifest: Schema<any> = namespace.schema('manifest')
|
|
9
|
-
export const annotation: Schema<any> = namespace.schema('annotation')
|
package/transpiled/const.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Source } from '@toa.io/core/types';
|
|
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
|
-
/**
|
|
11
|
-
* The port the UI is served on. `UI_PORT` is what a deployment publishes and what the chart
|
|
12
|
-
* renders; the variable is for a machine that runs more than one Toa process — a Toa checkout
|
|
13
|
-
* beside an application, or two applications — where one of them has to give it up.
|
|
14
|
-
*/
|
|
15
|
-
export declare const UI_PORT_ENV = "TOA_CONFIGURATION_UI_PORT";
|
|
16
|
-
export declare function uiPort(): number;
|
|
17
|
-
export declare const EVENT = "configuration.values.created";
|
|
18
|
-
export declare const SOURCE: Source;
|