List of usage examples for org.springframework.vault.core VaultOperations opsForSys
VaultSysOperations opsForSys();
From source file:example.pki.CertificateUtil.java
/** * Find a valid, possibly cached, {@link CertificateBundle}. * * @param vaultProperties//from w w w. j a v a 2s . co m * @param vaultOperations * @param pkiProperties * @return the {@link CertificateBundle} or {@literal null}. */ public static CertificateBundle findValidCertificate(VaultProperties vaultProperties, VaultOperations vaultOperations, VaultPkiProperties pkiProperties) { if (!pkiProperties.isReuseValidCertificate()) { return requestCertificate(vaultOperations, pkiProperties).getData(); } String cacheKey = createCacheKey(vaultProperties, pkiProperties); VaultResponseSupport<CachedCertificateBundle> readResponse = vaultOperations.read(cacheKey, CachedCertificateBundle.class); VaultHealth health = vaultOperations.opsForSys().health(); if (isValid(health, readResponse)) { logger.info("Found valid SSL certificate in Vault for: {}", pkiProperties.getCommonName()); return getCertificateBundle(readResponse); } return null; }
From source file:example.pki.CertificateUtil.java
/** * Request SSL Certificate from Vault or retrieve cached certificate. * <p>/*from w ww . j av a 2 s . c o m*/ * If {@link VaultPkiProperties#isReuseValidCertificate()} is enabled this method * attempts to read a cached Certificate from Vault at {@code secret/$ * spring.application.name}/cert/${spring.cloud.vault.pki.commonName}}. Valid * certificates will be reused until they expire. A new certificate is requested and * cached if no valid certificate is found. * * @param vaultProperties * @param vaultOperations * @param pkiProperties * @return the {@link CertificateBundle}. */ public static CertificateBundle getOrRequestCertificate(VaultProperties vaultProperties, VaultOperations vaultOperations, VaultPkiProperties pkiProperties) { CertificateBundle validCertificate = findValidCertificate(vaultProperties, vaultOperations, pkiProperties); if (!pkiProperties.isReuseValidCertificate()) { return validCertificate; } String cacheKey = createCacheKey(vaultProperties, pkiProperties); vaultOperations.delete(cacheKey); VaultCertificateResponse certificateResponse = requestCertificate(vaultOperations, pkiProperties); VaultHealth health = vaultOperations.opsForSys().health(); storeCertificate(cacheKey, vaultOperations, health, certificateResponse); return certificateResponse.getData(); }