Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empty default environment variable values #1822

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygeoapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 3 additions & 1 deletion tests/pygeoapi-test-config-envvars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Loading