Skip to content

fix: #758 #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ public BaseProvider withTransformation(Class<? extends Transformer> transformerC
*/
@Override
public Map<String, String> getMultiple(String path) {
// remove trailing whitespace
String pathWithoutTrailingSlash = path.replaceAll("\\/+$", "");
try {
return (Map<String, String>) cacheManager.getIfNotExpired(path, now()).orElseGet(() -> {
Map<String, String> params = getMultipleValues(path);
return (Map<String, String>) cacheManager.getIfNotExpired(pathWithoutTrailingSlash, now()).orElseGet(() -> {
Map<String, String> params = getMultipleValues(pathWithoutTrailingSlash);

cacheManager.putInCache(path, params);
cacheManager.putInCache(pathWithoutTrailingSlash, params);

params.forEach((k, v) -> cacheManager.putInCache(path + "/" + k, v));
params.forEach((k, v) -> cacheManager.putInCache(pathWithoutTrailingSlash + "/" + k, v));

return params;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ public void getMultiple() {
assertThat(paramByPathCaptor.getValue().recursive()).isFalse();
}

@Test
public void getMultipleWithTrailingSlash() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder().name("/prod/app1/key1").value("foo1").build());
parameters.add(Parameter.builder().name("/prod/app1/key2").value("foo2").build());
parameters.add(Parameter.builder().name("/prod/app1/key3").value("foo3").build());
GetParametersByPathResponse response = GetParametersByPathResponse.builder().parameters(parameters).build();
when(client.getParametersByPath(paramByPathCaptor.capture())).thenReturn(response);

Map<String, String> params = provider.getMultiple("/prod/app1/");
assertThat(params).contains(
MapEntry.entry("key1", "foo1"),
MapEntry.entry("key2", "foo2"),
MapEntry.entry("key3", "foo3"));
assertThat(provider.get("/prod/app1/key1")).isEqualTo("foo1");
assertThat(provider.get("/prod/app1/key2")).isEqualTo("foo2");
assertThat(provider.get("/prod/app1/key3")).isEqualTo("foo3");

assertThat(paramByPathCaptor.getValue().path()).isEqualTo("/prod/app1");
assertThat(paramByPathCaptor.getValue().withDecryption()).isFalse();
assertThat(paramByPathCaptor.getValue().recursive()).isFalse();
}

@Test
public void getMultiple_cached_shouldNotCallSSM() {
List<Parameter> parameters = new ArrayList<>();
Expand Down