org.springframework.vault.core.VaultVersionedKeyValueOperations Java Examples

The following examples show how to use org.springframework.vault.core.VaultVersionedKeyValueOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VaultCommunication.java    From vault-crd with Apache License 2.0 6 votes vote down vote up
private <T> T getVersionedSecret(String path, Optional<Integer> version, Class<T> clazz) throws SecretNotAccessibleException{
    String mountPoint = extractMountPoint(path);
    String extractedKey = extractKey(path);

    VaultVersionedKeyValueOperations versionedKV = vaultTemplate.opsForVersionedKeyValue(mountPoint);
    Versioned<T> versionedResponse;

    try {
        if (version.isPresent()) {
            versionedResponse = versionedKV.get(extractedKey, Version.from(version.get()), clazz);
        } else {
            versionedResponse = versionedKV.get(extractedKey, clazz);
        }

        if (versionedResponse != null) {
            return versionedResponse.getData();
        }

        throw new SecretNotAccessibleException(String.format("The secret %s is not available or in the wrong format.", path));

    } catch (VaultException ex) {
        throw new SecretNotAccessibleException(
                String.format("Couldn't load secret from vault path %s", path), ex);
    }
}
 
Example #2
Source File: KeyValueOperationsDelegate.java    From tessera with Apache License 2.0 4 votes vote down vote up
KeyValueOperationsDelegate(VaultVersionedKeyValueOperations keyValueOperations) {
    this.keyValueOperations = keyValueOperations;
}
 
Example #3
Source File: KeyValueOperationsDelegateFactory.java    From tessera with Apache License 2.0 4 votes vote down vote up
KeyValueOperationsDelegate create(String secretEngineName) {
    VaultVersionedKeyValueOperations keyValueOperations = new VaultVersionedKeyValueTemplate(vaultOperations, secretEngineName);

    return new KeyValueOperationsDelegate(keyValueOperations);
}
 
Example #4
Source File: KeyValueOperationsDelegateTest.java    From tessera with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    this.keyValueOperations = mock(VaultVersionedKeyValueOperations.class);
    this.delegate = new KeyValueOperationsDelegate(keyValueOperations);
}