From 18b237f05e9bd3f6ea368bf278b278ef6d9ca13b Mon Sep 17 00:00:00 2001 From: vmartorell Date: Wed, 6 Sep 2023 15:24:24 -0300 Subject: [PATCH 1/5] Adds performanceStandByCode --- .../java/io/github/jopenlibs/vault/api/Debug.java | 13 +++++++++++-- .../io/github/jopenlibs/vault/api/DebugTests.java | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/jopenlibs/vault/api/Debug.java b/src/main/java/io/github/jopenlibs/vault/api/Debug.java index 32c4f1e5..476a8df9 100644 --- a/src/main/java/io/github/jopenlibs/vault/api/Debug.java +++ b/src/main/java/io/github/jopenlibs/vault/api/Debug.java @@ -58,7 +58,7 @@ public Debug withNameSpace(final String nameSpace) { * */ public HealthResponse health() throws VaultException { - return health(null, null, null, null); + return health(null, null, null, null, null); } /** @@ -81,6 +81,8 @@ public HealthResponse health() throws VaultException { * node instead of the default of 429 * @param sealedCode (optional) Indicates the status code that should be returned for a sealed * node instead of the default of 500 + * @param performanceStandbyCode (optional) Indicates the status code that should be + * returned for a performanceStandbyCode node instead of the default of 473 * @return The response information returned from Vault * @throws VaultException If an error occurs or unexpected response received from Vault */ @@ -88,7 +90,8 @@ public HealthResponse health( final Boolean standbyOk, final Integer activeCode, final Integer standbyCode, - final Integer sealedCode + final Integer sealedCode, + final Integer performanceStandbyCode ) throws VaultException { final String path = "sys/health"; @@ -116,6 +119,8 @@ public HealthResponse health( if (sealedCode != null) { rest.parameter("sealedcode", sealedCode.toString()); } + if (performanceStandbyCode != null) rest.parameter("performancestandbycode", + performanceStandbyCode.toString()); // Execute request final RestResponse restResponse = rest.get(); @@ -124,6 +129,7 @@ public HealthResponse health( validCodes.add(200); validCodes.add(429); validCodes.add(500); + validCodes.add(473); if (activeCode != null) { validCodes.add(activeCode); } @@ -133,6 +139,9 @@ public HealthResponse health( if (sealedCode != null) { validCodes.add(sealedCode); } + if (performanceStandbyCode != null) { + validCodes.add(performanceStandbyCode); + } if (!validCodes.contains(restResponse.getStatus())) { throw new VaultException( diff --git a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java index 9b542611..10aad73b 100644 --- a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java +++ b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java @@ -49,7 +49,7 @@ public void testHealth_Plain() throws VaultException { @Test public void testHealth_WithParams() throws VaultException { - final HealthResponse response = vault.debug().health(null, 212, null, null); + final HealthResponse response = vault.debug().health(null, 212, null, null, null); assertTrue(response.getInitialized()); assertFalse(response.getSealed()); assertFalse(response.getStandby()); @@ -67,7 +67,7 @@ public void testHealth_WithParams() throws VaultException { @Test public void testHealth_WonkyActiveCode() throws VaultException { final HealthResponse response = vault.debug().health(null, 204, null, - null); + null, null); assertNull(response.getInitialized()); assertNull(response.getSealed()); assertNull(response.getStandby()); From 05bfb234c8053c6abad446707ef7f9137177a59e Mon Sep 17 00:00:00 2001 From: vmartorell Date: Tue, 10 Oct 2023 10:18:55 -0300 Subject: [PATCH 2/5] Adds codes --- .../io/github/jopenlibs/vault/api/Debug.java | 42 +++++++++++++++---- .../vault/response/HealthResponse.java | 24 ++++++++++- .../jopenlibs/vault/api/DebugTests.java | 28 +++++++++++-- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/jopenlibs/vault/api/Debug.java b/src/main/java/io/github/jopenlibs/vault/api/Debug.java index 476a8df9..b51a094f 100644 --- a/src/main/java/io/github/jopenlibs/vault/api/Debug.java +++ b/src/main/java/io/github/jopenlibs/vault/api/Debug.java @@ -58,7 +58,7 @@ public Debug withNameSpace(final String nameSpace) { * */ public HealthResponse health() throws VaultException { - return health(null, null, null, null, null); + return health(null, null, null, null, null, null, null, null); } /** @@ -75,23 +75,32 @@ public HealthResponse health() throws VaultException { * * @param standbyOk (optional) Indicates that being a standby should still return the active * status code instead of the standby code + * @param perfstandbyok (optional) Indicates that being a performance standby should still + * return the active status code instead of the performance standby code. * @param activeCode (optional) Indicates the status code that should be returned for an active * node instead of the default of 200 * @param standbyCode (optional) Indicates the status code that should be returned for a standby * node instead of the default of 429 + * @param drsecondarycode (optional) Indicates the status code that should be returned for a DR + * secondary node instead of the default of 472 + * @param performanceStandbyCode (optional) Indicates the status code that should be returned + * for a performance standby node instead of the default of 473 * @param sealedCode (optional) Indicates the status code that should be returned for a sealed * node instead of the default of 500 - * @param performanceStandbyCode (optional) Indicates the status code that should be - * returned for a performanceStandbyCode node instead of the default of 473 + * @param uninitcode (optional) Indicates the status code that should be returned for a + * uninitialized node instead of the default of 500 * @return The response information returned from Vault * @throws VaultException If an error occurs or unexpected response received from Vault */ public HealthResponse health( final Boolean standbyOk, + final Boolean perfstandbyok, final Integer activeCode, final Integer standbyCode, + final Integer drsecondarycode, + final Integer performanceStandbyCode, final Integer sealedCode, - final Integer performanceStandbyCode + final Integer uninitcode ) throws VaultException { final String path = "sys/health"; @@ -110,17 +119,27 @@ public HealthResponse health( if (standbyOk != null) { rest.parameter("standbyok", standbyOk.toString()); } + if (perfstandbyok != null) { + rest.parameter("perfstandbyok", perfstandbyok.toString()); + } if (activeCode != null) { rest.parameter("activecode", activeCode.toString()); } if (standbyCode != null) { rest.parameter("standbycode", standbyCode.toString()); } + if (drsecondarycode != null) { + rest.parameter("drsecondarycode", drsecondarycode.toString()); + } + if (performanceStandbyCode != null) { + rest.parameter("performancestandbycode", performanceStandbyCode.toString()); + } if (sealedCode != null) { rest.parameter("sealedcode", sealedCode.toString()); } - if (performanceStandbyCode != null) rest.parameter("performancestandbycode", - performanceStandbyCode.toString()); + if (uninitcode != null) { + rest.parameter("uninitcode", uninitcode.toString()); + } // Execute request final RestResponse restResponse = rest.get(); @@ -128,20 +147,29 @@ public HealthResponse health( final Set validCodes = new HashSet<>();//NOPMD validCodes.add(200); validCodes.add(429); - validCodes.add(500); + validCodes.add(472); validCodes.add(473); + validCodes.add(500); + validCodes.add(501); + validCodes.add(503); if (activeCode != null) { validCodes.add(activeCode); } if (standbyCode != null) { validCodes.add(standbyCode); } + if (drsecondarycode != null) { + validCodes.add(drsecondarycode); + } if (sealedCode != null) { validCodes.add(sealedCode); } if (performanceStandbyCode != null) { validCodes.add(performanceStandbyCode); } + if (uninitcode != null) { + validCodes.add(uninitcode); + } if (!validCodes.contains(restResponse.getStatus())) { throw new VaultException( diff --git a/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java b/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java index f183b262..4ce0c5e9 100644 --- a/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java +++ b/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java @@ -20,6 +20,9 @@ public class HealthResponse implements Serializable { private Boolean initialized; private Boolean sealed; private Boolean standby; + private Boolean drsecondary; + private Boolean perfstandby; + private Boolean uninit; private Long serverTimeUTC; /** @@ -31,8 +34,7 @@ public class HealthResponse implements Serializable { * standby, and serverTimeUTC set to null. This * typically happens when you use optional parameters in the health call, to designate * non-standard HTTP status codes. See docs for - * {@link Debug#health(Boolean, Integer, Integer, Integer)}.

- * + * {@link Debug#health(Boolean, Boolean, Integer, Integer, Integer,Integer, Integer, Integer)}.

* @param restResponse The raw HTTP response from Vault * @param retries The number of retry attempts that occurred during the API call (can be zero) * @throws VaultException If any error occurs or unexpected response is received from Vault @@ -65,6 +67,12 @@ public HealthResponse(final RestResponse restResponse, final int retries) : jsonObject.get("sealed").asBoolean(); this.standby = jsonObject.get("standby") == null ? null : jsonObject.get("standby").asBoolean(); + this.drsecondary = jsonObject.get("drsecondary") == null ? null + : jsonObject.get("drsecondary").asBoolean(); + this.perfstandby = jsonObject.get("perfstandby") == null ? null + : jsonObject.get("perfstandby").asBoolean(); + this.uninit = jsonObject.get("uninit") == null ? null + : jsonObject.get("uninit").asBoolean(); this.serverTimeUTC = jsonObject.get("server_time_utc") == null ? null : jsonObject.get("server_time_utc").asLong(); } catch (final Exception e) { @@ -94,6 +102,18 @@ public Boolean getStandby() { return standby; } + public Boolean getDrsecondary() { + return drsecondary; + } + + public Boolean getPerfstandby() { + return perfstandby; + } + + public Boolean getuninit() { + return uninit; + } + /** * @return A value representing the number of milliseconds since the epoch. With all of the * changes in date API's between Java 8 and pre-Java 8, it seemed best for the library not to diff --git a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java index 10aad73b..cd56e7d4 100644 --- a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java +++ b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java @@ -44,16 +44,22 @@ public void testHealth_Plain() throws VaultException { assertFalse(response.getSealed()); assertFalse(response.getStandby()); assertNotNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(200, response.getRestResponse().getStatus()); } @Test public void testHealth_WithParams() throws VaultException { - final HealthResponse response = vault.debug().health(null, 212, null, null, null); + final HealthResponse response = vault.debug().health(null, null,212, null, null, null, null, null); assertTrue(response.getInitialized()); assertFalse(response.getSealed()); assertFalse(response.getStandby()); assertNotNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(212, response.getRestResponse().getStatus()); } @@ -66,12 +72,28 @@ public void testHealth_WithParams() throws VaultException { */ @Test public void testHealth_WonkyActiveCode() throws VaultException { - final HealthResponse response = vault.debug().health(null, 204, null, - null, null); + final HealthResponse response = vault.debug().health(null, null, 204, + null, null, null, null, null); assertNull(response.getInitialized()); assertNull(response.getSealed()); assertNull(response.getStandby()); assertNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(204, response.getRestResponse().getStatus()); } + @Test + public void testHealth_WonkyPerformance() throws VaultException { + final HealthResponse response = vault.debug().health(null, true, null, null, + null, 473, null, null); + assertTrue(response.getInitialized()); + assertFalse(response.getSealed()); + assertFalse(response.getStandby()); + assertNull(response.getServerTimeUTC()); + assertFalse(response.getDrsecondary()); + assertFalse(response.getPerfstandby()); + assertFalse(response.getuninit()); + TestCase.assertEquals(473, response.getRestResponse().getStatus()); + } } From e35ddd82bad3d2d88484966c0f8336716c666450 Mon Sep 17 00:00:00 2001 From: vmartorell Date: Thu, 12 Oct 2023 11:46:55 -0300 Subject: [PATCH 3/5] removes test no needed. --- .../io/github/jopenlibs/vault/api/DebugTests.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java index cd56e7d4..f7850e41 100644 --- a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java +++ b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java @@ -83,17 +83,4 @@ public void testHealth_WonkyActiveCode() throws VaultException { assertNull(response.getuninit()); TestCase.assertEquals(204, response.getRestResponse().getStatus()); } - @Test - public void testHealth_WonkyPerformance() throws VaultException { - final HealthResponse response = vault.debug().health(null, true, null, null, - null, 473, null, null); - assertTrue(response.getInitialized()); - assertFalse(response.getSealed()); - assertFalse(response.getStandby()); - assertNull(response.getServerTimeUTC()); - assertFalse(response.getDrsecondary()); - assertFalse(response.getPerfstandby()); - assertFalse(response.getuninit()); - TestCase.assertEquals(473, response.getRestResponse().getStatus()); - } } From e0cbb0fba390e64d8a842c3c6fd3062ba64c0fe5 Mon Sep 17 00:00:00 2001 From: vmartorell Date: Tue, 10 Oct 2023 10:18:55 -0300 Subject: [PATCH 4/5] Adds codes Adds codes --- .../io/github/jopenlibs/vault/api/Debug.java | 42 +++++++++++++++---- .../vault/response/HealthResponse.java | 24 ++++++++++- .../jopenlibs/vault/api/DebugTests.java | 15 +++++-- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/jopenlibs/vault/api/Debug.java b/src/main/java/io/github/jopenlibs/vault/api/Debug.java index 476a8df9..7d6c51ff 100644 --- a/src/main/java/io/github/jopenlibs/vault/api/Debug.java +++ b/src/main/java/io/github/jopenlibs/vault/api/Debug.java @@ -58,7 +58,7 @@ public Debug withNameSpace(final String nameSpace) { * */ public HealthResponse health() throws VaultException { - return health(null, null, null, null, null); + return health(null, null, null, null, null, null, null, null); } /** @@ -75,23 +75,32 @@ public HealthResponse health() throws VaultException { * * @param standbyOk (optional) Indicates that being a standby should still return the active * status code instead of the standby code + * @param perfstandbyOk (optional) Indicates that being a performance standby should still + * return the active status code instead of the performance standby code. * @param activeCode (optional) Indicates the status code that should be returned for an active * node instead of the default of 200 * @param standbyCode (optional) Indicates the status code that should be returned for a standby * node instead of the default of 429 + * @param drsecondaryCode (optional) Indicates the status code that should be returned for a DR + * secondary node instead of the default of 472 + * @param performanceStandbyCode (optional) Indicates the status code that should be returned + * for a performance standby node instead of the default of 473 * @param sealedCode (optional) Indicates the status code that should be returned for a sealed * node instead of the default of 500 - * @param performanceStandbyCode (optional) Indicates the status code that should be - * returned for a performanceStandbyCode node instead of the default of 473 + * @param uninitCode (optional) Indicates the status code that should be returned for a + * uninitialized node instead of the default of 500 * @return The response information returned from Vault * @throws VaultException If an error occurs or unexpected response received from Vault */ public HealthResponse health( final Boolean standbyOk, + final Boolean perfstandbyOk, final Integer activeCode, final Integer standbyCode, + final Integer drsecondaryCode, + final Integer performanceStandbyCode, final Integer sealedCode, - final Integer performanceStandbyCode + final Integer uninitCode ) throws VaultException { final String path = "sys/health"; @@ -110,17 +119,27 @@ public HealthResponse health( if (standbyOk != null) { rest.parameter("standbyok", standbyOk.toString()); } + if (perfstandbyOk != null) { + rest.parameter("perfstandbyok", perfstandbyOk.toString()); + } if (activeCode != null) { rest.parameter("activecode", activeCode.toString()); } if (standbyCode != null) { rest.parameter("standbycode", standbyCode.toString()); } + if (drsecondaryCode != null) { + rest.parameter("drsecondarycode", drsecondaryCode.toString()); + } + if (performanceStandbyCode != null) { + rest.parameter("performancestandbycode", performanceStandbyCode.toString()); + } if (sealedCode != null) { rest.parameter("sealedcode", sealedCode.toString()); } - if (performanceStandbyCode != null) rest.parameter("performancestandbycode", - performanceStandbyCode.toString()); + if (uninitCode != null) { + rest.parameter("uninitcode", uninitCode.toString()); + } // Execute request final RestResponse restResponse = rest.get(); @@ -128,20 +147,29 @@ public HealthResponse health( final Set validCodes = new HashSet<>();//NOPMD validCodes.add(200); validCodes.add(429); - validCodes.add(500); + validCodes.add(472); validCodes.add(473); + validCodes.add(500); + validCodes.add(501); + validCodes.add(503); if (activeCode != null) { validCodes.add(activeCode); } if (standbyCode != null) { validCodes.add(standbyCode); } + if (drsecondaryCode != null) { + validCodes.add(drsecondaryCode); + } if (sealedCode != null) { validCodes.add(sealedCode); } if (performanceStandbyCode != null) { validCodes.add(performanceStandbyCode); } + if (uninitCode != null) { + validCodes.add(uninitCode); + } if (!validCodes.contains(restResponse.getStatus())) { throw new VaultException( diff --git a/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java b/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java index f183b262..4ce0c5e9 100644 --- a/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java +++ b/src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java @@ -20,6 +20,9 @@ public class HealthResponse implements Serializable { private Boolean initialized; private Boolean sealed; private Boolean standby; + private Boolean drsecondary; + private Boolean perfstandby; + private Boolean uninit; private Long serverTimeUTC; /** @@ -31,8 +34,7 @@ public class HealthResponse implements Serializable { * standby, and serverTimeUTC set to null. This * typically happens when you use optional parameters in the health call, to designate * non-standard HTTP status codes. See docs for - * {@link Debug#health(Boolean, Integer, Integer, Integer)}.

- * + * {@link Debug#health(Boolean, Boolean, Integer, Integer, Integer,Integer, Integer, Integer)}.

* @param restResponse The raw HTTP response from Vault * @param retries The number of retry attempts that occurred during the API call (can be zero) * @throws VaultException If any error occurs or unexpected response is received from Vault @@ -65,6 +67,12 @@ public HealthResponse(final RestResponse restResponse, final int retries) : jsonObject.get("sealed").asBoolean(); this.standby = jsonObject.get("standby") == null ? null : jsonObject.get("standby").asBoolean(); + this.drsecondary = jsonObject.get("drsecondary") == null ? null + : jsonObject.get("drsecondary").asBoolean(); + this.perfstandby = jsonObject.get("perfstandby") == null ? null + : jsonObject.get("perfstandby").asBoolean(); + this.uninit = jsonObject.get("uninit") == null ? null + : jsonObject.get("uninit").asBoolean(); this.serverTimeUTC = jsonObject.get("server_time_utc") == null ? null : jsonObject.get("server_time_utc").asLong(); } catch (final Exception e) { @@ -94,6 +102,18 @@ public Boolean getStandby() { return standby; } + public Boolean getDrsecondary() { + return drsecondary; + } + + public Boolean getPerfstandby() { + return perfstandby; + } + + public Boolean getuninit() { + return uninit; + } + /** * @return A value representing the number of milliseconds since the epoch. With all of the * changes in date API's between Java 8 and pre-Java 8, it seemed best for the library not to diff --git a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java index 10aad73b..f7850e41 100644 --- a/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java +++ b/src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java @@ -44,16 +44,22 @@ public void testHealth_Plain() throws VaultException { assertFalse(response.getSealed()); assertFalse(response.getStandby()); assertNotNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(200, response.getRestResponse().getStatus()); } @Test public void testHealth_WithParams() throws VaultException { - final HealthResponse response = vault.debug().health(null, 212, null, null, null); + final HealthResponse response = vault.debug().health(null, null,212, null, null, null, null, null); assertTrue(response.getInitialized()); assertFalse(response.getSealed()); assertFalse(response.getStandby()); assertNotNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(212, response.getRestResponse().getStatus()); } @@ -66,12 +72,15 @@ public void testHealth_WithParams() throws VaultException { */ @Test public void testHealth_WonkyActiveCode() throws VaultException { - final HealthResponse response = vault.debug().health(null, 204, null, - null, null); + final HealthResponse response = vault.debug().health(null, null, 204, + null, null, null, null, null); assertNull(response.getInitialized()); assertNull(response.getSealed()); assertNull(response.getStandby()); assertNull(response.getServerTimeUTC()); + assertNull(response.getDrsecondary()); + assertNull(response.getPerfstandby()); + assertNull(response.getuninit()); TestCase.assertEquals(204, response.getRestResponse().getStatus()); } } From 1dadfcf7bb756201f04dbd543b5529649840650c Mon Sep 17 00:00:00 2001 From: vmartorell Date: Mon, 16 Oct 2023 17:49:40 -0300 Subject: [PATCH 5/5] Update Debug.java --- src/main/java/io/github/jopenlibs/vault/api/Debug.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/io/github/jopenlibs/vault/api/Debug.java b/src/main/java/io/github/jopenlibs/vault/api/Debug.java index 2d08816f..7d6c51ff 100644 --- a/src/main/java/io/github/jopenlibs/vault/api/Debug.java +++ b/src/main/java/io/github/jopenlibs/vault/api/Debug.java @@ -92,7 +92,6 @@ public HealthResponse health() throws VaultException { * @return The response information returned from Vault * @throws VaultException If an error occurs or unexpected response received from Vault */ - public HealthResponse health( public HealthResponse health( final Boolean standbyOk, final Boolean perfstandbyOk, @@ -153,7 +152,6 @@ public HealthResponse health( validCodes.add(500); validCodes.add(501); validCodes.add(503); - if (activeCode != null) { validCodes.add(activeCode); }