Writing of complex data
This commit is contained in:
parent
2f312d3937
commit
d7e4e7e5be
@ -494,17 +494,14 @@ public class HTTPVaultConnector implements VaultConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void write(final String key, final Map<String, Object> data) throws VaultConnectorException {
|
||||||
public void write(final String key, final String value) throws VaultConnectorException {
|
|
||||||
if (!isAuthorized())
|
if (!isAuthorized())
|
||||||
throw new AuthorizationRequiredException();
|
throw new AuthorizationRequiredException();
|
||||||
|
|
||||||
if (key == null || key.isEmpty())
|
if (key == null || key.isEmpty())
|
||||||
throw new InvalidRequestException("Secret path must not be empty.");
|
throw new InvalidRequestException("Secret path must not be empty.");
|
||||||
|
|
||||||
Map<String, String> param = new HashMap<>();
|
if (!requestPost(key, data).equals(""))
|
||||||
param.put("value", value);
|
|
||||||
if (!requestPost(key, param).equals(""))
|
|
||||||
throw new InvalidResponseException("Received response where none was expected.");
|
throw new InvalidResponseException("Received response where none was expected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,12 @@
|
|||||||
|
|
||||||
package de.stklcode.jvault.connector;
|
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.InvalidRequestException;
|
||||||
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
||||||
import de.stklcode.jvault.connector.model.*;
|
import de.stklcode.jvault.connector.model.*;
|
||||||
import de.stklcode.jvault.connector.model.response.*;
|
import de.stklcode.jvault.connector.model.response.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vault Connector interface.
|
* Vault Connector interface.
|
||||||
@ -405,15 +403,28 @@ public interface VaultConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write value to Vault.
|
* Write simple value to Vault.
|
||||||
* Prefix "secret/" is automatically added to path.
|
|
||||||
*
|
*
|
||||||
* @param key Secret path
|
* @param key Secret path
|
||||||
* @param value Secret value
|
* @param value Secret value
|
||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
* @since 0.5.0
|
* @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.
|
* Write secret to Vault.
|
||||||
@ -424,9 +435,24 @@ public interface VaultConnector {
|
|||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
*/
|
*/
|
||||||
default void writeSecret(final String key, final String value) throws VaultConnectorException {
|
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())
|
if (key == null || key.isEmpty())
|
||||||
throw new InvalidRequestException("Secret path must not be empty.");
|
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.
|
* Renew lease with given ID.
|
||||||
*
|
*
|
||||||
* @param leaseID the lase ID
|
* @param leaseID the lase ID
|
||||||
* @return Renewed lease
|
* @return Renewed lease
|
||||||
* @throws VaultConnectorException on error
|
* @throws VaultConnectorException on error
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user