From c254fdf3fd605271578563a6e01afafb0ad0cf1d Mon Sep 17 00:00:00 2001 From: vmartorell Date: Mon, 16 Oct 2023 19:04:11 -0300 Subject: [PATCH] Adds codes (#59) --- .../io/github/jopenlibs/vault/api/Debug.java | 42 +++++++++++++++---- .../vault/response/HealthResponse.java | 24 ++++++++++- .../jopenlibs/vault/api/DebugTests.java | 16 +++++-- 3 files changed, 70 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 81f7e494..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, 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..859016aa 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,23 @@ 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 +73,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()); } }