66from itertools import chain , groupby
77import shlex
88import sys
9- import types
109
1110from munch import Munch , munchify
1211import yaml
1312
1413from .path import find_environment_path , find_user_environment_paths
1514from functools import reduce
1615
17-
1816class LazyEnv (object ):
1917 def __init__ (self ):
2018 self .__mode = tuple (shlex .split (environ .get ('CLRENV_MODE' , '' )))
@@ -152,6 +150,14 @@ def _get_keyfile_cache():
152150 _kf_dict_cache = clrypt .read_file_as_dict ('keys' , 'keys' )
153151 return _kf_dict_cache
154152
153+ _ssm_client = None
154+ def _get_ssm_client ():
155+ import boto3
156+ global _ssm_client
157+ if not _ssm_client :
158+ _ssm_client = boto3 .client ('ssm' )
159+ return _ssm_client
160+
155161def _clear_keyfile_cache ():
156162 global _kf_dict_cache
157163 _kf_dict_cache = {}
@@ -162,19 +168,26 @@ def _apply_functions(d, recursive=False):
162168
163169 ^function rest
164170
165- Currently, the only function available is `keyfile', which attempts
166- to replace with a value from the currently loaded keyfile."""
171+ Available functions:
172+ ^keyfile: Looks up the given value in the current environment's clrypt keyfile.
173+ ^parameter: Looks up the given value in AWS Parameter store.
174+ """
167175 new = Munch ()
168176
169- for k , v in list (d .items ()):
170- if isinstance (v , dict ):
171- v = _apply_functions (v , recursive = True )
172- elif isinstance (v , str ):
173- if v .startswith ('^keyfile ' ):
174- v = v [9 :]
175- v = _get_keyfile_cache ().get (v , '' )
176-
177- new [k ] = v
177+ for key , value in list (d .items ()):
178+ if isinstance (value , dict ):
179+ value = _apply_functions (value , recursive = True )
180+ elif isinstance (value , str ):
181+ if value .startswith ('^keyfile ' ):
182+ value = value [9 :]
183+ value = _get_keyfile_cache ().get (value , '' )
184+ 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' ]
190+ new [key ] = value
178191
179192 if not recursive :
180193 # Cache no longer needed, clear encrypted data.
0 commit comments