On Wed, 28 Apr 2021 at 13:01, Jan Kiszka <
jan.k...@siemens.com> wrote:
> Or we permit
>
> env:
> BB_NUMBER_THREADS:
>
> i.e. an empty default. I'm not even sure if that was possible before we
> introduce the schema. Maybe the code would do the right thing (it
> already checks if the var is in the environment).
Just BB_NUMBER_THREADS: isn't valid YAML, but ~ or null are parsed as
None, the schema can be told to allow null, and then the environment
function can filter out variables with no value set.
I tried to post a patch but I think its in the moderation queue.
Something like this works:
diff --git a/kas/config.py b/kas/config.py
index 0119f68..e5cb1a3 100644
--- a/kas/config.py
+++ b/kas/config.py
@@ -163,8 +163,13 @@ class Config:
Returns the configured environment variables from the configuration
file with possible overwritten values from the environment.
"""
+ # Defaults from the configuration
env = self._config.get('env', {})
- return {var: os.environ.get(var, env[var]) for var in env}
+ # Update from the environment
+ env = {var: os.environ.get(var, env[var]) for var in env}
+ # Remove entries with no value set
+ env = {k:v for k,v in env.items() if v is not None}
+ return env
def get_multiconfig(self):
"""
diff --git a/kas/configschema.py b/kas/configschema.py
index b97ef42..e9867d1 100644
--- a/kas/configschema.py
+++ b/kas/configschema.py
@@ -109,7 +109,14 @@ CONFIGSCHEMA = {
'env': {
'type': 'object',
'additionalProperties': {
- 'type': 'string',
+ 'oneOf': [
+ {
+ 'type': 'null',
+ },
+ {
+ 'type': 'string',
+ },
+ ],
},
},
'target': {
Ross