Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
See gh-631
Closes gh-630
  • Loading branch information
benba authored and mp911de committed Feb 23, 2023
1 parent 03e3977 commit 2c596dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.boot.context.config.Profiles;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.MergedAnnotations;
Expand Down Expand Up @@ -193,9 +194,8 @@ private static VaultKeyValueBackendProperties getKeyValueProperties(ConfigDataLo
kvProperties.setApplicationName(binder.bind("spring.cloud.vault.kv.application-name", String.class)
.orElseGet(() -> binder.bind("spring.cloud.vault.application-name", String.class)
.orElseGet(() -> binder.bind("spring.application.name", String.class).orElse(""))));
if (kvProperties.profiles == null) {
kvProperties.setProfiles(profiles.getActive());
}
kvProperties.setProfiles(binder.bind("spring.cloud.vault.kv.profiles", Bindable.listOf(String.class))
.orElseGet(profiles::getActive));

return kvProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ private static Health getHealth(Builder builder, VaultHealthImpl vaultHealthResp
protected Mono<Health> doHealthCheck(Builder builder) {

return this.vaultOperations
.doWithVault(
(it) -> it.get().uri("sys/health").header(VaultHttpHeaders.VAULT_NAMESPACE, "").exchange())
.doWithVault((it) -> it.get().uri("sys/health").header(VaultHttpHeaders.VAULT_NAMESPACE, "").exchange())
.flatMap((it) -> it.bodyToMono(VaultHealthImpl.class))
.onErrorResume(WebClientResponseException.class, VaultReactiveHealthIndicator::deserializeError)
.map((vaultHealthResponse) -> getHealth(builder, vaultHealthResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

import org.junit.Before;
import org.junit.Test;

import org.springframework.boot.DefaultBootstrapContext;
import org.springframework.boot.context.config.ConfigDataLocation;
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
import org.springframework.boot.context.config.Profiles;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.core.env.MapPropertySource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
Expand All @@ -39,6 +40,7 @@
*
* @author Mark Paluch
* @author Jeffrey van der Laan
* @author Benjamin Bargeton
*/
public class VaultConfigDataLocationResolverUnitTests {

Expand Down Expand Up @@ -121,4 +123,18 @@ public void shouldNotPrefixWhenPrefixIsEmpty() {
.transformProperties(Collections.singletonMap("key", "value"))).containsEntry("key", "value");
}

@Test
public void kvProfilesPropertyPrecedenceShouldBeRespected() {

VaultConfigDataLocationResolver resolver = new VaultConfigDataLocationResolver();

when(this.profilesMock.getActive()).thenReturn(Arrays.asList("a", "b"));
when(this.contextMock.getBinder()).thenReturn(new Binder(ConfigurationPropertySource.from(
new MapPropertySource("test", Collections.singletonMap("spring.cloud.vault.kv.profiles", "c, d, e")))));

assertThat(
resolver.resolveProfileSpecific(this.contextMock, ConfigDataLocation.of("vault://"), this.profilesMock))
.hasSize(4);
}

}

0 comments on commit 2c596dd

Please sign in to comment.