com.github.nagyesta.lowkeyvault.service.certificate.impl.CertificateLifetimeActionPolicy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lowkey-vault-app Show documentation
Show all versions of lowkey-vault-app Show documentation
Assembled application of Lowkey Vault.
package com.github.nagyesta.lowkeyvault.service.certificate.impl;
import com.github.nagyesta.lowkeyvault.service.certificate.CertificateLifetimeActionActivity;
import com.github.nagyesta.lowkeyvault.service.certificate.CertificateLifetimeActionTrigger;
import com.github.nagyesta.lowkeyvault.service.certificate.LifetimeActionPolicy;
import com.github.nagyesta.lowkeyvault.service.certificate.id.CertificateEntityId;
import com.github.nagyesta.lowkeyvault.service.common.impl.BaseLifetimePolicy;
import lombok.NonNull;
import org.springframework.util.Assert;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class CertificateLifetimeActionPolicy extends BaseLifetimePolicy implements LifetimeActionPolicy {
private Map lifetimeActions;
public CertificateLifetimeActionPolicy(
@org.springframework.lang.NonNull final CertificateEntityId certificateEntityId,
@NonNull final Map lifetimeActions) {
super(certificateEntityId);
this.lifetimeActions = Map.copyOf(lifetimeActions);
}
@Override
public Map getLifetimeActions() {
return lifetimeActions;
}
@Override
public void setLifetimeActions(final Map lifetimeActions) {
this.lifetimeActions = Map.copyOf(lifetimeActions);
this.markUpdate();
}
@Override
public boolean isAutoRenew() {
return getLifetimeActions().containsKey(CertificateLifetimeActionActivity.AUTO_RENEW);
}
@Override
public void validate(final int validityMonths) {
lifetimeActions.values().forEach(a -> a.validate(validityMonths));
}
@Override
public List missedRenewalDays(final OffsetDateTime validityStart,
final Function createdToExpiryFunction) {
Assert.isTrue(isAutoRenew(), "Cannot have missed renewals without an \"AutoRenew\" lifetime action.");
final CertificateLifetimeActionTrigger trigger = lifetimeActions.get(CertificateLifetimeActionActivity.AUTO_RENEW);
final Function triggerAfterDaysFunction = s -> trigger
.triggersAfterDays(s, createdToExpiryFunction.apply(s));
final OffsetDateTime startPoint = findTriggerTimeOffset(validityStart, triggerAfterDaysFunction);
return collectMissedTriggerDays(triggerAfterDaysFunction, startPoint);
}
}