io.quarkus.vault.runtime.config.VaultCacheEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-vault Show documentation
Show all versions of quarkus-vault Show documentation
Store your credentials securely in HashiCorp Vault
package io.quarkus.vault.runtime.config;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import org.jboss.logging.Logger;
public class VaultCacheEntry {
private static final Logger log = Logger.getLogger(VaultCacheEntry.class.getName());
private V value;
private volatile Instant created = Instant.now();
public static V tryReturnLastKnownValue(RuntimeException e, VaultCacheEntry cacheEntry) {
if (e.getCause() instanceof IOException && cacheEntry != null) {
log.debug("unable to fetch secrets from vault; returning last known value", e);
cacheEntry.reset(); // will return values from the cache for the cache-period
return cacheEntry.getValue();
} else {
throw e;
}
}
public VaultCacheEntry(V value) {
this.value = value;
}
public boolean youngerThan(Duration duration) {
return created.plus(duration).isAfter(Instant.now());
}
public V getValue() {
return value;
}
public void reset() {
created = Instant.now();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy