|
3 | 3 | import os.path |
4 | 4 | from os import environ |
5 | 5 | from glob import glob |
6 | | -from itertools import chain, groupby |
| 6 | +from itertools import chain |
7 | 7 | import shlex |
8 | 8 | import sys |
| 9 | +import logging |
| 10 | +import socket |
9 | 11 |
|
10 | 12 | from munch import Munch, munchify |
11 | 13 | import yaml |
12 | 14 |
|
13 | 15 | from .path import find_environment_path, find_user_environment_paths |
14 | 16 | from functools import reduce |
15 | 17 |
|
| 18 | +logger = logging.getLogger(__name__) |
| 19 | + |
| 20 | +# Flag to prevent clrenv from throwing errors |
| 21 | +# if it cannot connect to the Parameter Store API. |
| 22 | +OFFLINE_FLAG = 'CLRENV_OFFLINE_DEV' |
| 23 | +OFFLINE_VALUE = 'CLRENV_OFFLINE_PLACEHOLDER' |
| 24 | + |
| 25 | + |
16 | 26 | class LazyEnv(object): |
17 | 27 | def __init__(self): |
18 | 28 | self.__mode = tuple(shlex.split(environ.get('CLRENV_MODE', ''))) |
@@ -85,7 +95,6 @@ def get_env(*mode): |
85 | 95 |
|
86 | 96 | _env[mode] = e |
87 | 97 |
|
88 | | - |
89 | 98 | return _env[mode] |
90 | 99 |
|
91 | 100 | def _coerce_none_to_string(d): |
@@ -182,11 +191,15 @@ def _apply_functions(d, recursive=False): |
182 | 191 | value = value[9:] |
183 | 192 | value = _get_keyfile_cache().get(value, '') |
184 | 193 | elif value.startswith("^parameter "): |
185 | | - value = value.split(' ', 1)[1] |
186 | | - value = _get_ssm_client().get_parameter( |
187 | | - Name=value, |
188 | | - WithDecryption=True |
189 | | - )['Parameter']['Value'] |
| 194 | + parameter_name = value.split(' ', 1)[1] |
| 195 | + if os.environ.get(OFFLINE_FLAG): |
| 196 | + logger.warning(f"[{socket.gethostname()}] Offline, using placeholder value for {parameter_name}.") |
| 197 | + value = OFFLINE_VALUE |
| 198 | + else: |
| 199 | + value = _get_ssm_client().get_parameter( |
| 200 | + Name=parameter_name, |
| 201 | + WithDecryption=True |
| 202 | + )['Parameter']['Value'] |
190 | 203 | new[key] = value |
191 | 204 |
|
192 | 205 | if not recursive: |
|
0 commit comments