use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.
the class RollbackAction method run.
@Override
public void run() {
try {
if (rollbackActionConfig.name == null || !validName(rollbackActionConfig.name)) {
throw new IllegalArgumentException(format("Invalid name, must match %s", VALID_NAME_PATTERN));
}
if (rollbackActionConfig.id == null || rollbackActionConfig.id < 0) {
throw new IllegalArgumentException("Version ID must be specified and non-negative for rollback. List the secret's versions to view IDs.");
}
SanitizedSecret sanitizedSecret = keywhizClient.getSanitizedSecretByName(rollbackActionConfig.name);
// Get user confirmation for the rollback
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8));
while (true) {
System.out.println(format("Please confirm rollback of secret '%s' to version with ID %d: Y/N", sanitizedSecret.name(), rollbackActionConfig.id));
String line = reader.readLine();
if (line == null || /* EOF */
line.toUpperCase().startsWith("N")) {
return;
} else if (line.toUpperCase().startsWith("Y")) {
logger.info("Rolling back secret '{}' to version {}", sanitizedSecret.name(), rollbackActionConfig.id);
keywhizClient.rollbackSecret(sanitizedSecret.name(), rollbackActionConfig.id);
return;
}
// else loop again
}
} catch (NotFoundException e) {
throw new AssertionError("Secret does not exist: " + rollbackActionConfig.name);
} catch (IOException e) {
throw new AssertionError(String.format("Error executing rollback; check whether ID %d is a valid version ID for secret %s by listing the secret's versions%nError: %s", rollbackActionConfig.id, rollbackActionConfig.name, e.getMessage()));
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.
the class UpdateActionTest method updateCallsUpdateForSecret.
@Test
public void updateCallsUpdateForSecret() throws Exception {
updateActionConfig.name = secret.getDisplayName();
updateActionConfig.expiry = "2006-01-02T15:04:05Z";
updateActionConfig.contentProvided = true;
byte[] content = base64Decoder.decode(secret.getSecret());
updateAction.stream = new ByteArrayInputStream(content);
when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
new NotFoundException());
when(keywhizClient.updateSecret(secret.getName(), false, "", true, content, false, updateActionConfig.getMetadata(Jackson.newObjectMapper()), true, 1136214245)).thenReturn(secretDetailResponse);
updateAction.run();
verify(keywhizClient, times(1)).updateSecret(secret.getName(), false, "", true, content, false, updateActionConfig.getMetadata(Jackson.newObjectMapper()), true, 1136214245);
}
use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.
the class UpdateActionTest method updateThrowsIfMetadataHasBadKeys.
@Test(expected = IllegalArgumentException.class)
public void updateThrowsIfMetadataHasBadKeys() throws Exception {
updateActionConfig.name = secret.getDisplayName();
updateActionConfig.json = "{\"ThisIsABadKey\":\"doh\"}";
updateAction.stream = new ByteArrayInputStream(base64Decoder.decode(secret.getSecret()));
when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
new NotFoundException());
updateAction.run();
}
use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.
the class UpdateActionTest method updateWithMetadata.
@Test
public void updateWithMetadata() throws Exception {
updateActionConfig.name = secret.getDisplayName();
updateActionConfig.description = "metadata test";
updateActionConfig.json = "{\"owner\":\"example-name\", \"group\":\"example-group\"}";
updateActionConfig.contentProvided = true;
byte[] content = base64Decoder.decode(secret.getSecret());
updateAction.stream = new ByteArrayInputStream(content);
when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
new NotFoundException());
when(keywhizClient.updateSecret(secret.getName(), true, "metadata test", true, content, true, updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0)).thenReturn(secretDetailResponse);
updateAction.run();
verify(keywhizClient, times(1)).updateSecret(secret.getName(), true, "metadata test", true, content, true, updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0);
}
use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.
the class AddActionTest method addCallsAddForSecret.
@Test
public void addCallsAddForSecret() throws Exception {
addActionConfig.addType = Arrays.asList("secret");
addActionConfig.name = secret.getDisplayName();
addActionConfig.expiry = "2006-01-02T15:04:05Z";
byte[] content = base64Decoder.decode(secret.getSecret());
addAction.stream = new ByteArrayInputStream(content);
when(keywhizClient.getSanitizedSecretByName(secret.getName())).thenThrow(// Call checks for existence.
new NotFoundException());
when(keywhizClient.createSecret(secret.getName(), "", content, secret.getMetadata(), 1136214245)).thenReturn(secretDetailResponse);
addAction.run();
verify(keywhizClient, times(1)).createSecret(secret.getName(), "", content, secret.getMetadata(), 1136214245);
}
Aggregations