2929import java .net .URISyntaxException ;
3030import java .net .URL ;
3131import java .util .ArrayList ;
32+ import java .util .Arrays ;
3233import java .util .List ;
3334import java .util .Properties ;
3435import java .util .concurrent .Callable ;
@@ -157,13 +158,7 @@ protected String buildCommandLine(String[] command) {
157158 boolean obscureParam = false ;
158159 for (int i = 0 ; i < command .length ; i ++) {
159160 String cmd = command [i ];
160- if (StringUtils .isNotEmpty (cmd ) && cmd .startsWith ("vi://" )) {
161- String [] tokens = cmd .split ("@" );
162- if (tokens .length >= 2 ) {
163- builder .append ("vi://" ).append ("******@" ).append (tokens [1 ]).append (" " );
164- } else {
165- builder .append ("vi://" ).append ("******" ).append (" " );
166- }
161+ if (sanitizeViCmdParameter (cmd , builder ) || sanitizeRbdFileFormatCmdParameter (cmd , builder )) {
167162 continue ;
168163 }
169164 if (obscureParam ) {
@@ -181,6 +176,41 @@ protected String buildCommandLine(String[] command) {
181176 return builder .toString ();
182177 }
183178
179+ private boolean sanitizeViCmdParameter (String cmd , StringBuilder builder ) {
180+ if (StringUtils .isEmpty (cmd ) || !cmd .startsWith ("vi://" )) {
181+ return false ;
182+ }
183+
184+ String [] tokens = cmd .split ("@" );
185+ if (tokens .length >= 2 ) {
186+ builder .append ("vi://" ).append ("******@" ).append (tokens [1 ]).append (" " );
187+ } else {
188+ builder .append ("vi://" ).append ("******" ).append (" " );
189+ }
190+ return true ;
191+ }
192+
193+ private boolean sanitizeRbdFileFormatCmdParameter (String cmd , StringBuilder builder ) {
194+ if (StringUtils .isEmpty (cmd ) || !cmd .startsWith ("rbd:" ) || !cmd .contains ("key=" )) {
195+ return false ;
196+ }
197+
198+ String [] tokens = cmd .split ("key=" );
199+ if (tokens .length != 2 ) {
200+ return false ;
201+ }
202+
203+ String tokenWithKey = tokens [1 ];
204+ String [] options = tokenWithKey .split (":" );
205+ if (options .length > 1 ) {
206+ String optionsAfterKey = String .join (":" , Arrays .copyOfRange (options , 1 , options .length ));
207+ builder .append (tokens [0 ]).append ("key=" ).append ("******" ).append (":" ).append (optionsAfterKey ).append (" " );
208+ } else {
209+ builder .append (tokens [0 ]).append ("key=" ).append ("******" ).append (" " );
210+ }
211+ return true ;
212+ }
213+
184214 public long getTimeout () {
185215 return _timeout ;
186216 }
0 commit comments