Search in sources :

Example 6 with SecretSeriesAndContent

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

the class SecretsResourceIntegrationTest method partialUpdateSecretOverwritesNullOwnerWithNonNullValue.

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

Example 7 with SecretSeriesAndContent

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

the class SecretDAOTest method createOrUpdateNonExistingSecretWithOwner.

@Test
public void createOrUpdateNonExistingSecretWithOwner() {
    String ownerName = createGroup();
    long secretId = createOrUpdateSecretWithOwner(ownerName);
    SecretSeriesAndContent secret = secretDAO.getSecretById(secretId).get();
    assertEquals(ownerName, secret.series().owner());
}
Also used : SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 8 with SecretSeriesAndContent

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

the class SecretDAOTest method createsSecretWithOwner.

@Test
public void createsSecretWithOwner() {
    String ownerName = createGroup();
    long secretId = createSecretWithOwner(ownerName);
    SecretSeriesAndContent secret = secretDAO.getSecretById(secretId).get();
    assertEquals(ownerName, secret.series().owner());
}
Also used : SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 9 with SecretSeriesAndContent

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

the class SecretDetailResponseV2Test method formsCorrectlyFromSecretSeriesAndContent.

@Test
public void formsCorrectlyFromSecretSeriesAndContent() {
    SecretSeries series = SecretSeries.of(1, "secret-name", "secret-owner", "secret-description", ApiDate.parse("2013-03-28T21:23:04.159Z"), "creator-user", ApiDate.parse("2014-03-28T21:23:04.159Z"), "updater-user", "text/plain", null, 1L);
    SecretContent content = SecretContent.of(1, 1, "YXNkZGFz", "checksum", ApiDate.parse("2014-03-28T21:23:04.159Z"), "updater-user", ApiDate.parse("2014-03-28T21:23:04.159Z"), "updater-user", ImmutableMap.of("owner", "root"), 1136214245);
    SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
    SecretDetailResponseV2 fromSeriesAndContent = SecretDetailResponseV2.builder().seriesAndContent(seriesAndContent).build();
    assertThat(fromSeriesAndContent).isEqualTo(secretDetailResponse);
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) SecretContent(keywhiz.api.model.SecretContent) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent) Test(org.junit.Test)

Example 10 with SecretSeriesAndContent

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

the class SecretDAO method getSecretsBatched.

/**
 * @param idx the first index to select in a list of secrets sorted by creation time
 * @param num the number of secrets after idx to select in the list of secrets
 * @param newestFirst if true, order the secrets from newest creation time to oldest
 * @return A list of secrets
 */
public ImmutableList<SecretSeriesAndContent> getSecretsBatched(int idx, int num, boolean newestFirst) {
    return dslContext.transactionResult(configuration -> {
        SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
        SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);
        ImmutableList.Builder<SecretSeriesAndContent> secretsBuilder = ImmutableList.builder();
        for (SecretSeries series : secretSeriesDAO.getSecretSeriesBatched(idx, num, newestFirst)) {
            SecretContent content = secretContentDAO.getSecretContentById(series.currentVersion().get()).get();
            SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
            secretsBuilder.add(seriesAndContent);
        }
        return secretsBuilder.build();
    });
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) ImmutableList(com.google.common.collect.ImmutableList) SecretContent(keywhiz.api.model.SecretContent) SecretSeriesAndContent(keywhiz.api.model.SecretSeriesAndContent)

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