Skip to content

Commit

Permalink
Ensure setting /adf in the name of the param does not lead to double …
Browse files Browse the repository at this point in the history
…/adf/adf

**Why?**

If an end-user defines a parameter to `/adf/something`, it would render to
`/adf/adf/something`. This should autofix itself.
  • Loading branch information
sbkok committed Apr 5, 2024
1 parent d1f5b27 commit b7129da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit b7129da

Please sign in to comment.