in plugins/vault/src/main/java/co/elastic/gradle/vault/VaultExtension.java [200:234]
private Vault getDriver() {
if (getAuthExtension().getAuthMethods().isEmpty()) {
throw new GradleException("No authentication configured to access " + getAddress().get() +
"\nUse an `auth {}` block to configure at least one authentication method");
}
Path cachedTokenExpiration = cacheDir.toPath().resolve("token/expiration");
final Path tokenValue = cacheDir.toPath().resolve("token/value");
Long expiration = 0L;
if (Files.exists(cachedTokenExpiration)) {
try {
expiration = Long.parseLong(Files.readString(cachedTokenExpiration));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
final VaultTokenFile cachedToken = getAuthExtension().internalCachedTokenFile(
tokenValue.toFile()
);
if (cachedToken.isMethodUsable() && isValidLease(expiration)) {
return (new VaultAccessStrategy()).access(this, cachedToken, (token, expireMillis) -> {});
}
logger.lifecycle("Authenticating to vault at " + getAddress().get());
for (VaultAuthenticationExtension.VaultAuthMethod authMethod : getAuthExtension().getAuthMethods()) {
logger.lifecycle(authMethod.getExplanation());
if (authMethod.isMethodUsable()) {
return (new VaultAccessStrategy()).access(this, authMethod, (token, expireMillis) -> {
writeCacheDir(tokenValue, token);
writeCacheDir(cachedTokenExpiration, expireMillis.toString());
});
}
}
throw new GradleException("Could not find a suitable auth strategy");
}