Search in sources :

Example 1 with SecretVersion

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

the class SecretDetailResponseV2Test method formsCorrectlyFromSecretVersion.

@Test
public void formsCorrectlyFromSecretVersion() throws Exception {
    SecretVersion version = SecretVersion.of(10, 1, "secret-name", "secret-description", "checksum", ApiDate.parse("2013-03-28T21:23:04.159Z"), "creator-user", ApiDate.parse("2013-03-28T21:23:04.159Z"), "creator-user", ImmutableMap.of("owner", "root"), "text/plain", 1136214245);
    SecretDetailResponseV2 secretDetailResponse = SecretDetailResponseV2.builder().secretVersion(version).content("YXNkZGFz").build();
    assertThat(asJson(secretDetailResponse)).isEqualTo(jsonFixture("fixtures/v2/secretDetailResponse.json"));
}
Also used : SecretVersion(keywhiz.api.model.SecretVersion) Test(org.junit.Test)

Example 2 with SecretVersion

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

the class SecretDAO method getSecretVersionsByName.

/**
   * @param name of secret series to look up secrets by.
   * @param versionIdx the first index to select in a list of versions sorted by creation time
   * @param numVersions the number of versions after versionIdx to select in the list of versions
   * @return Versions of a secret matching input parameters or Optional.absent().
   */
public Optional<ImmutableList<SecretVersion>> getSecretVersionsByName(String name, int versionIdx, int numVersions) {
    checkArgument(!name.isEmpty());
    checkArgument(versionIdx >= 0);
    checkArgument(numVersions >= 0);
    SecretContentDAO secretContentDAO = secretContentDAOFactory.using(dslContext.configuration());
    SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration());
    Optional<SecretSeries> series = secretSeriesDAO.getSecretSeriesByName(name);
    if (series.isPresent()) {
        SecretSeries s = series.get();
        long secretId = s.id();
        Optional<ImmutableList<SecretContent>> contents = secretContentDAO.getSecretVersionsBySecretId(secretId, versionIdx, numVersions);
        if (contents.isPresent()) {
            ImmutableList.Builder<SecretVersion> b = new ImmutableList.Builder<>();
            b.addAll(contents.get().stream().map(c -> SecretVersion.of(s.id(), c.id(), s.name(), s.description(), c.hmac(), c.createdAt(), c.createdBy(), c.updatedAt(), c.updatedBy(), c.metadata(), s.type().orElse(""), c.expiry())).collect(toList()));
            return Optional.of(b.build());
        }
    }
    return Optional.empty();
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) SecretVersion(keywhiz.api.model.SecretVersion) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with SecretVersion

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

the class SecretsResourceTest method listSecretVersions.

@Test
public void listSecretVersions() {
    SanitizedSecret secret1 = SanitizedSecret.of(1, "name1", "checksum", "desc", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 125L);
    SanitizedSecret secret2 = SanitizedSecret.of(1, "name1", "checksum2", "desc", NOWPLUS, "user", NOWPLUS, "user", emptyMap, null, null, 1136214245, 250L);
    SecretVersion version1 = SecretVersion.of(1, 125L, "name1", "desc", "checksum", NOW, "user", NOW, "user", emptyMap, null, 1136214245);
    SecretVersion version2 = SecretVersion.of(1, 250L, "name1", "desc", "checksum2", NOWPLUS, "user", NOWPLUS, "user", emptyMap, null, 1136214245);
    when(secretDAO.getSecretVersionsByName("name1", 0, 10)).thenReturn(Optional.of(ImmutableList.of(version2, version1)));
    when(secretDAO.getSecretVersionsByName("name1", 1, 5)).thenReturn(Optional.of(ImmutableList.of(version1)));
    when(secretDAO.getSecretVersionsByName("name1", 2, 10)).thenReturn(Optional.of(ImmutableList.of()));
    List<SanitizedSecret> response = resource.secretVersions(user, "name1", 0, 10);
    assertThat(response).containsExactly(secret2, secret1);
    response = resource.secretVersions(user, "name1", 1, 5);
    assertThat(response).containsExactly(secret1);
    response = resource.secretVersions(user, "name1", 2, 10);
    assertThat(response).isEmpty();
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) SecretVersion(keywhiz.api.model.SecretVersion) Test(org.junit.Test)

Aggregations

SecretVersion (keywhiz.api.model.SecretVersion)3 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 SanitizedSecret (keywhiz.api.model.SanitizedSecret)1 SecretSeries (keywhiz.api.model.SecretSeries)1