Search in sources :

Example 16 with SecretSeriesAndContent

use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.

the class AclDAO method getSanitizedSecretsFor.

public ImmutableSet<SanitizedSecret> getSanitizedSecretsFor(Group group) {
    checkNotNull(group);
    ImmutableSet.Builder<SanitizedSecret> set = ImmutableSet.builder();
    return dslContext.transactionResult(configuration -> {
        SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
        for (SecretSeries series : getSecretSeriesFor(configuration, group)) {
            SecretContent content = secretContentDAO.getSecretContentById(series.currentVersion().get()).get();
            SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
            set.add(SanitizedSecret.fromSecretSeriesAndContent(seriesAndContent));
        }
        return set.build();
    });
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) ImmutableSet(com.google.common.collect.ImmutableSet) SecretSeries(keywhiz.api.model.SecretSeries) SecretContent(keywhiz.api.model.SecretContent) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent)

Example 17 with SecretSeriesAndContent

use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.

the class SecretsResourceIntegrationTest method partialUpdateSecretOverwritesNonNullOwnerWithNullValue.

@Test
public void partialUpdateSecretOverwritesNonNullOwnerWithNullValue() {
    String groupName = createGroup();
    String secretName = createSecretWithOwner(groupName);
    SecretSeriesAndContent originalSecret = getSecret(secretName);
    assertEquals(groupName, originalSecret.series().owner());
    updateOwner(secretName, null);
    SecretSeriesAndContent updatedSecret = getSecret(secretName);
    assertNull(updatedSecret.series().owner());
}
Also used : SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 18 with SecretSeriesAndContent

use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.

the class SecretsResourceIntegrationTest method partialUpdateSecretIgnoresOwnerIfNotPresent.

@Test
public void partialUpdateSecretIgnoresOwnerIfNotPresent() {
    String secretName = createSecretWithOwner(null);
    SecretSeriesAndContent originalSecret = getSecret(secretName);
    assertNull(originalSecret.series().owner());
    String groupName = createGroup();
    PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().ownerPresent(false).owner(groupName).build();
    resource.partialUpdateSecret(User.named("nobody"), secretName, request);
    SecretSeriesAndContent updatedSecret = getSecret(secretName);
    assertNull(updatedSecret.series().owner());
}
Also used : PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 19 with SecretSeriesAndContent

use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.

the class SecretsResourceIntegrationTest method partialUpdateSecretOverwritesNonNullOwnerWithNonNullValue.

@Test
public void partialUpdateSecretOverwritesNonNullOwnerWithNonNullValue() {
    String group1 = createGroup();
    String group2 = createGroup();
    String secretName = createSecretWithOwner(group1);
    SecretSeriesAndContent originalSecret = getSecret(secretName);
    assertEquals(group1, originalSecret.series().owner());
    updateOwner(secretName, group2);
    SecretSeriesAndContent updatedSecret = getSecret(secretName);
    assertEquals(group2, updatedSecret.series().owner());
}
Also used : SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 20 with SecretSeriesAndContent

use of keywhiz.api.model.SecretSeriesAndContent in project keywhiz by square.

the class SecretResource method renameSecret.

@Timed
@ExceptionMetered
@Path("{oldName}/rename/{newName}")
@POST
@Consumes(APPLICATION_JSON)
public Response renameSecret(@Auth AutomationClient automationClient, @PathParam("oldName") String oldName, @PathParam("newName") String newName) {
    SecretSeriesAndContent secret = secretDAO.getSecretByName(oldName).orElseThrow(NotFoundException::new);
    secretDAO.renameSecretById(secret.series().id(), newName, automationClient.getName());
    UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(newName);
    return Response.created(uriBuilder.build()).build();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

SecretSeriesAndContent (keywhiz.api.model.SecretSeriesAndContent)26 Test (org.junit.Test)16 SecretContent (keywhiz.api.model.SecretContent)9 SecretSeries (keywhiz.api.model.SecretSeries)8 ImmutableList (com.google.common.collect.ImmutableList)5 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3 Timed (com.codahale.metrics.annotation.Timed)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 NotFoundException (javax.ws.rs.NotFoundException)2 Produces (javax.ws.rs.Produces)2 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 Secret (keywhiz.api.model.Secret)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ArrayList (java.util.ArrayList)1