Skip to content

Commit 4ef0362

Browse files
committedAug 20, 2024··
Update code to use recent language features.
Closes #881
1 parent 899c9d1 commit 4ef0362

File tree

114 files changed

+532
-611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+532
-611
lines changed
 

‎spring-vault-core/src/main/java/org/springframework/vault/authentication/AppRoleAuthentication.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package org.springframework.vault.authentication;
1717

18+
import static org.springframework.vault.authentication.AuthenticationSteps.HttpRequestBuilder.*;
19+
import static org.springframework.vault.authentication.AuthenticationUtil.*;
20+
1821
import java.util.HashMap;
1922
import java.util.Map;
2023

@@ -43,9 +46,6 @@
4346
import org.springframework.web.client.RestClientException;
4447
import org.springframework.web.client.RestOperations;
4548

46-
import static org.springframework.vault.authentication.AuthenticationSteps.HttpRequestBuilder.*;
47-
import static org.springframework.vault.authentication.AuthenticationUtil.*;
48-
4949
/**
5050
* AppRole implementation of {@link ClientAuthentication}. RoleId and SecretId (optional)
5151
* are sent in the login request to Vault to obtain a {@link VaultToken}.
@@ -217,8 +217,8 @@ private String getRoleId(RoleId roleId) throws VaultLoginException {
217217
return (String) entity.getBody().getRequiredData().get("role_id");
218218
}
219219
catch (HttpStatusCodeException e) {
220-
throw new VaultLoginException(String.format("Cannot get Role id using AppRole: %s",
221-
VaultResponses.getError(e.getResponseBodyAsString())), e);
220+
throw new VaultLoginException("Cannot get Role id using AppRole: %s"
221+
.formatted(VaultResponses.getError(e.getResponseBodyAsString())), e);
222222
}
223223
}
224224

@@ -236,8 +236,8 @@ private String getRoleId(RoleId roleId) throws VaultLoginException {
236236
return (String) response.getRequiredData().get("role_id");
237237
}
238238
catch (HttpStatusCodeException e) {
239-
throw new VaultLoginException(String.format("Cannot unwrap Role id using AppRole: %s",
240-
VaultResponses.getError(e.getResponseBodyAsString())), e);
239+
throw new VaultLoginException("Cannot unwrap Role id using AppRole: %s"
240+
.formatted(VaultResponses.getError(e.getResponseBodyAsString())), e);
241241
}
242242
}
243243

@@ -260,8 +260,8 @@ private String getSecretId(SecretId secretId) throws VaultLoginException {
260260
return (String) response.getRequiredData().get("secret_id");
261261
}
262262
catch (HttpStatusCodeException e) {
263-
throw new VaultLoginException(String.format("Cannot get Secret id using AppRole: %s",
264-
VaultResponses.getError(e.getResponseBodyAsString())), e);
263+
throw new VaultLoginException("Cannot get Secret id using AppRole: %s"
264+
.formatted(VaultResponses.getError(e.getResponseBodyAsString())), e);
265265
}
266266
}
267267

@@ -280,8 +280,8 @@ private String getSecretId(SecretId secretId) throws VaultLoginException {
280280
return (String) response.getRequiredData().get("secret_id");
281281
}
282282
catch (HttpStatusCodeException e) {
283-
throw new VaultLoginException(String.format("Cannot unwrap Role id using AppRole: %s",
284-
VaultResponses.getError(e.getResponseBodyAsString())), e);
283+
throw new VaultLoginException("Cannot unwrap Role id using AppRole: %s"
284+
.formatted(VaultResponses.getError(e.getResponseBodyAsString())), e);
285285
}
286286
}
287287

@@ -331,11 +331,11 @@ private static Map<String, String> getAppRoleLoginBody(String roleId, @Nullable
331331
}
332332

333333
private static String getSecretIdPath(AppRoleAuthenticationOptions options) {
334-
return String.format("auth/%s/role/%s/secret-id", options.getPath(), options.getAppRole());
334+
return "auth/%s/role/%s/secret-id".formatted(options.getPath(), options.getAppRole());
335335
}
336336

337337
private static String getRoleIdIdPath(AppRoleAuthenticationOptions options) {
338-
return String.format("auth/%s/role/%s/role-id", options.getPath(), options.getAppRole());
338+
return "auth/%s/role/%s/role-id".formatted(options.getPath(), options.getAppRole());
339339
}
340340

341341
}

‎spring-vault-core/src/main/java/org/springframework/vault/authentication/AuthenticationSteps.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public static class HttpRequest<T> {
446446

447447
@Override
448448
public String toString() {
449-
return String.format("%s %s AS %s", getMethod(), getUri() != null ? getUri() : getUriTemplate(),
449+
return "%s %s AS %s".formatted(getMethod(), getUri() != null ? getUri() : getUriTemplate(),
450450
getResponseType());
451451
}
452452

@@ -508,9 +508,8 @@ public Node<?> getPrevious() {
508508
public boolean equals(Object o) {
509509
if (this == o)
510510
return true;
511-
if (!(o instanceof HttpRequestNode))
511+
if (!(o instanceof HttpRequestNode<?> that))
512512
return false;
513-
HttpRequestNode<?> that = (HttpRequestNode<?>) o;
514513
return this.definition.equals(that.definition) && this.previous.equals(that.previous);
515514
}
516515

@@ -553,9 +552,8 @@ public Node<?> getPrevious() {
553552
public boolean equals(Object o) {
554553
if (this == o)
555554
return true;
556-
if (!(o instanceof MapStep))
555+
if (!(o instanceof MapStep<?, ?> mapStep))
557556
return false;
558-
MapStep<?, ?> mapStep = (MapStep<?, ?>) o;
559557
return this.mapper.equals(mapStep.mapper) && this.previous.equals(mapStep.previous);
560558
}
561559

@@ -599,9 +597,8 @@ public List<Node<?>> getRight() {
599597
public boolean equals(Object o) {
600598
if (this == o)
601599
return true;
602-
if (!(o instanceof ZipStep))
600+
if (!(o instanceof ZipStep<?, ?> zipStep))
603601
return false;
604-
ZipStep<?, ?> zipStep = (ZipStep<?, ?>) o;
605602
return this.left.equals(zipStep.left) && this.right.equals(zipStep.right);
606603
}
607604

@@ -645,9 +642,8 @@ public AuthenticationSteps.Node<?> getPrevious() {
645642
public boolean equals(Object o) {
646643
if (this == o)
647644
return true;
648-
if (!(o instanceof OnNextStep))
645+
if (!(o instanceof OnNextStep<?> that))
649646
return false;
650-
OnNextStep<?> that = (OnNextStep<?>) o;
651647
return this.consumer.equals(that.consumer) && this.previous.equals(that.previous);
652648
}
653649

@@ -686,9 +682,8 @@ public Node<?> getPrevious() {
686682
public boolean equals(Object o) {
687683
if (this == o)
688684
return true;
689-
if (!(o instanceof ScalarValueStep))
685+
if (!(o instanceof ScalarValueStep<?> that))
690686
return false;
691-
ScalarValueStep<?> that = (ScalarValueStep<?>) o;
692687
return this.value.equals(that.value) && this.previous.equals(that.previous);
693688
}
694689

@@ -731,9 +726,8 @@ public Node<?> getPrevious() {
731726
public boolean equals(Object o) {
732727
if (this == o)
733728
return true;
734-
if (!(o instanceof SupplierStep))
729+
if (!(o instanceof SupplierStep<?> that))
735730
return false;
736-
SupplierStep<?> that = (SupplierStep<?>) o;
737731
return this.supplier.equals(that.supplier) && this.previous.equals(that.previous);
738732
}
739733

@@ -798,9 +792,8 @@ public R getRight() {
798792
public boolean equals(Object o) {
799793
if (this == o)
800794
return true;
801-
if (!(o instanceof Pair))
795+
if (!(o instanceof Pair<?, ?> pair))
802796
return false;
803-
Pair<?, ?> pair = (Pair<?, ?>) o;
804797
return this.left.equals(pair.left) && this.right.equals(pair.right);
805798
}
806799

0 commit comments

Comments
 (0)
Please sign in to comment.