@@ -28,16 +28,25 @@ private static List<String> getPathSegments(final String path) {
2828 * path to be converted for use with a Version 2 secret engine.
2929 *
3030 * @param segments The Vault path split into segments.
31+ * @param prefixPathDepth number of path elements in the prefix part of
32+ * the path (the part before the qualifier)
3133 * @param qualifier The String to add to the path, based on the operation.
3234 * @return The final path with the needed qualifier.
3335 */
34- public static String addQualifierToPath (final List <String > segments , final String qualifier ) {
35- final StringBuilder adjustedPath = new StringBuilder (segments .get (0 )).append ('/' ).append (qualifier ).append ('/' );
36- for (int index = 1 ; index < segments .size (); index ++) {
37- adjustedPath .append (segments .get (index ));
38- if (index + 1 < segments .size ()) {
39- adjustedPath .append ('/' );
40- }
36+ public static String addQualifierToPath (final List <String > segments , final int prefixPathDepth , final String qualifier ) {
37+ final StringBuilder adjustedPath = new StringBuilder ();
38+ int index ;
39+
40+ for (index =0 ;index < prefixPathDepth ;index ++) {
41+ adjustedPath .append (segments .get (index ))
42+ .append ('/' );
43+ }
44+
45+ adjustedPath .append (qualifier );
46+
47+ for (;index < segments .size (); index ++) {
48+ adjustedPath .append ('/' )
49+ .append (segments .get (index ));
4150 }
4251 return adjustedPath .toString ();
4352 }
@@ -51,11 +60,11 @@ public static String addQualifierToPath(final List<String> segments, final Strin
5160 * @param operation The operation being performed, e.g. readV2 or writeV1.
5261 * @return The Vault path mutated based on the operation.
5362 */
54- public static String adjustPathForReadOrWrite (final String path , final Logical .logicalOperations operation ) {
63+ public static String adjustPathForReadOrWrite (final String path , final int prefixPathLength , final Logical .logicalOperations operation ) {
5564 final List <String > pathSegments = getPathSegments (path );
5665 if (operation .equals (Logical .logicalOperations .readV2 ) || operation .equals (Logical .logicalOperations .writeV2 )) {
5766 // Version 2
58- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "data" ));
67+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathLength , "data" ));
5968 if (path .endsWith ("/" )) {
6069 adjustedPath .append ("/" );
6170 }
@@ -75,12 +84,12 @@ public static String adjustPathForReadOrWrite(final String path, final Logical.l
7584 * @param operation The operation being performed, e.g. readV2 or writeV1.
7685 * @return The Vault path mutated based on the operation.
7786 */
78- public static String adjustPathForList (final String path , final Logical .logicalOperations operation ) {
87+ public static String adjustPathForList (final String path , int prefixPathDepth , final Logical .logicalOperations operation ) {
7988 final List <String > pathSegments = getPathSegments (path );
8089 final StringBuilder adjustedPath = new StringBuilder ();
8190 if (operation .equals (Logical .logicalOperations .listV2 )) {
8291 // Version 2
83- adjustedPath .append (addQualifierToPath (pathSegments , "metadata" ));
92+ adjustedPath .append (addQualifierToPath (pathSegments , prefixPathDepth , "metadata" ));
8493 if (path .endsWith ("/" )) {
8594 adjustedPath .append ("/" );
8695 }
@@ -102,10 +111,10 @@ public static String adjustPathForList(final String path, final Logical.logicalO
102111 *
103112 * @return The modified path
104113 */
105- public static String adjustPathForDelete (final String path , final Logical .logicalOperations operation ) {
114+ public static String adjustPathForDelete (final String path , final int prefixPathDepth , final Logical .logicalOperations operation ) {
106115 final List <String > pathSegments = getPathSegments (path );
107116 if (operation .equals (Logical .logicalOperations .deleteV2 )) {
108- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "metadata" ));
117+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathDepth , "metadata" ));
109118 if (path .endsWith ("/" )) {
110119 adjustedPath .append ("/" );
111120 }
@@ -122,9 +131,9 @@ public static String adjustPathForDelete(final String path, final Logical.logica
122131 *
123132 * @return The modified path
124133 */
125- public static String adjustPathForVersionDelete (final String path ) {
134+ public static String adjustPathForVersionDelete (final String path , final int prefixPathDepth ) {
126135 final List <String > pathSegments = getPathSegments (path );
127- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "delete" ));
136+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathDepth , "delete" ));
128137 if (path .endsWith ("/" )) {
129138 adjustedPath .append ("/" );
130139 }
@@ -137,9 +146,9 @@ public static String adjustPathForVersionDelete(final String path) {
137146 * @param path The Vault path to check or mutate, based on the operation.
138147 * @return The path mutated depending on the operation.
139148 */
140- public static String adjustPathForVersionUnDelete (final String path ) {
149+ public static String adjustPathForVersionUnDelete (final String path , final int prefixPathDepth ) {
141150 final List <String > pathSegments = getPathSegments (path );
142- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "undelete" ));
151+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathDepth , "undelete" ));
143152 if (path .endsWith ("/" )) {
144153 adjustedPath .append ("/" );
145154 }
@@ -152,9 +161,9 @@ public static String adjustPathForVersionUnDelete(final String path) {
152161 * @param path The Vault path to check or mutate, based on the operation.
153162 * @return The path mutated depending on the operation.
154163 */
155- public static String adjustPathForVersionDestroy (final String path ) {
164+ public static String adjustPathForVersionDestroy (final String path , final int prefixPathDepth ) {
156165 final List <String > pathSegments = getPathSegments (path );
157- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "destroy" ));
166+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathDepth , "destroy" ));
158167 if (path .endsWith ("/" )) {
159168 adjustedPath .append ("/" );
160169 }
0 commit comments