@toa.io/extensions.configuration 0.20.0-dev.30 → 0.20.0-dev.34
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 +6 -6
- package/readme.md +60 -139
- package/source/.deployment/secrets.js +2 -0
- package/source/.deployment/variables.js +2 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.configuration",
|
|
3
|
-
"version": "0.20.0-dev.
|
|
3
|
+
"version": "0.20.0-dev.34",
|
|
4
4
|
"description": "Toa Configuration",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@toa.io/core": "0.20.0-dev.
|
|
20
|
-
"@toa.io/generic": "0.20.0-dev.
|
|
21
|
-
"@toa.io/schema": "0.20.0-dev.
|
|
22
|
-
"@toa.io/yaml": "0.20.0-dev.
|
|
19
|
+
"@toa.io/core": "0.20.0-dev.34",
|
|
20
|
+
"@toa.io/generic": "0.20.0-dev.34",
|
|
21
|
+
"@toa.io/schema": "0.20.0-dev.34",
|
|
22
|
+
"@toa.io/yaml": "0.20.0-dev.34",
|
|
23
23
|
"clone-deep": "4.0.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "7035b1985fe9bb844069308a272d061bfbd38bf0"
|
|
26
26
|
}
|
package/readme.md
CHANGED
|
@@ -5,20 +5,24 @@
|
|
|
5
5
|
### Define
|
|
6
6
|
|
|
7
7
|
```yaml
|
|
8
|
-
#
|
|
8
|
+
# manifest.toa.yaml
|
|
9
9
|
name: dummy
|
|
10
10
|
namespace: dummies
|
|
11
11
|
|
|
12
12
|
configuration:
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
schema:
|
|
14
|
+
foo: string
|
|
15
|
+
bar: number
|
|
16
|
+
defaults:
|
|
17
|
+
foo: bar
|
|
18
|
+
bar: 1
|
|
15
19
|
```
|
|
16
20
|
|
|
17
21
|
### Use
|
|
18
22
|
|
|
19
23
|
```javascript
|
|
20
24
|
function transition (input, entity, context) {
|
|
21
|
-
const { foo,
|
|
25
|
+
const { foo, bar } = context.configuration
|
|
22
26
|
|
|
23
27
|
// ...
|
|
24
28
|
}
|
|
@@ -30,9 +34,9 @@ function transition (input, entity, context) {
|
|
|
30
34
|
# context.toa.yaml
|
|
31
35
|
configuration:
|
|
32
36
|
dummies.dummy:
|
|
33
|
-
foo: qux # override default value
|
|
37
|
+
foo: qux # override default value
|
|
34
38
|
foo@staging: quux # deployment environment discriminator
|
|
35
|
-
|
|
39
|
+
bar: $BAZ_VALUE # secret
|
|
36
40
|
```
|
|
37
41
|
|
|
38
42
|
### Deploy secrets
|
|
@@ -49,126 +53,80 @@ $ toa conceal configuration BAZ_VALUE=$ecr3t
|
|
|
49
53
|
different configurations.
|
|
50
54
|
- Some algorithm parameters must be deployed secretly.
|
|
51
55
|
|
|
52
|
-
##
|
|
53
|
-
|
|
54
|
-
### Configuration (Distributed System Configuration)
|
|
55
|
-
|
|
56
|
-
Set of static[^1] parameters for all algorithms within a given system.
|
|
57
|
-
|
|
58
|
-
### Configuration Schema
|
|
59
|
-
|
|
60
|
-
Schema is defining component's algorithm parameters (optionally with default values).
|
|
61
|
-
|
|
62
|
-
### Configuration Object
|
|
63
|
-
|
|
64
|
-
Value valid against Configuration Schema.
|
|
65
|
-
|
|
66
|
-
### Configuration Value
|
|
67
|
-
|
|
68
|
-
The merge result of Configuration Schema's defaults and Configuration Object.
|
|
56
|
+
## Manifest
|
|
69
57
|
|
|
70
|
-
|
|
58
|
+
Component's configuration is declared using `configuration` manifest,
|
|
59
|
+
containing `schema` and optionnaly `defaults` properties.
|
|
71
60
|
|
|
72
|
-
|
|
61
|
+
### Schema
|
|
73
62
|
|
|
74
|
-
|
|
63
|
+
Configuration schema is declared with [COS](/libraries/concise).
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
See [Reusable Components](#).
|
|
81
|
-
|
|
82
|
-
## Configuration Schema
|
|
65
|
+
```yaml
|
|
66
|
+
# manifest.toa.yaml
|
|
67
|
+
name: dummy
|
|
68
|
+
namespace: dummies
|
|
83
69
|
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
configuration:
|
|
71
|
+
schema:
|
|
72
|
+
foo: string
|
|
73
|
+
bar: number
|
|
74
|
+
```
|
|
86
75
|
|
|
87
|
-
>
|
|
88
|
-
>
|
|
89
|
-
>
|
|
90
|
-
> Schema changes are subjects of component versioning.
|
|
76
|
+
> Introducing non-backward compatible changes to a configuration schema will result in a loss of
|
|
77
|
+
> compatibility with existing contexts and deployment environments.
|
|
78
|
+
> Therefore, configuration schema changes are subject to component versioning.
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
> Having default values for all required parameters will allow components to be runnable
|
|
94
|
-
> without configuration (i.e. on local environment).
|
|
80
|
+
### Defaults
|
|
95
81
|
|
|
96
|
-
|
|
82
|
+
The default configuration value can be provided using the `defaults` property, which should conform
|
|
83
|
+
to the configuration schema.
|
|
97
84
|
|
|
98
85
|
```yaml
|
|
99
|
-
#
|
|
86
|
+
# manifest.toa.yaml
|
|
100
87
|
name: dummy
|
|
101
88
|
namespace: dummies
|
|
102
89
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type: number
|
|
111
|
-
required: [foo]
|
|
90
|
+
configuration:
|
|
91
|
+
schema:
|
|
92
|
+
foo: string
|
|
93
|
+
bar: number
|
|
94
|
+
defaults:
|
|
95
|
+
foo: hello
|
|
96
|
+
bar: 0
|
|
112
97
|
```
|
|
113
98
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
As it is known that Configuration Schema is declared with a JSON Schema `object` type, any
|
|
117
|
-
configuration declaration without defined `properties` considered as concise. Properties of concise
|
|
118
|
-
declaration are treated as required Configuration Schema properties with the same type as its value
|
|
119
|
-
type and no additional properties allowed.
|
|
99
|
+
#### Schema defaults hint
|
|
120
100
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
The next two declarations are equivalent.
|
|
101
|
+
The configuration schema itself can contain default primitive values using the COS syntax.
|
|
124
102
|
|
|
125
103
|
```yaml
|
|
126
|
-
#
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
bar: 1
|
|
130
|
-
```
|
|
104
|
+
# manifest.toa.yaml
|
|
105
|
+
name: dummy
|
|
106
|
+
namespace: dummies
|
|
131
107
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
properties:
|
|
137
|
-
foo:
|
|
138
|
-
type: string
|
|
139
|
-
default: baz
|
|
140
|
-
bar:
|
|
141
|
-
type: number
|
|
142
|
-
default: 1
|
|
143
|
-
additionalProperties: false
|
|
144
|
-
required: [foo, bar]
|
|
108
|
+
configuration:
|
|
109
|
+
schema:
|
|
110
|
+
foo: hello
|
|
111
|
+
bar: 0
|
|
145
112
|
```
|
|
146
113
|
|
|
147
|
-
##
|
|
148
|
-
|
|
149
|
-
Context Configuration is declared as a context annotation. Its keys must be
|
|
150
|
-
component identifiers, and its values must be Configuration Objects for those
|
|
151
|
-
components.
|
|
152
|
-
|
|
153
|
-
Context Configuration keys and Configuration Object keys may be defined
|
|
154
|
-
with [deployment environment discriminators](#).
|
|
114
|
+
## Annotation
|
|
155
115
|
|
|
156
|
-
|
|
116
|
+
A component's configuration can be overridden using the configuration context annotation.
|
|
157
117
|
|
|
158
118
|
```yaml
|
|
159
119
|
# context.toa.yaml
|
|
160
120
|
configuration:
|
|
161
121
|
dummies.dummy:
|
|
162
|
-
foo:
|
|
122
|
+
foo: bye
|
|
163
123
|
bar: 1
|
|
164
124
|
bar@staging: 2
|
|
165
125
|
```
|
|
166
126
|
|
|
167
|
-
##
|
|
127
|
+
## Secrets
|
|
168
128
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
### Example
|
|
129
|
+
Configuration annotation values which are uppercase strings prefixed with `$` considered as secrets.
|
|
172
130
|
|
|
173
131
|
```yaml
|
|
174
132
|
# context.toa.yaml
|
|
@@ -177,14 +135,10 @@ configuration:
|
|
|
177
135
|
api-key: $STRIPE_API_KEY
|
|
178
136
|
```
|
|
179
137
|
|
|
180
|
-
Configuration values that are assigned with a reference to the Secret must be of type `string`.
|
|
181
|
-
|
|
182
|
-
### Secrets Deployment
|
|
183
|
-
|
|
184
138
|
Secrets are not being deployed with context
|
|
185
|
-
deployment ([`toa deploy`](
|
|
139
|
+
deployment ([`toa deploy`](/runtime/cli/readme.md#deploy)),
|
|
186
140
|
thus must be deployed separately at least once for each deployment environment
|
|
187
|
-
manually ([`toa conceal`](
|
|
141
|
+
manually ([`toa conceal`](/runtime/cli/readme.md#conceal)).
|
|
188
142
|
|
|
189
143
|
Deployed kubernetes secret's name is predefined as `configuration`.
|
|
190
144
|
|
|
@@ -194,11 +148,9 @@ $ toa conceal configuration STRIPE_API_KEY=xxxxxxxx
|
|
|
194
148
|
|
|
195
149
|
## Aspect
|
|
196
150
|
|
|
197
|
-
|
|
151
|
+
Component's configuration value is available as a well-known Aspect `configuration`.
|
|
198
152
|
|
|
199
153
|
```javascript
|
|
200
|
-
// Node.js bridge
|
|
201
|
-
|
|
202
154
|
function transition (input, entity, context) {
|
|
203
155
|
const foo = context.configiuration.foo
|
|
204
156
|
|
|
@@ -206,36 +158,13 @@ function transition (input, entity, context) {
|
|
|
206
158
|
}
|
|
207
159
|
```
|
|
208
160
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
> from [hot updates](#).
|
|
213
|
-
>
|
|
214
|
-
> ```javascript
|
|
215
|
-
> // NOT RECOMMENDED
|
|
216
|
-
> let foo
|
|
217
|
-
>
|
|
218
|
-
> function transition (input, entity, context) {
|
|
219
|
-
> // NOT RECOMMENDED
|
|
220
|
-
> if (foo === undefined) foo = context.configuration.foo
|
|
221
|
-
>
|
|
222
|
-
> // ...
|
|
223
|
-
> }
|
|
224
|
-
> ```
|
|
225
|
-
> See [Genuine operations](/documentation/design.md#genuine-operations).
|
|
226
|
-
|
|
227
|
-
## Development Configuration
|
|
228
|
-
|
|
229
|
-
Configuration can be exported by [`toa env`](/runtime/cli/readme.md#env).
|
|
230
|
-
|
|
231
|
-
### Local Environment Placeholders
|
|
232
|
-
|
|
233
|
-
Context Configuration values may contain placeholders that reference environment variables.
|
|
161
|
+
### Local environment placeholders
|
|
162
|
+
|
|
163
|
+
Configuration annotation values may contain placeholders that reference environment variables.
|
|
234
164
|
Placeholders are replaced with values if the corresponding environment variables are set.
|
|
235
165
|
|
|
236
|
-
> Placeholders can only be used with local environment (exported
|
|
237
|
-
> not
|
|
238
|
-
> deployed.
|
|
166
|
+
> Placeholders can only be used with local environment (exported
|
|
167
|
+
> by [`toa env`](/runtime/cli/readme.md#env)), as these values are not deployed.
|
|
239
168
|
|
|
240
169
|
```yaml
|
|
241
170
|
# context.toa.yaml
|
|
@@ -248,11 +177,3 @@ configuration:
|
|
|
248
177
|
# .env
|
|
249
178
|
STAGE=82
|
|
250
179
|
```
|
|
251
|
-
|
|
252
|
-
## Appendix
|
|
253
|
-
|
|
254
|
-
- [Discussion](./docs/discussion.md)
|
|
255
|
-
- [Configuration consistency](./docs/consistency.md)
|
|
256
|
-
|
|
257
|
-
[^1]: Cannot be changed without a deployment as new values are considered to be a subject of
|
|
258
|
-
testing. [#146](https://github.com/toa-io/toa/issues/146)
|
|
@@ -8,6 +8,8 @@ const find = require('../secrets')
|
|
|
8
8
|
* @return {toa.deployment.dependency.Variables}
|
|
9
9
|
*/
|
|
10
10
|
function secrets (components, annotations) {
|
|
11
|
+
if (annotations === undefined) return {}
|
|
12
|
+
|
|
11
13
|
/** @type {toa.deployment.dependency.Variables} */
|
|
12
14
|
const variables = {}
|
|
13
15
|
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const { encode } = require('@toa.io/generic')
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* @param {toa.norm.context.dependencies.Instance[]} components
|
|
7
|
-
* @param {object} annotations
|
|
8
|
-
* @return {toa.deployment.dependency.Variables}
|
|
9
|
-
*/
|
|
10
5
|
function variables (components, annotations) {
|
|
6
|
+
if (annotations === undefined) return {}
|
|
7
|
+
|
|
11
8
|
/** @type {toa.deployment.dependency.Variables} */
|
|
12
9
|
const variables = {}
|
|
13
10
|
|