Skip to content

Commit c254fdf

Browse files
authored
Adds codes (#59)
1 parent 7e56663 commit c254fdf

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

src/main/java/io/github/jopenlibs/vault/api/Debug.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Debug withNameSpace(final String nameSpace) {
5858
* </blockquote>
5959
*/
6060
public HealthResponse health() throws VaultException {
61-
return health(null, null, null, null, null);
61+
return health(null, null, null, null, null, null, null, null);
6262
}
6363

6464
/**
@@ -75,23 +75,32 @@ public HealthResponse health() throws VaultException {
7575
*
7676
* @param standbyOk (optional) Indicates that being a standby should still return the active
7777
* status code instead of the standby code
78+
* @param perfstandbyOk (optional) Indicates that being a performance standby should still
79+
* return the active status code instead of the performance standby code.
7880
* @param activeCode (optional) Indicates the status code that should be returned for an active
7981
* node instead of the default of 200
8082
* @param standbyCode (optional) Indicates the status code that should be returned for a standby
8183
* node instead of the default of 429
84+
* @param drsecondaryCode (optional) Indicates the status code that should be returned for a DR
85+
* secondary node instead of the default of 472
86+
* @param performanceStandbyCode (optional) Indicates the status code that should be returned
87+
* for a performance standby node instead of the default of 473
8288
* @param sealedCode (optional) Indicates the status code that should be returned for a sealed
8389
* node instead of the default of 500
84-
* @param performanceStandbyCode (optional) Indicates the status code that should be
85-
* returned for a performanceStandbyCode node instead of the default of 473
90+
* @param uninitCode (optional) Indicates the status code that should be returned for a
91+
* uninitialized node instead of the default of 500
8692
* @return The response information returned from Vault
8793
* @throws VaultException If an error occurs or unexpected response received from Vault
8894
*/
8995
public HealthResponse health(
9096
final Boolean standbyOk,
97+
final Boolean perfstandbyOk,
9198
final Integer activeCode,
9299
final Integer standbyCode,
100+
final Integer drsecondaryCode,
101+
final Integer performanceStandbyCode,
93102
final Integer sealedCode,
94-
final Integer performanceStandbyCode
103+
final Integer uninitCode
95104
) throws VaultException {
96105
final String path = "sys/health";
97106

@@ -110,38 +119,57 @@ public HealthResponse health(
110119
if (standbyOk != null) {
111120
rest.parameter("standbyok", standbyOk.toString());
112121
}
122+
if (perfstandbyOk != null) {
123+
rest.parameter("perfstandbyok", perfstandbyOk.toString());
124+
}
113125
if (activeCode != null) {
114126
rest.parameter("activecode", activeCode.toString());
115127
}
116128
if (standbyCode != null) {
117129
rest.parameter("standbycode", standbyCode.toString());
118130
}
131+
if (drsecondaryCode != null) {
132+
rest.parameter("drsecondarycode", drsecondaryCode.toString());
133+
}
134+
if (performanceStandbyCode != null) {
135+
rest.parameter("performancestandbycode", performanceStandbyCode.toString());
136+
}
119137
if (sealedCode != null) {
120138
rest.parameter("sealedcode", sealedCode.toString());
121139
}
122-
if (performanceStandbyCode != null) rest.parameter("performancestandbycode",
123-
performanceStandbyCode.toString());
140+
if (uninitCode != null) {
141+
rest.parameter("uninitcode", uninitCode.toString());
142+
}
124143
// Execute request
125144
final RestResponse restResponse = rest.get();
126145

127146
// Validate response
128147
final Set<Integer> validCodes = new HashSet<>();//NOPMD
129148
validCodes.add(200);
130149
validCodes.add(429);
131-
validCodes.add(500);
150+
validCodes.add(472);
132151
validCodes.add(473);
152+
validCodes.add(500);
153+
validCodes.add(501);
154+
validCodes.add(503);
133155
if (activeCode != null) {
134156
validCodes.add(activeCode);
135157
}
136158
if (standbyCode != null) {
137159
validCodes.add(standbyCode);
138160
}
161+
if (drsecondaryCode != null) {
162+
validCodes.add(drsecondaryCode);
163+
}
139164
if (sealedCode != null) {
140165
validCodes.add(sealedCode);
141166
}
142167
if (performanceStandbyCode != null) {
143168
validCodes.add(performanceStandbyCode);
144169
}
170+
if (uninitCode != null) {
171+
validCodes.add(uninitCode);
172+
}
145173

146174
if (!validCodes.contains(restResponse.getStatus())) {
147175
throw new VaultException(

src/main/java/io/github/jopenlibs/vault/response/HealthResponse.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class HealthResponse implements Serializable {
2020
private Boolean initialized;
2121
private Boolean sealed;
2222
private Boolean standby;
23+
private Boolean drsecondary;
24+
private Boolean perfstandby;
25+
private Boolean uninit;
2326
private Long serverTimeUTC;
2427

2528
/**
@@ -31,8 +34,7 @@ public class HealthResponse implements Serializable {
3134
* <code>standby</code>, and <code>serverTimeUTC</code> set to <code>null</code>. This
3235
* typically happens when you use optional parameters in the health call, to designate
3336
* non-standard HTTP status codes. See docs for
34-
* {@link Debug#health(Boolean, Integer, Integer, Integer, Integer)}.</p>
35-
*
37+
* {@link Debug#health(Boolean, Boolean, Integer, Integer, Integer,Integer, Integer, Integer)}.</p>
3638
* @param restResponse The raw HTTP response from Vault
3739
* @param retries The number of retry attempts that occurred during the API call (can be zero)
3840
* @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)
6567
: jsonObject.get("sealed").asBoolean();
6668
this.standby = jsonObject.get("standby") == null ? null
6769
: jsonObject.get("standby").asBoolean();
70+
this.drsecondary = jsonObject.get("drsecondary") == null ? null
71+
: jsonObject.get("drsecondary").asBoolean();
72+
this.perfstandby = jsonObject.get("perfstandby") == null ? null
73+
: jsonObject.get("perfstandby").asBoolean();
74+
this.uninit = jsonObject.get("uninit") == null ? null
75+
: jsonObject.get("uninit").asBoolean();
6876
this.serverTimeUTC = jsonObject.get("server_time_utc") == null ? null
6977
: jsonObject.get("server_time_utc").asLong();
7078
} catch (final Exception e) {
@@ -94,6 +102,18 @@ public Boolean getStandby() {
94102
return standby;
95103
}
96104

105+
public Boolean getDrsecondary() {
106+
return drsecondary;
107+
}
108+
109+
public Boolean getPerfstandby() {
110+
return perfstandby;
111+
}
112+
113+
public Boolean getuninit() {
114+
return uninit;
115+
}
116+
97117
/**
98118
* @return A value representing the number of milliseconds since the epoch. With all of the
99119
* changes in date API's between Java 8 and pre-Java 8, it seemed best for the library not to

src/test-integration/java/io/github/jopenlibs/vault/api/DebugTests.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,23 @@ public void testHealth_Plain() throws VaultException {
4444
assertFalse(response.getSealed());
4545
assertFalse(response.getStandby());
4646
assertNotNull(response.getServerTimeUTC());
47+
assertNull(response.getDrsecondary());
48+
assertNull(response.getPerfstandby());
49+
assertNull(response.getuninit());
4750
TestCase.assertEquals(200, response.getRestResponse().getStatus());
4851
}
4952

5053
@Test
5154
public void testHealth_WithParams() throws VaultException {
52-
final HealthResponse response = vault.debug().health(null, 212, null, null, null);
55+
final HealthResponse response = vault.debug().health(null, null, 212, null, null, null, null, null);
56+
5357
assertTrue(response.getInitialized());
5458
assertFalse(response.getSealed());
5559
assertFalse(response.getStandby());
5660
assertNotNull(response.getServerTimeUTC());
61+
assertNull(response.getDrsecondary());
62+
assertNull(response.getPerfstandby());
63+
assertNull(response.getuninit());
5764
TestCase.assertEquals(212, response.getRestResponse().getStatus());
5865
}
5966

@@ -66,12 +73,15 @@ public void testHealth_WithParams() throws VaultException {
6673
*/
6774
@Test
6875
public void testHealth_WonkyActiveCode() throws VaultException {
69-
final HealthResponse response = vault.debug().health(null, 204, null,
70-
null, null);
76+
final HealthResponse response = vault.debug().health(null, null, 204,
77+
null, null, null, null, null);
7178
assertNull(response.getInitialized());
7279
assertNull(response.getSealed());
7380
assertNull(response.getStandby());
7481
assertNull(response.getServerTimeUTC());
82+
assertNull(response.getDrsecondary());
83+
assertNull(response.getPerfstandby());
84+
assertNull(response.getuninit());
7585
TestCase.assertEquals(204, response.getRestResponse().getStatus());
7686
}
7787
}

0 commit comments

Comments
 (0)