Return VaultResponse in ReactiveVaultOperations.write(…).
We now return the actual response when writing to a Vault path. Closes gh-177.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.vault.VaultException;
|
||||
import org.springframework.vault.support.VaultResponse;
|
||||
import org.springframework.vault.support.VaultResponseSupport;
|
||||
@@ -74,6 +75,16 @@ public interface ReactiveVaultOperations {
|
||||
*/
|
||||
Flux<String> list(String path);
|
||||
|
||||
/**
|
||||
* Write to a secret backend.
|
||||
*
|
||||
* @param path must not be {@literal null}.
|
||||
* @return the configuration data. May be empty but never {@literal null}.
|
||||
*/
|
||||
default Mono<VaultResponse> write(String path) {
|
||||
return write(path, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to a secret backend.
|
||||
*
|
||||
@@ -81,7 +92,7 @@ public interface ReactiveVaultOperations {
|
||||
* @param body the body, may be {@literal null} if absent.
|
||||
* @return the configuration data. May be empty but never {@literal null}.
|
||||
*/
|
||||
Mono<Void> write(String path, Object body);
|
||||
Mono<VaultResponse> write(String path, @Nullable Object body);
|
||||
|
||||
/**
|
||||
* Delete a path in the secret backend.
|
||||
|
||||
@@ -26,6 +26,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.vault.VaultException;
|
||||
import org.springframework.vault.authentication.SessionManager;
|
||||
@@ -45,6 +46,7 @@ import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClientException;
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec;
|
||||
|
||||
import static org.springframework.web.reactive.function.client.ExchangeFilterFunction.ofRequestProcessor;
|
||||
|
||||
@@ -141,12 +143,19 @@ public class ReactiveVaultTemplate implements ReactiveVaultOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> write(String path, Object body) {
|
||||
public Mono<VaultResponse> write(String path, @Nullable Object body) {
|
||||
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
|
||||
return sessionClient.post().uri(path).syncBody(body).exchange()
|
||||
.flatMap(mapResponse(VaultResponse.class, path)).then();
|
||||
RequestBodySpec uri = sessionClient.post().uri(path);
|
||||
Mono<ClientResponse> exchange;
|
||||
if (body != null) {
|
||||
exchange = uri.syncBody(body).exchange();
|
||||
}
|
||||
else {
|
||||
exchange = uri.exchange();
|
||||
}
|
||||
return exchange.flatMap(mapResponse(VaultResponse.class, path));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,7 +136,6 @@ public class ReactiveVaultTemplateGenericIntegrationTests extends IntegrationTes
|
||||
StepVerifier.create(vaultOperations.list("secret").collectList())
|
||||
.consumeNextWith(actual -> assertThat(actual).contains("mykey"))
|
||||
.verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,6 +150,17 @@ public class ReactiveVaultTemplateGenericIntegrationTests extends IntegrationTes
|
||||
StepVerifier.create(vaultOperations.read("secret/mykey")).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeShouldReturnResponse() {
|
||||
|
||||
StepVerifier.create(vaultOperations.write("auth/token/create"))
|
||||
.assertNext(response -> {
|
||||
|
||||
assertThat(response.getAuth()).isNotNull();
|
||||
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
static class Person {
|
||||
|
||||
String firstname;
|
||||
|
||||
Reference in New Issue
Block a user