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:
Benjamin Webb
2024-11-19 20:53:28 -05:00
committed by GitHub
parent 3188db91da
commit 065ef3a495
3 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -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 = ""
+3 -1
View File
@@ -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: '&copy; <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
+11
View File
@@ -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')