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();
});
}
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);
}
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);
}
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();
}
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());
}
Aggregations