use of keywhiz.api.SecretDetailResponse in project keywhiz by square.
the class Printing method printSanitizedSecretWithDetails.
public void printSanitizedSecretWithDetails(SanitizedSecret secret) {
System.out.println(SanitizedSecret.displayName(secret));
SecretDetailResponse secretDetails;
try {
secretDetails = keywhizClient.secretDetailsForId(secret.id());
} catch (IOException e) {
throw Throwables.propagate(e);
}
System.out.println("\tGroups:");
secretDetails.groups.stream().sorted(Comparator.comparing(Group::getName)).forEach(g -> System.out.println(INDENT + g.getName()));
System.out.println("\tClients:");
secretDetails.clients.stream().sorted(Comparator.comparing(Client::getName)).forEach(c -> System.out.println(INDENT + c.getName()));
System.out.println("\tMetadata:");
if (!secret.metadata().isEmpty()) {
String metadata;
try {
metadata = new ObjectMapper().writeValueAsString(secret.metadata());
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
System.out.println(INDENT + metadata);
}
if (secret.expiry() > 0) {
System.out.println("\tExpiry:");
Date d = new Date(secret.expiry() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
if (!secret.description().isEmpty()) {
System.out.println("\tDescription:");
System.out.println(INDENT + secret.description());
}
if (!secret.createdBy().isEmpty()) {
System.out.println("\tCreated by:");
System.out.println(INDENT + secret.createdBy());
}
System.out.println("\tCreated at:");
Date d = new Date(secret.createdAt().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
if (!secret.updatedBy().isEmpty()) {
System.out.println("\tUpdated by:");
System.out.println(INDENT + secret.updatedBy());
}
System.out.println("\tUpdated at:");
d = new Date(secret.updatedAt().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
use of keywhiz.api.SecretDetailResponse in project keywhiz by square.
the class AddAction method createAndAssignSecret.
private void createAndAssignSecret(String secretName, String description, byte[] content, ImmutableMap<String, String> metadata, long expiry) {
try {
SecretDetailResponse secretResponse = keywhizClient.createSecret(secretName, description, content, metadata, expiry);
long secretId = secretResponse.id;
logger.info("Creating secret '{}'.", secretName);
// Optionally, also assign
if (config.group != null) {
assignSecret(secretId, secretName);
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of keywhiz.api.SecretDetailResponse in project keywhiz by square.
the class SecretsResourceTest method includesTheSecret.
@Test
public void includesTheSecret() {
when(secretController.getSecretById(22)).thenReturn(Optional.of(secret));
when(aclDAO.getGroupsFor(secret)).thenReturn(Collections.emptySet());
when(aclDAO.getClientsFor(secret)).thenReturn(Collections.emptySet());
SecretDetailResponse response = resource.retrieveSecret(user, new LongParam("22"));
assertThat(response.id).isEqualTo(secret.getId());
assertThat(response.name).isEqualTo(secret.getName());
assertThat(response.description).isEqualTo(secret.getDescription());
assertThat(response.createdAt).isEqualTo(secret.getCreatedAt());
assertThat(response.createdBy).isEqualTo(secret.getCreatedBy());
assertThat(response.updatedAt).isEqualTo(secret.getUpdatedAt());
assertThat(response.updatedBy).isEqualTo(secret.getUpdatedBy());
assertThat(response.metadata).isEqualTo(secret.getMetadata());
}
use of keywhiz.api.SecretDetailResponse in project keywhiz by square.
the class SecretsResourceIntegrationTest method createsSecret.
@Test
public void createsSecret() throws IOException {
keywhizClient.login(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword.toCharArray());
SecretDetailResponse secretDetails = keywhizClient.createSecret("newSecret", "", "content".getBytes(UTF_8), ImmutableMap.of(), 0);
assertThat(secretDetails.name).isEqualTo("newSecret");
assertThat(keywhizClient.allSecrets().stream().map(SanitizedSecret::name).toArray()).contains("newSecret");
}
use of keywhiz.api.SecretDetailResponse in project keywhiz by square.
the class SecretsResourceIntegrationTest method listsSpecificSecret.
@Test
public void listsSpecificSecret() throws IOException {
keywhizClient.login(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword.toCharArray());
SecretDetailResponse response = keywhizClient.secretDetailsForId(737);
assertThat(response.name).isEqualTo("Nobody_PgPass");
}
Aggregations