digital.toke.accessor.Data Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vault-java-driver Show documentation
Show all versions of vault-java-driver Show documentation
A java driver for a subset of Hashicorp's Vault HTTP REST API.
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 David R. Smith All Rights Reserved
*/
package digital.toke.accessor;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONObject;
/**
* Use with KVv1 and KVv2 read operations
*
* @author David R. Smith <[email protected]>
*
*/
public class Data extends Accessor {
public Data(Toke resp) {
super(resp);
}
public Map map() {
Map map = new HashMap();
JSONObject top = json();
JSONObject data = top.optJSONObject("data");
if(data == null) {
return map;
}else {
JSONObject inner = data.optJSONObject("data");
if(inner != null) {
data = inner;
}
}
Iterator keys = data.keys();
while(keys.hasNext()) {
String key = keys.next();
map.put(key, data.get(key));
}
return map;
}
/**
* Use on KVv1 and KVv2 reads
*
* @return
*/
public Map metadata() {
Map map = new HashMap();
JSONObject top = json();
JSONObject data = top.optJSONObject("data");
if(data == null) {
return map;
}else {
JSONObject inner = data.optJSONObject("metadata");
if(inner != null) {
data = inner;
}
}
Iterator keys = data.keys();
while(keys.hasNext()) {
String key = keys.next();
map.put(key, data.get(key));
}
return map;
}
}