diff --git a/pom.xml b/pom.xml index 74c163f..ed86ebf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.stklcode.jvault connector - 0.4.0 + 0.5.0-SNAPSHOT UTF-8 diff --git a/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java b/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java index 6e23abc..a7b0f0d 100644 --- a/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java +++ b/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java @@ -499,7 +499,7 @@ public class HTTPVaultConnector implements VaultConnector { } @Override - public boolean writeSecret(final String key, final String value) throws VaultConnectorException { + public void writeSecret(final String key, final String value) throws VaultConnectorException { if (!isAuthorized()) throw new AuthorizationRequiredException(); @@ -508,11 +508,12 @@ public class HTTPVaultConnector implements VaultConnector { Map param = new HashMap<>(); param.put("value", value); - return requestPost(PATH_SECRET + "/" + key, param).equals(""); + if (!requestPost(PATH_SECRET + "/" + key, param).equals("")) + throw new InvalidResponseException("Received response where none was expected."); } @Override - public boolean deleteSecret(String key) throws VaultConnectorException { + public void deleteSecret(String key) throws VaultConnectorException { if (!isAuthorized()) throw new AuthorizationRequiredException(); @@ -521,13 +522,11 @@ public class HTTPVaultConnector implements VaultConnector { /* Response should be code 204 without content */ if (!response.equals("")) - throw new InvalidResponseException("Received response where non was expected."); - - return true; + throw new InvalidResponseException("Received response where none was expected."); } @Override - public boolean revoke(String leaseID) throws VaultConnectorException { + public void revoke(String leaseID) throws VaultConnectorException { if (!isAuthorized()) throw new AuthorizationRequiredException(); @@ -536,9 +535,7 @@ public class HTTPVaultConnector implements VaultConnector { /* Response should be code 204 without content */ if (!response.equals("")) - throw new InvalidResponseException("Received response where non was expected."); - - return true; + throw new InvalidResponseException("Received response where none was expected."); } @Override diff --git a/src/main/java/de/stklcode/jvault/connector/VaultConnector.java b/src/main/java/de/stklcode/jvault/connector/VaultConnector.java index 829ff7b..8603577 100644 --- a/src/main/java/de/stklcode/jvault/connector/VaultConnector.java +++ b/src/main/java/de/stklcode/jvault/connector/VaultConnector.java @@ -387,28 +387,25 @@ public interface VaultConnector { * * @param key Secret path * @param value Secret value - * @return TRUE on success * @throws VaultConnectorException on error */ - boolean writeSecret(final String key, final String value) throws VaultConnectorException; + void writeSecret(final String key, final String value) throws VaultConnectorException; /** * Delete secret from Vault. * * @param key Secret path - * @return TRUE on succevss * @throws VaultConnectorException on error */ - boolean deleteSecret(final String key) throws VaultConnectorException; + void deleteSecret(final String key) throws VaultConnectorException; /** * Revoke given lease immediately. * * @param leaseID the lease ID - * @return TRUE on success * @throws VaultConnectorException on error */ - boolean revoke(final String leaseID) throws VaultConnectorException; + void revoke(final String leaseID) throws VaultConnectorException; /** * Renew lease with given ID. diff --git a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java index d959109..7dae61b 100644 --- a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java +++ b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java @@ -523,29 +523,28 @@ public class HTTPVaultConnectorTest { /* Try to write to null path */ try { - boolean res = connector.writeSecret(null, "someValue"); + connector.writeSecret(null, "someValue"); fail("Secret written to null path."); } catch (VaultConnectorException e) { assertThat(e, instanceOf(InvalidRequestException.class)); } /* Try to write to invalid path */ try { - boolean res = connector.writeSecret("", "someValue"); + connector.writeSecret("", "someValue"); fail("Secret written to invalid path."); } catch (VaultConnectorException e) { assertThat(e, instanceOf(InvalidRequestException.class)); } /* Try to write to a path the user has no access for */ try { - boolean res = connector.writeSecret("invalid/path", "someValue"); + connector.writeSecret("invalid/path", "someValue"); fail("Secret written to inaccessible path."); } catch (VaultConnectorException e) { assertThat(e, instanceOf(PermissionDeniedException.class)); } /* Perform a valid write/read roundtrip to valid path. Also check UTF8-encoding. */ try { - boolean res = connector.writeSecret(SECRET_PATH + "/temp", "Abc123äöü,!"); - assertThat("Secret could not be written to valid path.", res, is(true)); + connector.writeSecret(SECRET_PATH + "/temp", "Abc123äöü,!"); } catch (VaultConnectorException e) { fail("Secret written to inaccessible path."); } @@ -567,8 +566,7 @@ public class HTTPVaultConnectorTest { /* Write a test secret to vault */ try { - boolean res = connector.writeSecret(SECRET_PATH + "/toDelete", "secret content"); - assumeThat("Secret could not be written path.", res, is(true)); + connector.writeSecret(SECRET_PATH + "/toDelete", "secret content"); } catch (VaultConnectorException e) { fail("Secret written to inaccessible path."); } @@ -582,8 +580,7 @@ public class HTTPVaultConnectorTest { /* Delete secret */ try { - boolean deleted = connector.deleteSecret(SECRET_PATH + "/toDelete"); - assertThat("Revocation of secret faiked.", deleted, is(true)); + connector.deleteSecret(SECRET_PATH + "/toDelete"); } catch (VaultConnectorException e) { fail("Revocation threw unexpected exception."); } @@ -608,8 +605,7 @@ public class HTTPVaultConnectorTest { /* Write a test secret to vault */ try { - boolean res = connector.writeSecret(SECRET_PATH + "/toRevoke", "secret content"); - assumeThat("Secret could not be written path.", res, is(true)); + connector.writeSecret(SECRET_PATH + "/toRevoke", "secret content"); } catch (VaultConnectorException e) { fail("Secret written to inaccessible path."); } @@ -623,8 +619,7 @@ public class HTTPVaultConnectorTest { /* Revoke secret */ try { - boolean revoked = connector.revoke(SECRET_PATH + "/toRevoke"); - assertThat("Revocation of secret faiked.", revoked, is(true)); + connector.revoke(SECRET_PATH + "/toRevoke"); } catch (VaultConnectorException e) { fail("Revocation threw unexpected exception."); }