diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/parameter_store.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/parameter_store.py index 0c470881a..690656dbf 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/parameter_store.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/parameter_store.py @@ -91,9 +91,13 @@ def fetch_parameters_by_path(self, path): @staticmethod def _build_param_name(name, adf_only=True): - param_prefix = PARAMETER_PREFIX if adf_only else '' - prefix_seperator = '' if name.startswith('/') else '/' - return f"{param_prefix}{prefix_seperator}{name}" + slash_name = name if name.startswith('/') else f"/{name}" + add_prefix = ( + adf_only + and not slash_name.startswith(PARAMETER_PREFIX) + ) + param_prefix = PARAMETER_PREFIX if add_prefix else '' + return f"{param_prefix}{slash_name}" def fetch_parameter(self, name, with_decryption=False, adf_only=True): """Gets a Parameter from Parameter Store (Returns the Value) diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/tests/test_parameter_store.py b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/tests/test_parameter_store.py index 563d658e3..f8e3d277a 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/tests/test_parameter_store.py +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/tests/test_parameter_store.py @@ -5,7 +5,7 @@ import os import boto3 -from pytest import fixture +from pytest import fixture, mark from stubs import stub_parameter_store from mock import Mock @@ -21,6 +21,39 @@ def cls(): return cls +@mark.parametrize( + "input_name, output_path", + [ + ('/adf/test', '/adf/test'), + ('adf/test', '/adf/test'), + ('/test', '/test'), + ('test', '/test'), + ('/other/test', '/other/test'), + ('other/test', '/other/test'), + ], +) +def test_build_param_name_not_adf_only(input_name, output_path): + assert ParameterStore._build_param_name( + input_name, + adf_only=False, + ) == output_path + + +@mark.parametrize( + "input_name, output_path", + [ + ('/adf/test', '/adf/test'), + ('adf/test', '/adf/test'), + ('/test', '/adf/test'), + ('test', '/adf/test'), + ('/other/test', '/adf/other/test'), + ('other/test', '/adf/other/test'), + ], +) +def test_build_param_name_adf_only(input_name, output_path): + assert ParameterStore._build_param_name(input_name) == output_path + + def test_fetch_parameter(cls): cls.client = Mock() cls.client.get_parameter.return_value = stub_parameter_store.get_parameter