Skip to content

Commit b7129da

Browse files
committed
Ensure setting /adf in the name of the param does not lead to double /adf/adf
**Why?** If an end-user defines a parameter to `/adf/something`, it would render to `/adf/adf/something`. This should autofix itself.
1 parent d1f5b27 commit b7129da

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/parameter_store.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ def fetch_parameters_by_path(self, path):
9191

9292
@staticmethod
9393
def _build_param_name(name, adf_only=True):
94-
param_prefix = PARAMETER_PREFIX if adf_only else ''
95-
prefix_seperator = '' if name.startswith('/') else '/'
96-
return f"{param_prefix}{prefix_seperator}{name}"
94+
slash_name = name if name.startswith('/') else f"/{name}"
95+
add_prefix = (
96+
adf_only
97+
and not slash_name.startswith(PARAMETER_PREFIX)
98+
)
99+
param_prefix = PARAMETER_PREFIX if add_prefix else ''
100+
return f"{param_prefix}{slash_name}"
97101

98102
def fetch_parameter(self, name, with_decryption=False, adf_only=True):
99103
"""Gets a Parameter from Parameter Store (Returns the Value)

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/python/tests/test_parameter_store.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import os
77
import boto3
8-
from pytest import fixture
8+
from pytest import fixture, mark
99
from stubs import stub_parameter_store
1010
from mock import Mock
1111

@@ -21,6 +21,39 @@ def cls():
2121
return cls
2222

2323

24+
@mark.parametrize(
25+
"input_name, output_path",
26+
[
27+
('/adf/test', '/adf/test'),
28+
('adf/test', '/adf/test'),
29+
('/test', '/test'),
30+
('test', '/test'),
31+
('/other/test', '/other/test'),
32+
('other/test', '/other/test'),
33+
],
34+
)
35+
def test_build_param_name_not_adf_only(input_name, output_path):
36+
assert ParameterStore._build_param_name(
37+
input_name,
38+
adf_only=False,
39+
) == output_path
40+
41+
42+
@mark.parametrize(
43+
"input_name, output_path",
44+
[
45+
('/adf/test', '/adf/test'),
46+
('adf/test', '/adf/test'),
47+
('/test', '/adf/test'),
48+
('test', '/adf/test'),
49+
('/other/test', '/adf/other/test'),
50+
('other/test', '/adf/other/test'),
51+
],
52+
)
53+
def test_build_param_name_adf_only(input_name, output_path):
54+
assert ParameterStore._build_param_name(input_name) == output_path
55+
56+
2457
def test_fetch_parameter(cls):
2558
cls.client = Mock()
2659
cls.client.get_parameter.return_value = stub_parameter_store.get_parameter

0 commit comments

Comments
 (0)