Skip to content

Commit e8b7b08

Browse files
author
Alan Christie
committed
Adds 'value-from : secret'
1 parent c1fce15 commit e8b7b08

File tree

2 files changed

+100
-23
lines changed

2 files changed

+100
-23
lines changed

decoder/schema.yaml

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,36 +142,74 @@ definitions:
142142
type: array
143143
items:
144144
anyOf:
145-
- $ref: '#/definitions/environment-value-from-api-token'
145+
- $ref: '#/definitions/environment-value-from'
146146

147-
# An Image environment from an 'api-token'.
148-
# Roles is an optional list of API token realm roles where, for now,
149-
# we limit the number in the list to a maximum 1.
150-
environment-value-from-api-token:
147+
# An Image environment from something else.
148+
environment-value-from:
151149
type: object
152150
additionalProperties: false
153151
properties:
154152
name:
155153
$ref: '#/definitions/env-var-name'
156154
value-from:
155+
oneOf:
156+
- $ref: '#/definitions/environment-value-from-api-token'
157+
- $ref: '#/definitions/environment-value-from-secret'
158+
required:
159+
- name
160+
- value-from
161+
162+
# Declaration for value-from 'api-token'.
163+
# User provides a list of roles (which can be empty).
164+
# Here, we limit the number of roles to 1.
165+
environment-value-from-api-token:
166+
type: object
167+
additionalProperties: false
168+
properties:
169+
api-token:
157170
type: object
158171
properties:
159-
api-token:
160-
type: object
161-
properties:
162-
roles:
163-
type: array
164-
items:
165-
type: string
166-
pattern: '^[a-z]{1,}[a-z-_]{0,}$'
167-
minItems: 0
168-
maxItems: 1
169-
uniqueItems: true
172+
roles:
173+
type: array
174+
items:
175+
type: string
176+
pattern: '^[a-z]{1,}[a-z-_]{0,}$'
177+
minItems: 0
178+
maxItems: 1
179+
uniqueItems: true
170180
required:
171-
- api-token
181+
- roles
172182
required:
173-
- name
174-
- value-from
183+
- api-token
184+
185+
# An Image environment from a Kubernetes 'secret'.
186+
# At the moment we expect the secret to be unencrypted,
187+
# just 'opaque', so it can be read by the DM without special actions.
188+
environment-value-from-secret:
189+
type: object
190+
additionalProperties: false
191+
properties:
192+
secret:
193+
type: object
194+
properties:
195+
# The name of the secret object,
196+
# i.e. its metadata->name.
197+
name:
198+
$ref: '#/definitions/rfc-1035-name'
199+
# The name of the key in the secret.
200+
# - Begins with lowercase letter
201+
# - Then lower-case alphanumeric including '-', '_' and '.'
202+
# - Ends begins with lower-case alphanumeric
203+
key:
204+
type: string
205+
minLength: 1
206+
maxLength: 63
207+
pattern: '^[a-z]([a-z0-9-_.]*[a-z0-9])?$'
208+
required:
209+
- name
210+
- key
211+
required:
212+
- secret
175213

176214
# The pattern for Image environment names.
177215
# Classic linux/shell,

tests/test_validate_job_schema.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Tests for the schema validator.
22
from typing import Any, Dict
3+
from copy import deepcopy
34

45
import pytest
56
pytestmark = pytest.mark.unit
67

78
from decoder import decoder
89

9-
10-
def test_validate_minimal():
11-
# Arrange
12-
text: Dict[str, Any] = {
10+
# A minimal Job Definition.
11+
# Tests can use this and adjust accordingly.
12+
_MINIMAL: Dict[str, Any] = {
1313
'kind': 'DataManagerJobDefinition',
1414
'kind-version': '2021.1',
1515
'collection': 'test',
@@ -22,6 +22,45 @@ def test_validate_minimal():
2222
'project-directory': '/data'},
2323
'command': 'sys.exit(1)'}}}
2424

25+
26+
def test_validate_minimal():
27+
# Arrange
28+
29+
# Act
30+
error = decoder.validate_job_schema(_MINIMAL)
31+
32+
# Assert
33+
assert error is None
34+
35+
36+
def test_validate_image_env_from_api_token():
37+
# Arrange
38+
text: Dict[str, Any] = deepcopy(_MINIMAL)
39+
demo_job: Dict[str, Any] = text['jobs']['demo']
40+
demo_job['image']['environment'] = \
41+
[{'name': 'ENV_VAR',
42+
'value-from': {
43+
'api-token': {
44+
'roles': ['abc']}}}]
45+
46+
# Act
47+
error = decoder.validate_job_schema(text)
48+
49+
# Assert
50+
assert error is None
51+
52+
53+
def test_validate_image_env_from_secret():
54+
# Arrange
55+
text: Dict[str, Any] = deepcopy(_MINIMAL)
56+
demo_job: Dict[str, Any] = text['jobs']['demo']
57+
demo_job['image']['environment'] = \
58+
[{'name': 'ENV_VAR',
59+
'value-from': {
60+
'secret': {
61+
'name': 'secret-a',
62+
'key': 'secret'}}}]
63+
2564
# Act
2665
error = decoder.validate_job_schema(text)
2766

0 commit comments

Comments
 (0)