11package io .github .jopenlibs .vault .response ;
22
33import io .github .jopenlibs .vault .api .Logical ;
4+ import io .github .jopenlibs .vault .api .Logical .logicalOperations ;
45import io .github .jopenlibs .vault .json .Json ;
56import io .github .jopenlibs .vault .json .JsonArray ;
67import io .github .jopenlibs .vault .json .JsonObject ;
@@ -26,6 +27,7 @@ public class LogicalResponse extends VaultResponse {
2627 private Boolean renewable ;
2728 private Long leaseDuration ;
2829 private final Map <String , String > dataMetadata = new HashMap <>();
30+ private List <String > subkeys ;
2931
3032 /**
3133 * @param restResponse The raw HTTP response from Vault.
@@ -71,6 +73,10 @@ public DataMetadata getDataMetadata() {
7173 return new DataMetadata (dataMetadata );
7274 }
7375
76+ public List <String > getListSubkeys () {
77+ return subkeys ;
78+ }
79+
7480 private void parseMetadataFields () {
7581 try {
7682 final String jsonString = new String (getRestResponse ().getBody (),
@@ -105,10 +111,7 @@ private void parseResponseData(final Logical.logicalOperations operation) {
105111 // For list operations convert the array of keys to a list of values
106112 if (operation .equals (Logical .logicalOperations .listV1 ) || operation .equals (
107113 Logical .logicalOperations .listV2 )) {
108- if (
109- getRestResponse ().getStatus () != 404
110- && data .get ("keys" ) != null
111- ) {
114+ if (getRestResponse ().getStatus () != 404 && data .get ("keys" ) != null ) {
112115
113116 final JsonArray keys = Json .parse (data .get ("keys" )).asArray ();
114117 for (int index = 0 ; index < keys .size (); index ++) {
@@ -117,6 +120,13 @@ private void parseResponseData(final Logical.logicalOperations operation) {
117120 }
118121
119122 }
123+
124+ if (operation .equals (logicalOperations .listSubKeys )) {
125+ if (data .containsKey ("subkeys" )) {
126+ final var keys = Json .parse (data .get ("subkeys" )).asObject ();
127+ this .subkeys = keys .names ();
128+ }
129+ }
120130 } catch (Exception ignored ) {
121131 }
122132 }
0 commit comments