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

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

Introduction

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

Prototype

@Nullable
<T> VaultResponseSupport<T> read(String path, Class<T> responseType);

Source Link

Document

Read from a secret backend.

Usage

From source file:example.pki.CertificateUtil.java

/**
 * Find a valid, possibly cached, {@link CertificateBundle}.
 *
 * @param vaultProperties// w ww.j a v  a  2s .c om
 * @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;
}