Skip to content

Commit af1f9a4

Browse files
committed
Refine VaultResponseSupport metadata copying.
Replace static copy method with an instance method. Closes gh-823
1 parent f42bd96 commit af1f9a4

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

spring-vault-core/src/main/java/org/springframework/vault/core/ReactiveVaultKeyValue1Template.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ public Flux<String> list(String path) {
6060
public Mono<VaultResponse> get(String path) {
6161

6262
return doRead(path, Map.class, (response, map) -> {
63+
6364
VaultResponse vaultResponse = new VaultResponse();
64-
VaultResponseSupport.updateWithoutData(vaultResponse, response);
65+
vaultResponse.applyMetadata(response);
6566
vaultResponse.setData(map);
67+
6668
return vaultResponse;
6769
});
6870
}

spring-vault-core/src/main/java/org/springframework/vault/core/ReactiveVaultKeyValue2Template.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Mono<VaultResponse> get(String path) {
5656
return doRead(path, Map.class, (response, data) -> {
5757

5858
VaultResponse vaultResponse = new VaultResponse();
59-
VaultResponse.updateWithoutData(vaultResponse, response);
59+
vaultResponse.applyMetadata(response);
6060
vaultResponse.setData(data);
6161

6262
return vaultResponse;

spring-vault-core/src/main/java/org/springframework/vault/core/VaultKeyValue1Template.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*
3232
* @author Mark Paluch
3333
* @author Younghwan Jang
34-
* @since 2.1
3534
* @see KeyValueBackend#KV_1
35+
* @since 2.1
3636
*/
3737
class VaultKeyValue1Template extends VaultKeyValueAccessor implements VaultKeyValueOperations {
3838

@@ -67,8 +67,9 @@ public VaultResponse get(String path) {
6767
Assert.hasText(path, "Path must not be empty");
6868

6969
return doRead(path, Map.class, (response, data) -> {
70+
7071
VaultResponse vaultResponse = new VaultResponse();
71-
VaultResponse.updateWithoutData(vaultResponse, response);
72+
vaultResponse.applyMetadata(response);
7273
vaultResponse.setData(data);
7374

7475
return vaultResponse;

spring-vault-core/src/main/java/org/springframework/vault/core/VaultKeyValue2Template.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public VaultResponse get(String path) {
5656
return doRead(path, Map.class, (response, data) -> {
5757

5858
VaultResponse vaultResponse = new VaultResponse();
59-
VaultResponse.updateWithoutData(vaultResponse, response);
59+
vaultResponse.applyMetadata(response);
6060
vaultResponse.setData(data);
6161

6262
return vaultResponse;

spring-vault-core/src/main/java/org/springframework/vault/support/VaultResponseSupport.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,21 @@ public class VaultResponseSupport<T> {
6363
@Nullable
6464
private List<String> warnings;
6565

66-
public static void updateWithoutData(final VaultResponseSupport<?> dst, final VaultResponseSupport<?> src) {
67-
dst.auth = src.auth;
68-
dst.metadata = src.metadata;
69-
dst.wrapInfo = src.wrapInfo;
70-
dst.leaseDuration = src.leaseDuration;
71-
dst.leaseId = src.leaseId;
72-
dst.requestId = src.requestId;
73-
dst.renewable = src.renewable;
74-
dst.warnings = src.warnings;
66+
/**
67+
* Apply metadata such as auth or warnings without copying data.
68+
* @param other
69+
* @since 3.1
70+
*/
71+
public void applyMetadata(VaultResponseSupport<?> other) {
72+
73+
this.auth = other.auth;
74+
this.metadata = other.metadata;
75+
this.wrapInfo = other.wrapInfo;
76+
this.leaseDuration = other.leaseDuration;
77+
this.leaseId = other.leaseId;
78+
this.requestId = other.requestId;
79+
this.renewable = other.renewable;
80+
this.warnings = other.warnings;
7581
}
7682

7783
/**

0 commit comments

Comments
 (0)