Skip to content

Commit

Permalink
Treat missing WAL-E environment variables as empty strings
Browse files Browse the repository at this point in the history
This fixes crashes when e.g. the `WAL_BUCKET_SCOPE_PREFIX` or
`WAL_BUCKET_SCOPE_SUFFIX` variables are unset.
  • Loading branch information
Manuel Gómez authored and mgomezch committed Mar 1, 2018
1 parent 7404798 commit b8eaeec
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions postgres-appliance/configure_spilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys

from six.moves.urllib_parse import urlparse
from collections import defaultdict

import yaml
import pystache
Expand Down Expand Up @@ -470,13 +471,21 @@ def get_dcs_config(config, placeholders):


def write_wale_environment(placeholders, provider, prefix, overwrite):
wale = {}

for name in ('SCOPE', 'WALE_ENV_DIR', 'WAL_S3_BUCKET', 'WAL_BUCKET_SCOPE_PREFIX', 'WAL_BUCKET_SCOPE_SUFFIX',
'WAL_GCS_BUCKET', 'GOOGLE_APPLICATION_CREDENTIALS'):
rename = prefix + name
if rename in placeholders:
wale[name] = placeholders[rename]
# Propagate missing variables as empty strings as that's generally easier
# to work around than an exception in this code.
wale = defaultdict(lambda: '')
wale.update({
name: placeholders.get(prefix + name, '')
for name in [
'SCOPE',
'WALE_ENV_DIR',
'WAL_S3_BUCKET',
'WAL_BUCKET_SCOPE_PREFIX',
'WAL_BUCKET_SCOPE_SUFFIX',
'WAL_GCS_BUCKET',
'GOOGLE_APPLICATION_CREDENTIALS',
]
})

if not os.path.exists(wale['WALE_ENV_DIR']):
os.makedirs(wale['WALE_ENV_DIR'])
Expand Down

0 comments on commit b8eaeec

Please sign in to comment.