Removed unnecessary boolean results from API

This commit is contained in:
Stefan Kalscheuer 2016-11-13 18:05:36 +01:00
parent a80805a044
commit ecf398c9d0
4 changed files with 19 additions and 30 deletions

View File

@ -6,7 +6,7 @@
<groupId>de.stklcode.jvault</groupId> <groupId>de.stklcode.jvault</groupId>
<artifactId>connector</artifactId> <artifactId>connector</artifactId>
<version>0.4.0</version> <version>0.5.0-SNAPSHOT</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -499,7 +499,7 @@ public class HTTPVaultConnector implements VaultConnector {
} }
@Override @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()) if (!isAuthorized())
throw new AuthorizationRequiredException(); throw new AuthorizationRequiredException();
@ -508,11 +508,12 @@ public class HTTPVaultConnector implements VaultConnector {
Map<String, String> param = new HashMap<>(); Map<String, String> param = new HashMap<>();
param.put("value", value); 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 @Override
public boolean deleteSecret(String key) throws VaultConnectorException { public void deleteSecret(String key) throws VaultConnectorException {
if (!isAuthorized()) if (!isAuthorized())
throw new AuthorizationRequiredException(); throw new AuthorizationRequiredException();
@ -521,13 +522,11 @@ public class HTTPVaultConnector implements VaultConnector {
/* Response should be code 204 without content */ /* Response should be code 204 without content */
if (!response.equals("")) if (!response.equals(""))
throw new InvalidResponseException("Received response where non was expected."); throw new InvalidResponseException("Received response where none was expected.");
return true;
} }
@Override @Override
public boolean revoke(String leaseID) throws VaultConnectorException { public void revoke(String leaseID) throws VaultConnectorException {
if (!isAuthorized()) if (!isAuthorized())
throw new AuthorizationRequiredException(); throw new AuthorizationRequiredException();
@ -536,9 +535,7 @@ public class HTTPVaultConnector implements VaultConnector {
/* Response should be code 204 without content */ /* Response should be code 204 without content */
if (!response.equals("")) if (!response.equals(""))
throw new InvalidResponseException("Received response where non was expected."); throw new InvalidResponseException("Received response where none was expected.");
return true;
} }
@Override @Override

View File

@ -387,28 +387,25 @@ public interface VaultConnector {
* *
* @param key Secret path * @param key Secret path
* @param value Secret value * @param value Secret value
* @return TRUE on success
* @throws VaultConnectorException on error * @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. * Delete secret from Vault.
* *
* @param key Secret path * @param key Secret path
* @return TRUE on succevss
* @throws VaultConnectorException on error * @throws VaultConnectorException on error
*/ */
boolean deleteSecret(final String key) throws VaultConnectorException; void deleteSecret(final String key) throws VaultConnectorException;
/** /**
* Revoke given lease immediately. * Revoke given lease immediately.
* *
* @param leaseID the lease ID * @param leaseID the lease ID
* @return TRUE on success
* @throws VaultConnectorException on error * @throws VaultConnectorException on error
*/ */
boolean revoke(final String leaseID) throws VaultConnectorException; void revoke(final String leaseID) throws VaultConnectorException;
/** /**
* Renew lease with given ID. * Renew lease with given ID.

View File

@ -523,29 +523,28 @@ public class HTTPVaultConnectorTest {
/* Try to write to null path */ /* Try to write to null path */
try { try {
boolean res = connector.writeSecret(null, "someValue"); connector.writeSecret(null, "someValue");
fail("Secret written to null path."); fail("Secret written to null path.");
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
assertThat(e, instanceOf(InvalidRequestException.class)); assertThat(e, instanceOf(InvalidRequestException.class));
} }
/* Try to write to invalid path */ /* Try to write to invalid path */
try { try {
boolean res = connector.writeSecret("", "someValue"); connector.writeSecret("", "someValue");
fail("Secret written to invalid path."); fail("Secret written to invalid path.");
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
assertThat(e, instanceOf(InvalidRequestException.class)); assertThat(e, instanceOf(InvalidRequestException.class));
} }
/* Try to write to a path the user has no access for */ /* Try to write to a path the user has no access for */
try { try {
boolean res = connector.writeSecret("invalid/path", "someValue"); connector.writeSecret("invalid/path", "someValue");
fail("Secret written to inaccessible path."); fail("Secret written to inaccessible path.");
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
assertThat(e, instanceOf(PermissionDeniedException.class)); assertThat(e, instanceOf(PermissionDeniedException.class));
} }
/* Perform a valid write/read roundtrip to valid path. Also check UTF8-encoding. */ /* Perform a valid write/read roundtrip to valid path. Also check UTF8-encoding. */
try { try {
boolean res = connector.writeSecret(SECRET_PATH + "/temp", "Abc123äöü,!"); connector.writeSecret(SECRET_PATH + "/temp", "Abc123äöü,!");
assertThat("Secret could not be written to valid path.", res, is(true));
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
fail("Secret written to inaccessible path."); fail("Secret written to inaccessible path.");
} }
@ -567,8 +566,7 @@ public class HTTPVaultConnectorTest {
/* Write a test secret to vault */ /* Write a test secret to vault */
try { try {
boolean res = connector.writeSecret(SECRET_PATH + "/toDelete", "secret content"); connector.writeSecret(SECRET_PATH + "/toDelete", "secret content");
assumeThat("Secret could not be written path.", res, is(true));
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
fail("Secret written to inaccessible path."); fail("Secret written to inaccessible path.");
} }
@ -582,8 +580,7 @@ public class HTTPVaultConnectorTest {
/* Delete secret */ /* Delete secret */
try { try {
boolean deleted = connector.deleteSecret(SECRET_PATH + "/toDelete"); connector.deleteSecret(SECRET_PATH + "/toDelete");
assertThat("Revocation of secret faiked.", deleted, is(true));
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
fail("Revocation threw unexpected exception."); fail("Revocation threw unexpected exception.");
} }
@ -608,8 +605,7 @@ public class HTTPVaultConnectorTest {
/* Write a test secret to vault */ /* Write a test secret to vault */
try { try {
boolean res = connector.writeSecret(SECRET_PATH + "/toRevoke", "secret content"); connector.writeSecret(SECRET_PATH + "/toRevoke", "secret content");
assumeThat("Secret could not be written path.", res, is(true));
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
fail("Secret written to inaccessible path."); fail("Secret written to inaccessible path.");
} }
@ -623,8 +619,7 @@ public class HTTPVaultConnectorTest {
/* Revoke secret */ /* Revoke secret */
try { try {
boolean revoked = connector.revoke(SECRET_PATH + "/toRevoke"); connector.revoke(SECRET_PATH + "/toRevoke");
assertThat("Revocation of secret faiked.", revoked, is(true));
} catch (VaultConnectorException e) { } catch (VaultConnectorException e) {
fail("Revocation threw unexpected exception."); fail("Revocation threw unexpected exception.");
} }