Search in sources :

Example 11 with SecretContent

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

the class SecretResource method backfillHmac.

/**
 * Backfill content hmac for this secret.
 */
@Timed
@ExceptionMetered
@Path("{name}/backfill-hmac")
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public boolean backfillHmac(@Auth AutomationClient automationClient, @PathParam("name") String name) {
    Optional<SecretSeriesAndContent> secret = secretDAO.getSecretByName(name);
    if (!secret.isPresent()) {
        return false;
    }
    logger.info("backfill-hmac {}: processing secret", name);
    SecretContent secretContent = secret.get().content();
    if (!secretContent.hmac().isEmpty()) {
        // No need to backfill
        return true;
    }
    String hmac = cryptographer.computeHmac(cryptographer.decrypt(secretContent.encryptedContent()).getBytes(UTF_8), "hmackey");
    // We expect only one row to be changed
    return secretSeriesDAO.setHmac(secretContent.id(), hmac) == 1;
}
Also used : SecretContent(keywhiz.api.model.SecretContent) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 12 with SecretContent

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

the class SecretTransformerTest method transformsOwner.

@Test
public void transformsOwner() {
    String ownerName = "foo";
    SecretSeries series = validSeries().toBuilder().owner(ownerName).build();
    SecretContent content = validContent();
    SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
    Secret secret = transformer.transform(seriesAndContent);
    assertEquals(ownerName, secret.getOwner());
}
Also used : Secret(keywhiz.api.model.Secret) SecretSeries(keywhiz.api.model.SecretSeries) SecretContent(keywhiz.api.model.SecretContent) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Aggregations

SecretContent (keywhiz.api.model.SecretContent)12 SecretSeries (keywhiz.api.model.SecretSeries)9 SecretSeriesAndContent (keywhiz.api.model.SecretSeriesAndContent)9 ImmutableList (com.google.common.collect.ImmutableList)3 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)2 Timed (com.codahale.metrics.annotation.Timed)2 Consumes (javax.ws.rs.Consumes)2 NotFoundException (javax.ws.rs.NotFoundException)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Secret (keywhiz.api.model.Secret)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 SanitizedSecret (keywhiz.api.model.SanitizedSecret)1 SecretsContentRecord (keywhiz.jooq.tables.records.SecretsContentRecord)1 ContentEncodingException (keywhiz.service.crypto.ContentEncodingException)1