@@ -28,16 +28,25 @@ private static List<String> getPathSegments(final String path) {
28
28
* path to be converted for use with a Version 2 secret engine.
29
29
*
30
30
* @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)
31
33
* @param qualifier The String to add to the path, based on the operation.
32
34
* @return The final path with the needed qualifier.
33
35
*/
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 ));
41
50
}
42
51
return adjustedPath .toString ();
43
52
}
@@ -51,11 +60,11 @@ public static String addQualifierToPath(final List<String> segments, final Strin
51
60
* @param operation The operation being performed, e.g. readV2 or writeV1.
52
61
* @return The Vault path mutated based on the operation.
53
62
*/
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 ) {
55
64
final List <String > pathSegments = getPathSegments (path );
56
65
if (operation .equals (Logical .logicalOperations .readV2 ) || operation .equals (Logical .logicalOperations .writeV2 )) {
57
66
// Version 2
58
- final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , "data" ));
67
+ final StringBuilder adjustedPath = new StringBuilder (addQualifierToPath (pathSegments , prefixPathLength , "data" ));
59
68
if (path .endsWith ("/" )) {
60
69
adjustedPath .append ("/" );
61
70
}
@@ -75,12 +84,12 @@ public static String adjustPathForReadOrWrite(final String path, final Logical.l
75
84
* @param operation The operation being performed, e.g. readV2 or writeV1.
76
85
* @return The Vault path mutated based on the operation.
77
86
*/
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 ) {
79
88
final List <String > pathSegments = getPathSegments (path );
80
89
final StringBuilder adjustedPath = new StringBuilder ();
81
90
if (operation .equals (Logical .logicalOperations .listV2 )) {
82
91
// Version 2
83
- adjustedPath .append (addQualifierToPath (pathSegments , "metadata" ));
92
+ adjustedPath .append (addQualifierToPath (pathSegments , prefixPathDepth , "metadata" ));
84
93
if (path .endsWith ("/" )) {
85
94
adjustedPath .append ("/" );
86
95
}
@@ -102,10 +111,10 @@ public static String adjustPathForList(final String path, final Logical.logicalO
102
111
*
103
112
* @return The modified path
104
113
*/
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 ) {
106
115
final List <String > pathSegments = getPathSegments (path );
107
116
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" ));
109
118
if (path .endsWith ("/" )) {
110
119
adjustedPath .append ("/" );
111
120
}
@@ -122,9 +131,9 @@ public static String adjustPathForDelete(final String path, final Logical.logica
122
131
*
123
132
* @return The modified path
124
133
*/
125
- public static String adjustPathForVersionDelete (final String path ) {
134
+ public static String adjustPathForVersionDelete (final String path , final int prefixPathDepth ) {
126
135
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" ));
128
137
if (path .endsWith ("/" )) {
129
138
adjustedPath .append ("/" );
130
139
}
@@ -137,9 +146,9 @@ public static String adjustPathForVersionDelete(final String path) {
137
146
* @param path The Vault path to check or mutate, based on the operation.
138
147
* @return The path mutated depending on the operation.
139
148
*/
140
- public static String adjustPathForVersionUnDelete (final String path ) {
149
+ public static String adjustPathForVersionUnDelete (final String path , final int prefixPathDepth ) {
141
150
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" ));
143
152
if (path .endsWith ("/" )) {
144
153
adjustedPath .append ("/" );
145
154
}
@@ -152,9 +161,9 @@ public static String adjustPathForVersionUnDelete(final String path) {
152
161
* @param path The Vault path to check or mutate, based on the operation.
153
162
* @return The path mutated depending on the operation.
154
163
*/
155
- public static String adjustPathForVersionDestroy (final String path ) {
164
+ public static String adjustPathForVersionDestroy (final String path , final int prefixPathDepth ) {
156
165
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" ));
158
167
if (path .endsWith ("/" )) {
159
168
adjustedPath .append ("/" );
160
169
}
0 commit comments