Search in sources :

Example 1 with SecretDetailResponse

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));
}
Also used : Group(keywhiz.api.model.Group) SecretDetailResponse(keywhiz.api.SecretDetailResponse) IOException(java.io.IOException) Client(keywhiz.api.model.Client) KeywhizClient(keywhiz.client.KeywhizClient) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date)

Example 2 with SecretDetailResponse

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);
    }
}
Also used : SecretDetailResponse(keywhiz.api.SecretDetailResponse) IOException(java.io.IOException)

Example 3 with SecretDetailResponse

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());
}
Also used : SecretDetailResponse(keywhiz.api.SecretDetailResponse) LongParam(io.dropwizard.jersey.params.LongParam) Test(org.junit.Test)

Example 4 with SecretDetailResponse

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");
}
Also used : SecretDetailResponse(keywhiz.api.SecretDetailResponse) Test(org.junit.Test)

Example 5 with SecretDetailResponse

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");
}
Also used : SecretDetailResponse(keywhiz.api.SecretDetailResponse) Test(org.junit.Test)

Aggregations

SecretDetailResponse (keywhiz.api.SecretDetailResponse)7 Test (org.junit.Test)5 LongParam (io.dropwizard.jersey.params.LongParam)3 IOException (java.io.IOException)2 Client (keywhiz.api.model.Client)2 Group (keywhiz.api.model.Group)2 KeywhizClient (keywhiz.client.KeywhizClient)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1