Search in sources :

Example 1 with SecretSeries

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

the class SecretDAO method getSecrets.

/** @return list of secrets. can limit/sort by expiry, and for group if given */
public ImmutableList<SecretSeriesAndContent> getSecrets(@Nullable Long expireMaxTime, Group group) {
    return dslContext.transactionResult(configuration -> {
        SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
        SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);
        ImmutableList.Builder<SecretSeriesAndContent> secretsBuilder = ImmutableList.builder();
        for (SecretSeries series : secretSeriesDAO.getSecretSeries(expireMaxTime, group)) {
            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)

Example 2 with SecretSeries

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

the class SecretSeriesDAOTest method assertListContainsSecretsWithIds.

private void assertListContainsSecretsWithIds(List<SecretSeries> secrets, List<Long> ids) {
    Set<Long> foundIds = new HashSet<>();
    for (SecretSeries secret : secrets) {
        if (ids.contains(secret.id())) {
            foundIds.add(secret.id());
        }
    }
    assertThat(foundIds).as("List should contain secrets with IDs %s; found IDs %s in secret list %s", ids, foundIds, secrets).containsExactlyInAnyOrderElementsOf(ids);
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) HashSet(java.util.HashSet)

Example 3 with SecretSeries

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

the class SecretSeriesDAOTest method getMultipleSecretSeriesByNameReturnsOne.

@Test
public void getMultipleSecretSeriesByNameReturnsOne() {
    int before = tableSize();
    long now = OffsetDateTime.now().toEpochSecond();
    ApiDate nowDate = new ApiDate(now);
    long id = secretSeriesDAO.createSecretSeries("newSecretSeries", null, "creator", "desc", null, ImmutableMap.of("foo", "bar"), now);
    long contentId = secretContentDAO.createSecretContent(id, "blah", "checksum", "creator", null, 0, now);
    secretSeriesDAO.setCurrentVersion(id, contentId, "creator", now);
    List<SecretSeries> expected = List.of(SecretSeries.of(id, "newSecretSeries", null, "desc", nowDate, "creator", nowDate, "creator", null, ImmutableMap.of("foo", "bar"), contentId));
    assertThat(tableSize()).isEqualTo(before + 1);
    List<SecretSeries> actual = secretSeriesDAO.getMultipleSecretSeriesByName(List.of("newSecretSeries"));
    assertThat(actual).isEqualTo(expected);
}
Also used : ApiDate(keywhiz.api.ApiDate) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 4 with SecretSeries

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

the class SecretSeriesDAOTest method assertListDoesNotContainSecretsWithIds.

private void assertListDoesNotContainSecretsWithIds(List<SecretSeries> secrets, List<Long> ids) {
    Set<Long> foundIds = new HashSet<>();
    for (SecretSeries secret : secrets) {
        if (ids.contains(secret.id())) {
            foundIds.add(secret.id());
        }
    }
    assertThat(foundIds).as("List should NOT contain secrets with IDs %s; found IDs %s in secret list %s", ids, foundIds, secrets).isEmpty();
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) HashSet(java.util.HashSet)

Example 5 with SecretSeries

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

the class SecretSeriesMapperTest method mapsRecordWithExistingOwner.

@Test
public void mapsRecordWithExistingOwner() {
    String ownerName = randomName();
    Long ownerId = createGroup(ownerName);
    SecretsRecord record = minimalRecord();
    record.setOwner(ownerId);
    SecretSeries series = mapper.map(record);
    assertEquals(ownerName, series.owner());
}
Also used : SecretsRecord(keywhiz.jooq.tables.records.SecretsRecord) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Aggregations

SecretSeries (keywhiz.api.model.SecretSeries)30 Test (org.junit.Test)12 SecretContent (keywhiz.api.model.SecretContent)9 SecretSeriesAndContent (keywhiz.api.model.SecretSeriesAndContent)8 ApiDate (keywhiz.api.ApiDate)6 ImmutableList (com.google.common.collect.ImmutableList)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 NotFoundException (javax.ws.rs.NotFoundException)3 SecretsRecord (keywhiz.jooq.tables.records.SecretsRecord)3 HashSet (java.util.HashSet)2 Group (keywhiz.api.model.Group)2 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 Secret (keywhiz.api.model.Secret)2 Event (keywhiz.log.Event)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 BadRequestException (javax.ws.rs.BadRequestException)1 ContentEncodingException (keywhiz.service.crypto.ContentEncodingException)1 Record (org.jooq.Record)1 DataAccessException (org.jooq.exception.DataAccessException)1