Skip to content

Commit

Permalink
Allow generate_params.py to lookup of parameters outside of /adf
Browse files Browse the repository at this point in the history
**Why?**

Pipelines that need to read SSM parameters at different locations would not be
able to read outside of the /adf parameter path.
  • Loading branch information
sbkok committed Mar 22, 2024
1 parent 22f11f6 commit c33f8d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,23 @@ def fetch_parameters_by_path(self, path):
f'Parameter Path {PARAMETER_PREFIX}/{path} Not Found',
) from error

def fetch_parameter(self, name, with_decryption=False):
def fetch_parameter(self, name, with_decryption=False, adf_only=True):
"""Gets a Parameter from Parameter Store (Returns the Value)
"""
try:
LOGGER.debug('Fetching Parameter %s/%s', PARAMETER_PREFIX, name)
param_prefix = PARAMETER_PREFIX if adf_only else '/'
prefix_seperator = '' if name.startswith('/') else '/'
param_name = f"{param_prefix}{prefix_seperator}{name}"
LOGGER.debug(
'Fetching Parameter %s',
param_name,
)
response = self.client.get_parameter(
Name=f"{PARAMETER_PREFIX}/{name}",
Name=param_name,
WithDecryption=with_decryption
)
return response['Parameter']['Value']
except self.client.exceptions.ParameterNotFound as error:
raise ParameterNotFoundError(
f'Parameter {PARAMETER_PREFIX}/{name} Not Found',
f'Parameter {param_name} Not Found',
) from error
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def resolve(self, lookup_str: str, random_filename: str) -> str:
return self.cache.get(cache_key)
client = ParameterStore(region, boto3)
try:
param_value = client.fetch_parameter(param_path)
param_value = client.fetch_parameter(param_path, adf_only=False)
if param_value:
self.cache.add(f'{region}/{param_path}', param_value)
return param_value
Expand Down

0 comments on commit c33f8d8

Please sign in to comment.