forked from jopenlibs/vault-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose CAS option on secret write and version on secret read (K/V 2) (j…
- Loading branch information
1 parent
38fad23
commit 871375f
Showing
7 changed files
with
306 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/io/github/jopenlibs/vault/api/WriteOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.github.jopenlibs.vault.api; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Additional options that may be set as part of K/V V2 write operation. | ||
* Construct instances of this class using a builder pattern, calling setter methods for each | ||
* value and then terminating with a call to build(). | ||
*/ | ||
public class WriteOptions { | ||
|
||
public static final String CHECK_AND_SET_KEY = "cas"; | ||
|
||
private final Map<String, Object> options = new HashMap<>(); | ||
|
||
/** | ||
* Enable check and set (CAS) option | ||
* @param version current version of the secret | ||
* @return updated options ready for additional builder-pattern calls or else finalization | ||
* with the build() method | ||
*/ | ||
public WriteOptions checkAndSet(Long version) { | ||
return setOption(CHECK_AND_SET_KEY, version); | ||
} | ||
|
||
/** | ||
* Set an option to a value | ||
* @param name option name | ||
* @param value option value | ||
* @return updated options ready for additional builder-pattern calls or else finalization | ||
* with the build() method | ||
*/ | ||
public WriteOptions setOption(String name, Object value) { | ||
options.put(name, value); | ||
return this; | ||
} | ||
|
||
/** | ||
* Finalize the options (terminating method in the builder pattern) | ||
* @return this object, with all available config options parsed and loaded | ||
*/ | ||
public WriteOptions build() { | ||
return this; | ||
} | ||
|
||
/** | ||
* @return options as a Map | ||
*/ | ||
public Map<String, Object> getOptionsMap() { | ||
return Collections.unmodifiableMap(options); | ||
} | ||
|
||
/** | ||
* @return true if no options are set, false otherwise | ||
*/ | ||
public boolean isEmpty() { | ||
return options.isEmpty(); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/github/jopenlibs/vault/response/DataMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.jopenlibs.vault.response; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* Container for metadata that can be returned with a logical operation response | ||
*/ | ||
public class DataMetadata { | ||
|
||
public static final String VERSION_KEY = "version"; | ||
|
||
private final Map<String, String> metadataMap; | ||
|
||
public DataMetadata(Map<String, String> metadataMap) { | ||
this.metadataMap = metadataMap; | ||
} | ||
|
||
public Long getVersion() { | ||
final String versionString = metadataMap.get(VERSION_KEY); | ||
return (null != versionString) ? Long.valueOf(versionString) : null; | ||
} | ||
|
||
public Map<String, String> getMetadataMap() { | ||
return Collections.unmodifiableMap(metadataMap); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return metadataMap.isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.