Add replication flags to HealthResponse (closes #21)

This commit is contained in:
Stefan Kalscheuer 2018-10-06 10:58:43 +02:00
parent 44858edb76
commit 13793dc9ce
4 changed files with 52 additions and 9 deletions

View File

@ -3,6 +3,7 @@
refactoring of the internal SSL handling (#17) refactoring of the internal SSL handling (#17)
* [improvement] `VaultConnector` extends `java.io.Serializable` (#19) * [improvement] `VaultConnector` extends `java.io.Serializable` (#19)
* [improvement] Added missing flags to `SealResponse` (#20) * [improvement] Added missing flags to `SealResponse` (#20)
* [improvement] Added replication flags to `HealthResponse` (#21)
* [improvement] Build environment and tests now compatible with Java 10 * [improvement] Build environment and tests now compatible with Java 10
* [dependencies] Updated dependencies to fix vulnerabilities (i.e. CVE-2018-7489) * [dependencies] Updated dependencies to fix vulnerabilities (i.e. CVE-2018-7489)
* [deprecation] `VaultConnectorFactory` is deprecated in favor of `VaultConnectorBuilder` with identical API (#18) * [deprecation] `VaultConnectorFactory` is deprecated in favor of `VaultConnectorBuilder` with identical API (#18)

View File

@ -71,13 +71,13 @@ VaultConnector vault = VaultConnectorFactory.httpFactory()
### Authentication ### Authentication
```java ```java
// Authenticate with token // Authenticate with token.
vault.authToken("01234567-89ab-cdef-0123-456789abcdef"); vault.authToken("01234567-89ab-cdef-0123-456789abcdef");
// Authenticate with username and password // Authenticate with username and password.
vault.authUserPass("username", "p4ssw0rd"); vault.authUserPass("username", "p4ssw0rd");
// Authenticate with AppID (secret - 2nd argument - is optional) // Authenticate with AppRole (secret - 2nd argument - is optional).
vault.authAppId("01234567-89ab-cdef-0123-456789abcdef", "fedcba98-7654-3210-fedc-ba9876543210"); vault.authAppId("01234567-89ab-cdef-0123-456789abcdef", "fedcba98-7654-3210-fedc-ba9876543210");
``` ```
@ -87,17 +87,17 @@ vault.authAppId("01234567-89ab-cdef-0123-456789abcdef", "fedcba98-7654-3210-fedc
// Retrieve secret (prefix "secret/" assumed, use read() to read arbitrary paths) // Retrieve secret (prefix "secret/" assumed, use read() to read arbitrary paths)
String secret = vault.readSecret("some/secret/key").getValue(); String secret = vault.readSecret("some/secret/key").getValue();
// Complex secret // Complex secret.
Map<String, Object> secretData = vault.readSecret("another/secret/key").getData(); Map<String, Object> secretData = vault.readSecret("another/secret/key").getData();
// Write simple secret // Write simple secret.
vault.writeSecret("new/secret/key", "secret value"); vault.writeSecret("new/secret/key", "secret value");
// Write complex data to arbitraty path // Write complex data to arbitraty path.
Map<String, Object> map = [...] Map<String, Object> map = [...]
vault.write("any/path/to/write", map); vault.write("any/path/to/write", map);
// Delete secret // Delete secret.
vault.delete("any/path/to/write"); vault.delete("any/path/to/write");
``` ```

View File

@ -48,6 +48,15 @@ public final class HealthResponse implements VaultResponse {
@JsonProperty("initialized") @JsonProperty("initialized")
private Boolean initialized; private Boolean initialized;
@JsonProperty("replication_perf_mode")
private String replicationPerfMode;
@JsonProperty("replication_dr_mode")
private String replicationDrMode;
@JsonProperty("performance_standby")
private Boolean performanceStandby;
/** /**
* @return The Cluster ID. * @return The Cluster ID.
*/ */
@ -96,4 +105,28 @@ public final class HealthResponse implements VaultResponse {
public Boolean isInitialized() { public Boolean isInitialized() {
return initialized; return initialized;
} }
/**
* @return Replication performance mode of the active node (since Vault 0.9.2).
* @since 0.8 (#21)
*/
public String getReplicationPerfMode() {
return replicationPerfMode;
}
/**
* @return Replication DR mode of the active node (since Vault 0.9.2).
* @since 0.8 (#21)
*/
public String getReplicationDrMode() {
return replicationDrMode;
}
/**
* @return Performance standby status.
* @since 0.8 (#21)
*/
public Boolean isPerformanceStandby() {
return performanceStandby;
}
} }

View File

@ -35,11 +35,14 @@ import static org.junit.jupiter.api.Assertions.fail;
public class HealthResponseTest { public class HealthResponseTest {
private static final String CLUSTER_ID = "c9abceea-4f46-4dab-a688-5ce55f89e228"; private static final String CLUSTER_ID = "c9abceea-4f46-4dab-a688-5ce55f89e228";
private static final String CLUSTER_NAME = "vault-cluster-5515c810"; private static final String CLUSTER_NAME = "vault-cluster-5515c810";
private static final String VERSION = "0.6.2"; private static final String VERSION = "0.9.2";
private static final Long SERVER_TIME_UTC = 1469555798L; private static final Long SERVER_TIME_UTC = 1469555798L;
private static final Boolean STANDBY = false; private static final Boolean STANDBY = false;
private static final Boolean SEALED = false; private static final Boolean SEALED = false;
private static final Boolean INITIALIZED = true; private static final Boolean INITIALIZED = true;
private static final Boolean PERF_STANDBY = false;
private static final String REPL_PERF_MODE = "disabled";
private static final String REPL_DR_MODE = "disabled";
private static final String RES_JSON = "{\n" + private static final String RES_JSON = "{\n" +
" \"cluster_id\": \"" + CLUSTER_ID + "\",\n" + " \"cluster_id\": \"" + CLUSTER_ID + "\",\n" +
@ -48,7 +51,10 @@ public class HealthResponseTest {
" \"server_time_utc\": " + SERVER_TIME_UTC + ",\n" + " \"server_time_utc\": " + SERVER_TIME_UTC + ",\n" +
" \"standby\": " + STANDBY + ",\n" + " \"standby\": " + STANDBY + ",\n" +
" \"sealed\": " + SEALED + ",\n" + " \"sealed\": " + SEALED + ",\n" +
" \"initialized\": " + INITIALIZED + "\n" + " \"initialized\": " + INITIALIZED + ",\n" +
" \"replication_perf_mode\": \"" + REPL_PERF_MODE + "\",\n" +
" \"replication_dr_mode\": \"" + REPL_DR_MODE + "\",\n" +
" \"performance_standby\": " + PERF_STANDBY + "\n" +
"}"; "}";
/** /**
* Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation).
@ -65,6 +71,9 @@ public class HealthResponseTest {
assertThat("Incorrect standby state", res.isStandby(), is(STANDBY)); assertThat("Incorrect standby state", res.isStandby(), is(STANDBY));
assertThat("Incorrect seal state", res.isSealed(), is(SEALED)); assertThat("Incorrect seal state", res.isSealed(), is(SEALED));
assertThat("Incorrect initialization state", res.isInitialized(), is(INITIALIZED)); assertThat("Incorrect initialization state", res.isInitialized(), is(INITIALIZED));
assertThat("Incorrect performance standby state", res.isPerformanceStandby(), is(PERF_STANDBY));
assertThat("Incorrect replication perf mode", res.getReplicationPerfMode(), is(REPL_PERF_MODE));
assertThat("Incorrect replication DR mode", res.getReplicationDrMode(), is(REPL_DR_MODE));
} catch (IOException e) { } catch (IOException e) {
fail("Health deserialization failed: " + e.getMessage()); fail("Health deserialization failed: " + e.getMessage());
} }