public String read ( String path , String key , long delay ) { if ( ! secrets . containsKey ( path ) ) { VaultClient vault = new VaultClient ( getConfig ( ) ) ; Secret secret ; try { secret = vault . logical ( ) . read ( path ) ; } catch ( VaultException e ) { LOG . error ( e . toString ( ) , e ) ; throw new VaultRuntimeException ( e . toString ( ) ) ; } // Record the expiration date of this lease String leaseId ; if ( secret . isRenewable ( ) ) { // Only renewable secrets seem to have a leaseId leaseId = secret . getLeaseId ( ) ; } else { // So for non-renewable secrets we'll store the path with an extra / so that we can purge them correctly. leaseId = path + "/" ; } leases . put ( leaseId , System . currentTimeMillis ( ) + ( secret . getLeaseDuration ( ) * 1000 ) ) ; secrets . put ( path , secret ) ; try { Thread . sleep ( delay ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; } } Map < String , Object > data = secrets . get ( path ) . getData ( ) ; String value = getSecretValue ( data , key ) . orElseThrow ( ( ) -> new VaultRuntimeException ( "Value not found for key" ) ) ; LOG . trace ( "CredentialStore '{}' Vault, retrieved value for key '{}'" , csId , key ) ; return value ; }
Reads a secret from the local cache if it hasn t expired and returns the value for the specified key . If the secret isn t cached or has expired it requests it from Vault again .