Skip to content

Commit

Permalink
add separator-option in paramstore post processor
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoelfel authored and frankbregulla1111 committed Feb 12, 2024
1 parent 3ccaba2 commit 30118bf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 3.2.1
* **[edison-core]**
* Add seperator-option to use sections in a parameter name as properties e.g. `some/value` results in `some.value` with a seperator of `/`

## 3.2.0
* **[all]**
* Spring Boot 3.2.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ParamStoreProperties {
private String path;
private boolean addWithLowestPrecedence;

private String separator;

public ParamStoreProperties() {
}

Expand All @@ -34,4 +36,13 @@ public boolean isAddWithLowestPrecedence() {
public void setAddWithLowestPrecedence(final boolean addWithLowestPrecedence) {
this.addWithLowestPrecedence = addWithLowestPrecedence;
}


public String getSeparator() {
return separator;
}

public void setSeparator(String separator) {
this.separator = separator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFac

private void addParametersToPropertiesSource(final Properties propertiesSource, final List<Parameter> parameters) {
parameters.forEach(p -> {
final String name = p.name().substring(properties.getPath().length() + 1);
String name = p.name().substring(properties.getPath().length() + 1);
if (StringUtils.hasText(properties.getSeparator())) {
name = name.replaceAll(properties.getSeparator(), ".");
}
final String loggingValue = SECURE_STRING == p.type() ? "*****" : p.value();
LOG.info("Loaded '" + name + "' from ParametersStore, value='" + loggingValue + "', length=" + p.value().length());

Expand All @@ -87,6 +90,7 @@ public void setEnvironment(final Environment environment) {
final String path = requireNonNull(environment.getProperty(pathProperty),
"Property '" + pathProperty + "' must not be null");
properties = new ParamStoreProperties();
properties.setSeparator(environment.getProperty("edison.env.paramstore.separator"));
properties.setAddWithLowestPrecedence(
parseBoolean(environment.getProperty("edison.env.paramstore.addWithLowestPrecedence", "false")));
properties.setPath(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public SsmClient ssmClient() {
SsmClient mock = mock(SsmClient.class);
when(mock.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(
GetParametersByPathResponse.builder()
.parameters(Parameter.builder().name("mongo/password").value("secret").build())
.parameters(
Parameter.builder().name("mongo/password").value("secret").build(),
Parameter.builder().name("mongo/subSection/config").value("someConfig").build()
)
.build()
);
return mock;
Expand All @@ -59,6 +62,21 @@ void shouldLoadPropertiesFromParamStore() {
assertThat(this.context.containsBean("paramStorePropertySourcePostProcessor"), is(true));
assertThat(this.context.getEnvironment().getPropertySources().contains("paramStorePropertySource"), is(true));
assertEquals("secret", this.context.getEnvironment().getProperty("password"));
assertEquals("someConfig", this.context.getEnvironment().getProperty("subSection/config"));
}

@Test
void shouldLoadPropertiesWithSeperatorsFromParamStore() {
this.context.register(ParamStoreTestConfiguration.class);
TestPropertyValues
.of("edison.env.paramstore.enabled=true")
.and("edison.env.paramstore.path=mongo")
.and("edison.env.paramstore.separator=/")
.applyTo(context);
this.context.refresh();
assertThat(this.context.containsBean("paramStorePropertySourcePostProcessor"), is(true));
assertThat(this.context.getEnvironment().getPropertySources().contains("paramStorePropertySource"), is(true));
assertEquals("someConfig", this.context.getEnvironment().getProperty("subSection.config"));
}

@Test
Expand Down

0 comments on commit 30118bf

Please sign in to comment.