use of keywhiz.api.model.SecretSeries in project keywhiz by square.
the class SecretDAO method getSecrets.
/**
* @param expireMaxTime the maximum expiration date for secrets to return (exclusive)
* @param group the group secrets returned must be assigned to
* @param expireMinTime the minimum expiration date for secrets to return (inclusive)
* @param minName the minimum name (alphabetically) that will be returned for secrets
* expiring on expireMinTime (inclusive)
* @param limit the maximum number of secrets to return
* which to start the list of returned secrets
* @return list of secrets. can limit/sort by expiry, and for group if given
*/
public ImmutableList<SecretSeriesAndContent> getSecrets(@Nullable Long expireMaxTime, @Nullable Group group, @Nullable Long expireMinTime, @Nullable String minName, @Nullable Integer limit) {
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, expireMinTime, minName, limit)) {
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 SecretDAO method getSecretsByName.
/**
* @param names of secrets series to look up secrets by.
* @return Secrets matching input parameters.
*/
public List<SecretSeriesAndContent> getSecretsByName(List<String> names) {
checkArgument(!names.isEmpty());
SecretContentDAO secretContentDAO = secretContentDAOFactory.using(dslContext.configuration());
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration());
List<SecretSeries> multipleSeries = secretSeriesDAO.getMultipleSecretSeriesByName(names);
List<SecretSeriesAndContent> ret = new ArrayList<SecretSeriesAndContent>();
for (SecretSeries series : multipleSeries) {
if (series.currentVersion().isPresent()) {
long secretContentId = series.currentVersion().get();
Optional<SecretContent> secretContent = secretContentDAO.getSecretContentById(secretContentId);
if (secretContent.isPresent()) {
ret.add(SecretSeriesAndContent.of(series, secretContent.get()));
} else {
throw new NotFoundException("Secret not found.");
}
}
}
return ret;
}
use of keywhiz.api.model.SecretSeries 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<SanitizedSecret>> 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<SanitizedSecret> b = new ImmutableList.Builder<>();
b.addAll(contents.get().stream().map(c -> SanitizedSecret.fromSecretSeriesAndContent(SecretSeriesAndContent.of(s, c))).collect(toList()));
return Optional.of(b.build());
}
}
return Optional.empty();
}
use of keywhiz.api.model.SecretSeries in project keywhiz by square.
the class SecretDAO method setCurrentSecretVersionByName.
/**
* @param name of secret series for which to reset secret version
* @param versionId The identifier for the desired current version
* @param updater the user to be linked to this update
* @throws NotFoundException if secret not found
*/
public void setCurrentSecretVersionByName(String name, long versionId, String updater) {
checkArgument(!name.isEmpty());
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration());
SecretSeries series = secretSeriesDAO.getSecretSeriesByName(name).orElseThrow(NotFoundException::new);
secretSeriesDAO.setCurrentVersion(series.id(), versionId, updater, OffsetDateTime.now().toEpochSecond());
}
use of keywhiz.api.model.SecretSeries in project keywhiz by square.
the class AclDAO method getSanitizedSecretsFor.
public ImmutableSet<SanitizedSecret> getSanitizedSecretsFor(Group group) {
checkNotNull(group);
ImmutableSet.Builder<SanitizedSecret> set = ImmutableSet.builder();
return dslContext.transactionResult(configuration -> {
SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
for (SecretSeries series : getSecretSeriesFor(configuration, group)) {
SecretContent content = secretContentDAO.getSecretContentById(series.currentVersion().get()).get();
SecretSeriesAndContent seriesAndContent = SecretSeriesAndContent.of(series, content);
set.add(SanitizedSecret.fromSecretSeriesAndContent(seriesAndContent));
}
return set.build();
});
}
Aggregations