Support empty default environment variable values (#1822)
* Add default env variable Add env variable test Co-Authored-By: Sarah Gammon <91751417+sarahg-579462@users.noreply.github.com> * Update test for empty env variable * Remove pygeoapi env variable from config --------- Co-authored-by: Sarah Gammon <91751417+sarahg-579462@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -168,7 +168,7 @@ def yaml_load(fh: IO) -> dict:
|
||||
# # https://stackoverflow.com/a/55301129
|
||||
|
||||
env_matcher = re.compile(
|
||||
r'.*?\$\{(?P<varname>\w+)(:-(?P<default>[^}]+))?\}')
|
||||
r'.*?\$\{(?P<varname>\w+)(:-(?P<default>[^}]*))?\}')
|
||||
|
||||
def env_constructor(loader, node):
|
||||
result = ""
|
||||
|
||||
@@ -31,7 +31,7 @@ server:
|
||||
bind:
|
||||
host: 0.0.0.0
|
||||
port: ${PYGEOAPI_PORT}
|
||||
url: http://localhost:5000/
|
||||
url: ${PYGEOAPI_URL:-http://localhost:5000/}
|
||||
mimetype: application/json; charset=UTF-8
|
||||
encoding: utf-8
|
||||
language: en-US
|
||||
@@ -43,6 +43,8 @@ server:
|
||||
map:
|
||||
url: https://tile.openstreetmap.org/{z}/{x}/{y}.png
|
||||
attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
|
||||
api_rules: # optional API design rules to which pygeoapi should adhere
|
||||
url_prefix: ${PYGEOAPI_PREFIX:-}
|
||||
|
||||
logging:
|
||||
level: DEBUG
|
||||
|
||||
@@ -54,8 +54,19 @@ def test_config_envvars():
|
||||
|
||||
assert isinstance(config, dict)
|
||||
assert config['server']['bind']['port'] == 5001
|
||||
assert config['server']['url'] == 'http://localhost:5000/'
|
||||
assert config['metadata']['identification']['title'] == \
|
||||
'pygeoapi default instance my title'
|
||||
assert config['server']['api_rules']['url_prefix'] == ''
|
||||
|
||||
os.environ['PYGEOAPI_URL'] = 'https://localhost:5000'
|
||||
os.environ['PYGEOAPI_PREFIX'] = 'v1'
|
||||
|
||||
with open(get_test_file_path('pygeoapi-test-config-envvars.yml')) as fh:
|
||||
config = yaml_load(fh)
|
||||
|
||||
assert config['server']['url'] == 'https://localhost:5000'
|
||||
assert config['server']['api_rules']['url_prefix'] == 'v1'
|
||||
|
||||
os.environ.pop('PYGEOAPI_PORT')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user