Writing of complex data

This commit is contained in:
Stefan Kalscheuer 2017-01-09 12:41:49 +01:00
parent 2f312d3937
commit d7e4e7e5be
2 changed files with 36 additions and 13 deletions

View File

@ -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<String, Object> data) throws VaultConnectorException {
if (!isAuthorized())
throw new AuthorizationRequiredException();
if (key == null || key.isEmpty())
throw new InvalidRequestException("Secret path must not be empty.");
Map<String, String> 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.");
}

View File

@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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);
}
/**