diff --git a/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java b/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java index 4a205fd..0fec43b 100644 --- a/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java +++ b/src/main/java/de/stklcode/jvault/connector/HTTPVaultConnector.java @@ -494,17 +494,14 @@ public class HTTPVaultConnector implements VaultConnector { } } - @Override - public void write(final String key, final String value) throws VaultConnectorException { + public void write(final String key, final Map data) throws VaultConnectorException { if (!isAuthorized()) throw new AuthorizationRequiredException(); if (key == null || key.isEmpty()) throw new InvalidRequestException("Secret path must not be empty."); - Map param = new HashMap<>(); - param.put("value", value); - if (!requestPost(key, param).equals("")) + if (!requestPost(key, data).equals("")) throw new InvalidResponseException("Received response where none was expected."); } diff --git a/src/main/java/de/stklcode/jvault/connector/VaultConnector.java b/src/main/java/de/stklcode/jvault/connector/VaultConnector.java index 554b43e..01551ef 100644 --- a/src/main/java/de/stklcode/jvault/connector/VaultConnector.java +++ b/src/main/java/de/stklcode/jvault/connector/VaultConnector.java @@ -16,14 +16,12 @@ package de.stklcode.jvault.connector; -import de.stklcode.jvault.connector.exception.AuthorizationRequiredException; import de.stklcode.jvault.connector.exception.InvalidRequestException; import de.stklcode.jvault.connector.exception.VaultConnectorException; import de.stklcode.jvault.connector.model.*; import de.stklcode.jvault.connector.model.response.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * Vault Connector interface. @@ -405,15 +403,28 @@ public interface VaultConnector { } /** - * Write value to Vault. - * Prefix "secret/" is automatically added to path. + * Write simple value to Vault. * * @param key Secret path * @param value Secret value * @throws VaultConnectorException on error * @since 0.5.0 */ - void write(final String key, final String value) throws VaultConnectorException; + default void write(final String key, final String value) throws VaultConnectorException { + Map param = new HashMap<>(); + param.put("value", value); + write(key, param); + } + + /** + * Write value to Vault. + * + * @param key Secret path + * @param data Secret content. Value must be be JSON serializable. + * @throws VaultConnectorException on error + * @since 0.5.0 + */ + void write(final String key, final Map data) throws VaultConnectorException; /** * Write secret to Vault. @@ -424,9 +435,24 @@ public interface VaultConnector { * @throws VaultConnectorException on error */ default void writeSecret(final String key, final String value) throws VaultConnectorException { + Map param = new HashMap<>(); + param.put("value", value); + writeSecret(key, param); + } + + /** + * Write secret to Vault. + * Prefix "secret/" is automatically added to path. + * + * @param key Secret path + * @param data Secret content. Value must be be JSON serializable. + * @throws VaultConnectorException on error + * @since 0.5.0 + */ + default void writeSecret(final String key, final Map data) throws VaultConnectorException { if (key == null || key.isEmpty()) throw new InvalidRequestException("Secret path must not be empty."); - write(PATH_SECRET + "/" + key, value); + write(PATH_SECRET + "/" + key, data); } /** @@ -460,7 +486,7 @@ public interface VaultConnector { /** * Renew lease with given ID. * - * @param leaseID the lase ID + * @param leaseID the lase ID * @return Renewed lease * @throws VaultConnectorException on error */