From 8ec160a436fd6a6792a325ffa5cd3d8e217d7544 Mon Sep 17 00:00:00 2001
From: Stefan Kalscheuer <stefan@stklcode.de>
Date: Sat, 22 Jun 2024 13:53:57 +0200
Subject: [PATCH] feat: add mount_type attribute to common response model

---
 CHANGELOG.md                                    |  1 +
 .../model/response/VaultDataResponse.java       | 17 ++++++++++++++---
 .../model/response/TokenResponseTest.java       |  5 ++++-
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e41acdd..847b178 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
   * `replication_primary_canary_age_ms`
   * `enterprise`
 * Add missing `num_uses` field to `AuthData`
+* Add `mount_type` attribute to common response model
 
 ### Dependencies
 * Updated Jackson to 2.17.1
diff --git a/src/main/java/de/stklcode/jvault/connector/model/response/VaultDataResponse.java b/src/main/java/de/stklcode/jvault/connector/model/response/VaultDataResponse.java
index bad9a8f..c193d60 100644
--- a/src/main/java/de/stklcode/jvault/connector/model/response/VaultDataResponse.java
+++ b/src/main/java/de/stklcode/jvault/connector/model/response/VaultDataResponse.java
@@ -29,7 +29,7 @@ import java.util.Objects;
  * @since 0.1
  */
 public abstract class VaultDataResponse implements VaultResponse {
-    private static final long serialVersionUID = 7486270767477652184L;
+    private static final long serialVersionUID = -6396903229092254181L;
 
     @JsonProperty("request_id")
     private String requestId;
@@ -49,6 +49,9 @@ public abstract class VaultDataResponse implements VaultResponse {
     @JsonProperty("wrap_info")
     private WrapInfo wrapInfo;
 
+    @JsonProperty("mount_type")
+    private String mountType;
+
     /**
      * @return Request ID
      * @since 1.1
@@ -93,6 +96,13 @@ public abstract class VaultDataResponse implements VaultResponse {
         return wrapInfo;
     }
 
+    /**
+     * @return Information about the type of mount this secret is from (since Vault 1.17)
+     * @since 1.3
+     */
+    public final String getMountType() {
+        return mountType;
+    }
     @Override
     public boolean equals(Object o) {
         if (this == o) {
@@ -106,11 +116,12 @@ public abstract class VaultDataResponse implements VaultResponse {
                 Objects.equals(leaseId, that.leaseId) &&
                 Objects.equals(leaseDuration, that.leaseDuration) &&
                 Objects.equals(warnings, that.warnings) &&
-                Objects.equals(wrapInfo, that.wrapInfo);
+                Objects.equals(wrapInfo, that.wrapInfo) &&
+                Objects.equals(mountType, that.mountType);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(requestId, leaseId, renewable, leaseDuration, warnings, wrapInfo);
+        return Objects.hash(requestId, leaseId, renewable, leaseDuration, warnings, wrapInfo, mountType);
     }
 }
diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java
index 32eede6..a04e9c8 100644
--- a/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java
+++ b/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java
@@ -55,6 +55,7 @@ class TokenResponseTest extends AbstractModelTest<TokenResponse> {
     private static final String TOKEN_ID = "my-token";
     private static final String TOKEN_ISSUE_TIME = "2018-04-17T11:35:54.466476078-04:00";
     private static final String TOKEN_TYPE = "service";
+    private static final String MOUNT_TYPE = "token";
 
     private static final String RES_JSON = "{\n" +
             "  \"lease_id\": \"\",\n" +
@@ -85,7 +86,8 @@ class TokenResponseTest extends AbstractModelTest<TokenResponse> {
             "    \"type\": \"" + TOKEN_TYPE + "\"\n" +
             "  },\n" +
             "  \"warnings\": null,\n" +
-            "  \"auth\": null\n" +
+            "  \"auth\": null,\n" +
+            "  \"mount_type\": \"" + MOUNT_TYPE + "\"\n" +
             "}";
 
     TokenResponseTest() {
@@ -125,6 +127,7 @@ class TokenResponseTest extends AbstractModelTest<TokenResponse> {
         assertEquals(RES_LEASE_DURATION, res.getLeaseDuration(), "Incorrect lease duration");
         assertEquals(RES_RENEWABLE, res.isRenewable(), "Incorrect response renewable flag");
         assertEquals(RES_LEASE_DURATION, res.getLeaseDuration(), "Incorrect response lease duration");
+        assertEquals(MOUNT_TYPE, res.getMountType(), "Incorrect mount type");
         // Extract token data.
         TokenData data = res.getData();
         assertNotNull(data, "Token data is NULL");