@@ -202,14 +202,51 @@ public LogicalResponse read(final String path, Boolean shouldRetry, final Intege
202202 public LogicalResponse write (final String path , final Map <String , Object > nameValuePairs )
203203 throws VaultException {
204204 if (engineVersionForSecretPath (path ).equals (2 )) {
205- return write (path , nameValuePairs , logicalOperations .writeV2 );
205+ return write (path , nameValuePairs , logicalOperations .writeV2 , null );
206206 } else {
207- return write (path , nameValuePairs , logicalOperations .writeV1 );
207+ return write (path , nameValuePairs , logicalOperations .writeV1 , null );
208+ }
209+ }
210+
211+ /**
212+ * <p>Basic operation to store secrets. Multiple name value pairs can be stored under the same
213+ * secret key. E.g.:</p>
214+ *
215+ * <blockquote>
216+ * <pre>{@code
217+ * final Map<String, String> nameValuePairs = new HashMap<String, Object>();
218+ * nameValuePairs.put("value", "foo");
219+ * nameValuePairs.put("other_value", "bar");
220+ *
221+ * final LogicalResponse response = vault.logical().write("secret/hello", nameValuePairs);
222+ * }</pre>
223+ * </blockquote>
224+ *
225+ * <p>The values in these name-value pairs may be booleans, numerics, strings, or nested JSON
226+ * objects. However, be aware that this method does not recursively parse any nested
227+ * structures. If you wish to write arbitrary JSON objects to Vault... then you should parse
228+ * them to JSON outside of this method, and pass them here as JSON strings.</p>
229+ *
230+ * @param path The Vault key value to which to write (e.g. <code>secret/hello</code>)
231+ * @param nameValuePairs Secret name and value pairs to store under this Vault key (can be
232+ * @param wrapTTL Time (in seconds) which secret is wrapped
233+ * <code>null</code> for writing to keys that do not need or expect any fields to be specified)
234+ * @return The response information received from Vault
235+ * @throws VaultException If any errors occurs with the REST request, and the maximum number of
236+ * retries is exceeded.
237+ */
238+ public LogicalResponse write (final String path , final Map <String , Object > nameValuePairs ,
239+ final Integer wrapTTL )
240+ throws VaultException {
241+ if (engineVersionForSecretPath (path ).equals (2 )) {
242+ return write (path , nameValuePairs , logicalOperations .writeV2 , wrapTTL );
243+ } else {
244+ return write (path , nameValuePairs , logicalOperations .writeV1 , wrapTTL );
208245 }
209246 }
210247
211248 private LogicalResponse write (final String path , final Map <String , Object > nameValuePairs ,
212- final logicalOperations operation ) throws VaultException {
249+ final logicalOperations operation , final Integer wrapTTL ) throws VaultException {
213250
214251 return retry (attempt -> {
215252 JsonObject requestJson = Json .object ();
@@ -246,6 +283,7 @@ private LogicalResponse write(final String path, final Map<String, Object> nameV
246283 .header ("X-Vault-Token" , config .getToken ())
247284 .header ("X-Vault-Namespace" , this .nameSpace )
248285 .header ("X-Vault-Request" , "true" )
286+ .header ("X-Vault-Wrap-TTL" , wrapTTL != null ? wrapTTL .toString () : null )
249287 .connectTimeoutSeconds (config .getOpenTimeout ())
250288 .readTimeoutSeconds (config .getReadTimeout ())
251289 .sslVerification (config .getSslConfig ().isVerify ())
0 commit comments