Skip to content

Commit

Permalink
Upgrade to Spring Javaformat 0.38.
Browse files Browse the repository at this point in the history
Closes gh-781
  • Loading branch information
mp911de committed Apr 19, 2023
1 parent fda78f4 commit 2ab0fa3
Show file tree
Hide file tree
Showing 147 changed files with 2,292 additions and 1,409 deletions.
355 changes: 355 additions & 0 deletions etc/ide/org.eclipse.core.jdt.prefs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.29</version>
<version>0.0.38</version>
<executions>
<execution>
<phase>validate</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
beanFactory.getBeansOfType(org.springframework.vault.core.env.VaultPropertySource.class).values(),
propertySources);

registerPropertySources(beanFactory
.getBeansOfType(org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class).values(),
registerPropertySources(
beanFactory.getBeansOfType(org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class)
.values(),
propertySources);
}

Expand All @@ -102,9 +103,9 @@ public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanD

if (!registry.isBeanNameInUse("VaultPropertySourceRegistrar")) {
registry.registerBeanDefinition("VaultPropertySourceRegistrar", BeanDefinitionBuilder //
.rootBeanDefinition(VaultPropertySourceRegistrar.class) //
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE) //
.getBeanDefinition());
.rootBeanDefinition(VaultPropertySourceRegistrar.class) //
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE) //
.getBeanDefinition());
}

Set<AnnotationAttributes> propertySources = attributesForRepeatable(annotationMetadata,
Expand Down Expand Up @@ -163,7 +164,7 @@ private AbstractBeanDefinition createBeanDefinition(String ref, Renewal renewal,

if (isRenewable(renewal)) {
builder = BeanDefinitionBuilder
.rootBeanDefinition(org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class);
.rootBeanDefinition(org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class);

RequestedSecret requestedSecret = renewal == Renewal.ROTATE ? RequestedSecret.rotating(propertyPath)
: RequestedSecret.renewable(propertyPath);
Expand All @@ -174,7 +175,7 @@ private AbstractBeanDefinition createBeanDefinition(String ref, Renewal renewal,
}
else {
builder = BeanDefinitionBuilder
.rootBeanDefinition(org.springframework.vault.core.env.VaultPropertySource.class);
.rootBeanDefinition(org.springframework.vault.core.env.VaultPropertySource.class);

builder.addConstructorArgValue(propertyPath);
builder.addConstructorArgReference(ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,25 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
throw new RuntimeException(e);
}

Stream.of("org.springframework.vault.core.VaultSysTemplate$GetMounts$VaultMountsResponse",
"org.springframework.vault.core.VaultVersionedKeyValueTemplate$VersionedResponse",
"org.springframework.vault.core.ReactiveVaultTemplate$VaultListResponse",
"org.springframework.vault.core.VaultListResponse",

"org.springframework.vault.core.VaultTransitTemplate$RawTransitKeyImpl",
"org.springframework.vault.core.VaultTransitTemplate$VaultTransitKeyImpl",

"org.springframework.vault.core.VaultSysTemplate$GetMounts",
"org.springframework.vault.core.VaultSysTemplate$GetUnsealStatus",
"org.springframework.vault.core.VaultSysTemplate$Health",
"org.springframework.vault.core.VaultSysTemplate$Seal",
"org.springframework.vault.core.VaultSysTemplate$VaultHealthImpl",
"org.springframework.vault.core.VaultSysTemplate$VaultInitializationResponseImpl",
"org.springframework.vault.core.VaultSysTemplate$VaultUnsealStatusImpl",

"org.springframework.vault.core.VaultVersionedKeyValueTemplate$VersionedResponse")
.forEach(cls -> reflection.registerType(TypeReference.of(cls), dataObjectCategories));
Stream
.of("org.springframework.vault.core.VaultSysTemplate$GetMounts$VaultMountsResponse",
"org.springframework.vault.core.VaultVersionedKeyValueTemplate$VersionedResponse",
"org.springframework.vault.core.ReactiveVaultTemplate$VaultListResponse",
"org.springframework.vault.core.VaultListResponse",

"org.springframework.vault.core.VaultTransitTemplate$RawTransitKeyImpl",
"org.springframework.vault.core.VaultTransitTemplate$VaultTransitKeyImpl",

"org.springframework.vault.core.VaultSysTemplate$GetMounts",
"org.springframework.vault.core.VaultSysTemplate$GetUnsealStatus",
"org.springframework.vault.core.VaultSysTemplate$Health",
"org.springframework.vault.core.VaultSysTemplate$Seal",
"org.springframework.vault.core.VaultSysTemplate$VaultHealthImpl",
"org.springframework.vault.core.VaultSysTemplate$VaultInitializationResponseImpl",
"org.springframework.vault.core.VaultSysTemplate$VaultUnsealStatusImpl",

"org.springframework.vault.core.VaultVersionedKeyValueTemplate$VersionedResponse")
.forEach(cls -> reflection.registerType(TypeReference.of(cls), dataObjectCategories));

reflection.registerTypeIfPresent(classLoader, "com.google.api.client.json.jackson2.JacksonFactory",
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static AuthenticationSteps createAuthenticationSteps(AppIdAuthenticationO
Assert.notNull(options, "AppIdAuthenticationOptions must not be null");

return AuthenticationSteps
.fromSupplier(() -> getAppIdLogin(options.getAppId(), options.getUserIdMechanism().createUserId())) //
.login(AuthenticationUtil.getLoginPath(options.getPath()));
.fromSupplier(() -> getAppIdLogin(options.getAppId(), options.getUserIdMechanism().createUserId())) //
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

@Override
Expand All @@ -96,7 +96,7 @@ private VaultToken createTokenUsingAppId() {

try {
VaultResponse response = this.restOperations
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);

Assert.state(response != null && response.getAuth() != null, "Auth field must not be null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ private static Node<String> getRoleIdSteps(AppRoleAuthenticationOptions options,
HttpHeaders headers = createHttpHeaders(((Pull) roleId).getInitialToken());

return AuthenticationSteps
.fromHttpRequest(get(getRoleIdIdPath(options)).with(headers).as(VaultResponse.class))
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("role_id"));
.fromHttpRequest(get(getRoleIdIdPath(options)).with(headers).as(VaultResponse.class))
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("role_id"));
}

if (roleId instanceof Wrapped) {
return unwrapResponse(options.getUnwrappingEndpoints(), ((Wrapped) roleId).getInitialToken())
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("role_id"));
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("role_id"));
}

throw new IllegalArgumentException("Unknown RoleId configuration: " + roleId);
Expand All @@ -148,14 +148,14 @@ private static Node<String> getSecretIdSteps(AppRoleAuthenticationOptions option
HttpHeaders headers = createHttpHeaders(((Pull) secretId).getInitialToken());

return AuthenticationSteps
.fromHttpRequest(post(getSecretIdPath(options)).with(headers).as(VaultResponse.class))
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("secret_id"));
.fromHttpRequest(post(getSecretIdPath(options)).with(headers).as(VaultResponse.class))
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("secret_id"));
}

if (secretId instanceof Wrapped) {

return unwrapResponse(options.getUnwrappingEndpoints(), ((Wrapped) secretId).getInitialToken())
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("secret_id"));
.map(vaultResponse -> (String) vaultResponse.getRequiredData().get("secret_id"));
}

throw new IllegalArgumentException("Unknown SecretId configuration: " + secretId);
Expand All @@ -165,9 +165,10 @@ private static Node<String> getSecretIdSteps(AppRoleAuthenticationOptions option
private static Node<VaultResponse> unwrapResponse(UnwrappingEndpoints unwrappingEndpoints, VaultToken token) {

return AuthenticationSteps
.fromHttpRequest(method(unwrappingEndpoints.getUnwrapRequestMethod(), unwrappingEndpoints.getPath())
.with(createHttpHeaders(token)).as(VaultResponse.class))
.map(unwrappingEndpoints::unwrap);
.fromHttpRequest(method(unwrappingEndpoints.getUnwrapRequestMethod(), unwrappingEndpoints.getPath())
.with(createHttpHeaders(token))
.as(VaultResponse.class))
.map(unwrappingEndpoints::unwrap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private Mono<Object> createMono(Iterable<Node<?>> steps) {

if (o instanceof ZipStep) {
state = state.zipWith(doZipStep((ZipStep<Object, Object>) o))
.map(it -> Pair.of(it.getT1(), it.getT2()));
.map(it -> Pair.of(it.getT1(), it.getT2()));
}

if (o instanceof OnNextStep) {
Expand Down Expand Up @@ -166,8 +166,8 @@ private Mono<Object> doHttpRequest(HttpRequestNode<Object> step, Object state) {
RequestBodySpec spec;
if (definition.getUri() == null) {

spec = this.webClient.method(definition.getMethod()).uri(definition.getUriTemplate(),
definition.getUrlVariables());
spec = this.webClient.method(definition.getMethod())
.uri(definition.getUriTemplate(), definition.getUrlVariables());
}
else {
spec = this.webClient.method(definition.getMethod()).uri(definition.getUri());
Expand Down Expand Up @@ -224,14 +224,13 @@ private Mono<Object> doSupplierStepLater(SupplierStep<Object> supplierStep) {
ResourceCredentialSupplier resourceSupplier = (ResourceCredentialSupplier) supplier;

return DataBufferUtils.join(DataBufferUtils.read(resourceSupplier.getResource(), this.factory, 4096))
.map(dataBuffer -> {
String result = dataBuffer.toString(ResourceCredentialSupplier.CHARSET);
DataBufferUtils.release(dataBuffer);
return (Object) result;
}).onErrorMap(IOException.class,
e -> new VaultException(
String.format("Credential retrieval from %s failed", resourceSupplier.getResource()),
e));
.map(dataBuffer -> {
String result = dataBuffer.toString(ResourceCredentialSupplier.CHARSET);
DataBufferUtils.release(dataBuffer);
return (Object) result;
})
.onErrorMap(IOException.class, e -> new VaultException(
String.format("Credential retrieval from %s failed", resourceSupplier.getResource()), e));
}

enum Undefinded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,27 @@ protected static AuthenticationSteps createAuthenticationSteps(AwsEc2Authenticat
AtomicReference<char[]> nonce, Supplier<char[]> nonceSupplier) {

return AuthenticationSteps
.fromHttpRequest(HttpRequestBuilder.get(options.getIdentityDocumentUri().toString()).as(String.class)) //
.map(pkcs7 -> pkcs7.replaceAll("\\r", "")) //
.map(pkcs7 -> pkcs7.replaceAll("\\n", "")) //
.map(pkcs7 -> {
.fromHttpRequest(HttpRequestBuilder.get(options.getIdentityDocumentUri().toString()).as(String.class)) //
.map(pkcs7 -> pkcs7.replaceAll("\\r", "")) //
.map(pkcs7 -> pkcs7.replaceAll("\\n", "")) //
.map(pkcs7 -> {

Map<String, String> login = new HashMap<>();
Map<String, String> login = new HashMap<>();

if (StringUtils.hasText(options.getRole())) {
login.put("role", options.getRole());
}
if (StringUtils.hasText(options.getRole())) {
login.put("role", options.getRole());
}

if (Objects.equals(nonce.get(), EMPTY)) {
nonce.compareAndSet(EMPTY, nonceSupplier.get());
}
if (Objects.equals(nonce.get(), EMPTY)) {
nonce.compareAndSet(EMPTY, nonceSupplier.get());
}

login.put("nonce", new String(nonce.get()));
login.put("pkcs7", pkcs7);
login.put("nonce", new String(nonce.get()));
login.put("pkcs7", pkcs7);

return login;
}).login(AuthenticationUtil.getLoginPath(options.getPath()));
return login;
})
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

@Override
Expand All @@ -148,7 +149,7 @@ private VaultToken createTokenUsingAwsEc2() {
try {

VaultResponse response = this.vaultRestOperations
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);

Assert.state(response != null && response.getAuth() != null, "Auth field must not be null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class AwsEc2AuthenticationOptions {

public static final URI DEFAULT_PKCS7_IDENTITY_DOCUMENT_URI = URI
.create("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7");
.create("http://169.254.169.254/latest/dynamic/instance-identity/pkcs7");

public static final String DEFAULT_AWS_AUTHENTICATION_PATH = "aws-ec2";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected static AuthenticationSteps createAuthenticationSteps(AwsIamAuthenticat
AwsCredentials credentials, Region region) {

return AuthenticationSteps.fromSupplier(() -> createRequestBody(options, credentials, region)) //
.login(AuthenticationUtil.getLoginPath(options.getPath()));
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

@Override
Expand All @@ -147,7 +147,7 @@ private VaultToken createTokenUsingAwsIam() {
try {

VaultResponse response = this.vaultRestOperations
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);

Assert.state(response != null && response.getAuth() != null, "Auth field must not be null");

Expand Down Expand Up @@ -214,13 +214,18 @@ private static String getSignedHeaders(AwsIamAuthenticationOptions options, AwsC
Map<String, List<String>> headers = createIamRequestHeaders(options);

SdkHttpFullRequest.Builder builder = SdkHttpFullRequest.builder()
.contentStreamProvider(() -> new ByteArrayInputStream(REQUEST_BODY.getBytes())).headers(headers)
.method(SdkHttpMethod.POST).uri(options.getEndpointUri());
.contentStreamProvider(() -> new ByteArrayInputStream(REQUEST_BODY.getBytes()))
.headers(headers)
.method(SdkHttpMethod.POST)
.uri(options.getEndpointUri());
SdkHttpFullRequest request = builder.build();

Aws4Signer signer = Aws4Signer.create();
Aws4SignerParams signerParams = Aws4SignerParams.builder().awsCredentials(credentials).signingName("sts")
.signingRegion(region).build();
Aws4SignerParams signerParams = Aws4SignerParams.builder()
.awsCredentials(credentials)
.signingName("sts")
.signingRegion(region)
.build();
SdkHttpFullRequest signedRequest = signer.sign(request, signerParams);

Map<String, Object> map = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,27 @@ protected static AuthenticationSteps createAuthenticationSteps(AzureMsiAuthentic
@Nullable AzureVmEnvironment environment) {

Node<String> msiToken = AuthenticationSteps
.fromHttpRequest(HttpRequestBuilder.get(options.getIdentityTokenServiceUri()).with(METADATA_HEADERS)
.as(Map.class)) //
.map(token -> (String) token.get("access_token"));
.fromHttpRequest(
HttpRequestBuilder.get(options.getIdentityTokenServiceUri()).with(METADATA_HEADERS).as(Map.class)) //
.map(token -> (String) token.get("access_token"));

Node<AzureVmEnvironment> environmentSteps;

if (environment == null) {

environmentSteps = AuthenticationSteps
.fromHttpRequest(HttpRequestBuilder.get(options.getInstanceMetadataServiceUri())
.with(METADATA_HEADERS).as(Map.class)) //
.map(AzureMsiAuthentication::toAzureVmEnvironment);
.fromHttpRequest(HttpRequestBuilder.get(options.getInstanceMetadataServiceUri())
.with(METADATA_HEADERS)
.as(Map.class)) //
.map(AzureMsiAuthentication::toAzureVmEnvironment);
}
else {
environmentSteps = AuthenticationSteps.fromValue(environment);
}

return environmentSteps.zipWith(msiToken)
.map(tuple -> getAzureLogin(options.getRole(), tuple.getLeft(), tuple.getRight())) //
.login(AuthenticationUtil.getLoginPath(options.getPath()));
.map(tuple -> getAzureLogin(options.getRole(), tuple.getLeft(), tuple.getRight())) //
.login(AuthenticationUtil.getLoginPath(options.getPath()));
}

@Override
Expand All @@ -156,7 +157,7 @@ private VaultToken createTokenUsingAzureMsiCompute() {
try {

VaultResponse response = this.vaultRestOperations
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);
.postForObject(AuthenticationUtil.getLoginPath(this.options.getPath()), login, VaultResponse.class);

Assert.state(response != null && response.getAuth() != null, "Auth field must not be null");

Expand Down Expand Up @@ -187,7 +188,7 @@ private static Map<String, String> getAzureLogin(String role, AzureVmEnvironment
private String getAccessToken() {

ResponseEntity<Map> response = this.azureMetadataRestOperations
.exchange(this.options.getIdentityTokenServiceUri(), HttpMethod.GET, METADATA_HEADERS, Map.class);
.exchange(this.options.getIdentityTokenServiceUri(), HttpMethod.GET, METADATA_HEADERS, Map.class);

return (String) response.getBody().get("access_token");
}
Expand All @@ -202,7 +203,7 @@ private AzureVmEnvironment getVmEnvironment() {
private AzureVmEnvironment fetchAzureVmEnvironment() {

ResponseEntity<Map> response = this.azureMetadataRestOperations
.exchange(this.options.getInstanceMetadataServiceUri(), HttpMethod.GET, METADATA_HEADERS, Map.class);
.exchange(this.options.getInstanceMetadataServiceUri(), HttpMethod.GET, METADATA_HEADERS, Map.class);

return toAzureVmEnvironment(response.getBody());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AzureMsiAuthenticationOptions {
public static final String DEFAULT_AZURE_AUTHENTICATION_PATH = "azure";

public static final URI DEFAULT_INSTANCE_METADATA_SERVICE_URI = URI
.create("http://169.254.169.254/metadata/instance?api-version=2017-12-01");
.create("http://169.254.169.254/metadata/instance?api-version=2017-12-01");

public static final URI DEFAULT_IDENTITY_TOKEN_SERVICE_URI = URI.create(
"http://169.254.169.254/metadata/identity/oauth2/token?resource=https://vault.hashicorp.com&api-version=2018-02-01");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static AuthenticationSteps createAuthenticationSteps(ClientCertificateAut
Assert.notNull(options, "ClientCertificateAuthenticationOptions must not be null");

return AuthenticationSteps
.just(post(AuthenticationUtil.getLoginPath(options.getPath())).as(VaultResponse.class));
.just(post(AuthenticationUtil.getLoginPath(options.getPath())).as(VaultResponse.class));
}

@Override
Expand Down
Loading

0 comments on commit 2ab0fa3

Please sign in to comment.