Polishing.
See gh-631 Closes gh-630
This commit is contained in:
committed by
Mark Paluch
parent
03e397765c
commit
2c596dd474
@@ -31,6 +31,7 @@ import org.springframework.boot.context.config.ConfigDataLocationResolverContext
|
||||
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;
|
||||
@@ -193,9 +194,8 @@ public class VaultConfigDataLocationResolver implements ConfigDataLocationResolv
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ public class VaultReactiveHealthIndicator extends AbstractReactiveHealthIndicato
|
||||
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));
|
||||
|
||||
@@ -22,12 +22,13 @@ import java.util.List;
|
||||
|
||||
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;
|
||||
@@ -39,6 +40,7 @@ import static org.mockito.Mockito.when;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Jeffrey van der Laan
|
||||
* @author Benjamin Bargeton
|
||||
*/
|
||||
public class VaultConfigDataLocationResolverUnitTests {
|
||||
|
||||
@@ -121,4 +123,18 @@ public class VaultConfigDataLocationResolverUnitTests {
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user