Skip to content

Commit

Permalink
Move off deprecated API.
Browse files Browse the repository at this point in the history
See gh-874
  • Loading branch information
mp911de committed Aug 7, 2024
1 parent 11b6790 commit 0ea3ddf
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;

import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;

/**
* Default implementation of{@link GcpProjectIdAccessor} and
Expand All @@ -34,7 +34,7 @@ enum DefaultGcpCredentialAccessors implements GcpProjectIdAccessor, GcpServiceAc
INSTANCE;

/**
* Get a the service account id (email) to be placed in the signed JWT.
* Get the service account id (email) to be placed in the signed JWT.
* @param credential credential object to obtain the service account id from.
* @return the service account id to use.
*/
Expand All @@ -49,7 +49,7 @@ public String getServiceAccountId(GoogleCredential credential) {
}

/**
* Get a the GCP project id to used in Google Cloud IAM API calls.
* Get the GCP project id to used in Google Cloud IAM API calls.
* @param credential the credential object to obtain the project id from.
* @return the service account id to use.
*/
Expand All @@ -58,7 +58,7 @@ public String getProjectId(GoogleCredential credential) {

Assert.notNull(credential, "GoogleCredential must not be null");

return StringUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
return ObjectUtils.isEmpty(credential.getServiceAccountProjectId()) ? "-"
: credential.getServiceAccountProjectId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContextBuilder;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
Expand All @@ -54,10 +54,8 @@

/**
* Factory for {@link ClientHttpConnector} that supports
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}.
*
* This factory configures a {@link ClientHttpConnector} depending on the available
* dependencies.
* {@link ReactorClientHttpConnector} and {@link JettyClientHttpConnector}. This factory
* configures a {@link ClientHttpConnector} depending on the available dependencies.
*
* @author Mark Paluch
* @author Ryan Gow
Expand Down Expand Up @@ -208,6 +206,24 @@ public static HttpAsyncClientBuilder createHttpAsyncClientBuilder(ClientOptions
httpClientBuilder.setRoutePlanner(
new SystemDefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));

Timeout readTimeout = Timeout.ofMilliseconds(options.getReadTimeout().toMillis());
Timeout connectTimeout = Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis());

ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setConnectTimeout(connectTimeout) //
.setSocketTimeout(readTimeout) //
.build();

RequestConfig requestConfig = RequestConfig.custom()
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
.setAuthenticationEnabled(true) //
.setRedirectsEnabled(true)
.build();

PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder //
.create()
.setDefaultConnectionConfig(connectionConfig);

if (hasSslConfiguration(sslConfiguration)) {

SSLContext sslContext = getSSLContext(sslConfiguration);
Expand All @@ -229,21 +245,11 @@ public static HttpAsyncClientBuilder createHttpAsyncClientBuilder(ClientOptions
}
}, null);

PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder //
.create()
.setTlsStrategy(tlsStrategy) //
.build(); //
httpClientBuilder.setConnectionManager(connectionManager);
connectionManagerBuilder.setTlsStrategy(tlsStrategy);
}

RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()))
.setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis()))
.setAuthenticationEnabled(true) //
.setRedirectsEnabled(true)
.build();

httpClientBuilder.setDefaultRequestConfig(requestConfig);
httpClientBuilder.setConnectionManager(connectionManagerBuilder.build());

return httpClientBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ private <S> S read(VaultPersistentEntity<S> entity, SecretDocument source) {
Object idValue;

if (entity.requiresPropertyPopulation()) {
if (idProperty != null && !entity.isConstructorArgument(idProperty)
&& documentAccessor.hasValue(idProperty)) {
if (idProperty != null && !entity.isCreatorArgument(idProperty) && documentAccessor.hasValue(idProperty)) {

idValue = readIdValue(idProperty, documentAccessor);
accessor.setProperty(idProperty, idValue);
Expand Down Expand Up @@ -210,7 +209,7 @@ private void readProperties(VaultPersistentEntity<?> entity, PersistentPropertyA
continue;
}

if (entity.isConstructorArgument(prop) || !documentAccessor.hasValue(prop)) {
if (entity.isCreatorArgument(prop) || !documentAccessor.hasValue(prop)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ void shouldUseVaultEndpointProvider() {

client.get()
.uri("/sys/health")
.exchange()
.flatMap(it -> it.bodyToMono(String.class))
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.consumeNextWith(actual -> {
assertThat(actual).contains("initialized").contains("standby");
Expand All @@ -61,8 +60,7 @@ void shouldUseVaultEndpointProvider() {

client.get()
.uri("sys/health")
.exchange()
.flatMap(it -> it.bodyToMono(String.class))
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.consumeNextWith(actual -> {
assertThat(actual).contains("initialized").contains("standby");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void shouldApplyCustomizerToWebClientFactory() {
WebClientFactory factory = context.getBean(WebClientFactory.class);
WebClient webClient = factory.create();

webClient.get().uri("/foo").exchange().as(StepVerifier::create).verifyError(CustomizedSignal.class);
webClient.get()
.uri("/foo")
.exchangeToMono(it -> it.bodyToMono(String.class))
.as(StepVerifier::create)
.verifyError(CustomizedSignal.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ void shouldReportReactiveInitialized() {
return webClient.get()
.uri("sys/init")
.header(VaultHttpHeaders.VAULT_NAMESPACE, "")
.exchange()
.flatMap(it -> it.bodyToMono(Map.class));
.exchangeToMono(it -> it.bodyToMono(Map.class));
})
.as(StepVerifier::create)
.assertNext(actual -> assertThat(actual).containsEntry("initialized", true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ void getX509CertificateShouldReturnCertificate() {

X509Certificate x509Certificate = this.certificate.getX509Certificate();

assertThat(x509Certificate.getSubjectDN().getName()).isEqualTo("CN=hello.example.com");
assertThat(x509Certificate.getSubjectX500Principal().getName()).isEqualTo("CN=hello.example.com");
}

@Test
void getX509IssuerCertificateShouldReturnCertificate() {

X509Certificate x509Certificate = this.certificate.getX509IssuerCertificate();

assertThat(x509Certificate.getSubjectDN().getName()).startsWith("CN=Intermediate CA Certificate");
assertThat(x509Certificate.getSubjectX500Principal().getName()).startsWith("CN=Intermediate CA Certificate");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void shouldDecodeX509Certificate() throws IOException {
PemObject pemObject = PemObject.parseFirst(content);

assertThat(pemObject.isCertificate()).isTrue();
assertThat(pemObject.getCertificate().getSubjectDN().getName()).contains("O=spring-cloud-vault-config");
assertThat(pemObject.getCertificate().getSubjectX500Principal().getName())
.contains("O=spring-cloud-vault-config");
}

}

0 comments on commit 0ea3ddf

Please sign in to comment.