Example usage for org.springframework.vault.core VaultOperations delete

List of usage examples for org.springframework.vault.core VaultOperations delete

Introduction

In this page you can find the example usage for org.springframework.vault.core VaultOperations delete.

Prototype

void delete(String path);

Source Link

Document

Delete a path.

Usage

From source file:example.pki.CertificateUtil.java

/**
 * Request SSL Certificate from Vault or retrieve cached certificate.
 * <p>/*from  ww  w .ja  v a  2s  .com*/
 * 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();
}