fixed env var parser
This commit is contained in:
parent
1363030b95
commit
20c520aa17
@ -1,6 +1,7 @@
|
||||
"""Implements a config object with dot-indexing syntax."""
|
||||
import os
|
||||
from itertools import chain
|
||||
from operator import truth
|
||||
|
||||
from envyaml import EnvYAML
|
||||
from funcy import first, juxt, butlast, last
|
||||
@ -51,4 +52,4 @@ def parse_disjunction_string(disjunction_string):
|
||||
|
||||
options = disjunction_string.split("|")
|
||||
identifiers, fallback_value = juxt(butlast, last)(options)
|
||||
return first(chain(filter(try_parse_env_var, identifiers), [fallback_value]))
|
||||
return first(chain(filter(truth, map(try_parse_env_var, identifiers)), [fallback_value]))
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from pyinfra.config import Config
|
||||
from pyinfra.config import Config, parse_disjunction_string
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -36,3 +37,9 @@ def test_dot_access_key_does_not_exists(config):
|
||||
|
||||
def test_access_key_does_not_exists(config):
|
||||
assert config["B"] is None
|
||||
|
||||
|
||||
def test_parse_disjunction_string():
|
||||
assert parse_disjunction_string("A|Bb|c") == "c"
|
||||
os.environ["Bb"] = "d"
|
||||
assert parse_disjunction_string("A|Bb|c") == "d"
|
||||
|
||||
@ -27,8 +27,10 @@ def get_object_descriptor(body):
|
||||
|
||||
|
||||
def get_response_object_descriptor(body):
|
||||
return {"bucket_name": parse_disjunction_string(CONFIG.storage.bucket),
|
||||
"object_name": get_response_object_name(body)}
|
||||
return {
|
||||
"bucket_name": parse_disjunction_string(CONFIG.storage.bucket),
|
||||
"object_name": get_response_object_name(body),
|
||||
}
|
||||
|
||||
|
||||
class ResponseStrategy(abc.ABC):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user