Removed unnecessary boolean results from API
This commit is contained in:
parent
a80805a044
commit
ecf398c9d0
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>connector</artifactId>
|
||||
<version>0.4.0</version>
|
||||
<version>0.5.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -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<String, String> 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
|
||||
|
@ -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.
|
||||
|
@ -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.");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user