@@ -308,6 +308,8 @@ def execute(
308308 command : str ,
309309 verbose : bool = False ,
310310 timeout : typing .Union [int , float , None ] = constants .DEFAULT_TIMEOUT ,
311+ * ,
312+ log_mask_re : typing .Optional [str ] = None ,
311313 ** kwargs : typing .Any ,
312314 ) -> exec_result .ExecResult :
313315 """Execute command and wait for return code.
@@ -318,6 +320,9 @@ def execute(
318320 :type verbose: bool
319321 :param timeout: Timeout for command execution.
320322 :type timeout: typing.Union[int, float, None]
323+ :param log_mask_re: regex lookup rule to mask command for logger.
324+ all MATCHED groups will be replaced by '<*masked*>'
325+ :type log_mask_re: typing.Optional[str]
321326 :param kwargs: additional parameters for call.
322327 :type kwargs: typing.Any
323328 :return: Execution result
@@ -327,10 +332,17 @@ def execute(
327332 .. versionchanged:: 1.2.0 default timeout 1 hour
328333 .. versionchanged:: 2.1.0 Allow parallel calls
329334 """
330- async_result : ExecuteAsyncResult = self .execute_async (command , verbose = verbose , ** kwargs )
335+ async_result : ExecuteAsyncResult = self .execute_async (
336+ command , verbose = verbose , log_mask_re = log_mask_re , ** kwargs
337+ )
331338
332339 result : exec_result .ExecResult = self ._exec_command (
333- command = command , async_result = async_result , timeout = timeout , verbose = verbose , ** kwargs
340+ command = command ,
341+ async_result = async_result ,
342+ timeout = timeout ,
343+ verbose = verbose ,
344+ log_mask_re = log_mask_re ,
345+ ** kwargs ,
334346 )
335347 message = f"Command { result .cmd !r} exit code: { result .exit_code !s} "
336348 self .logger .log (level = logging .INFO if verbose else logging .DEBUG , msg = message ) # type: ignore
@@ -341,6 +353,8 @@ def __call__(
341353 command : str ,
342354 verbose : bool = False ,
343355 timeout : typing .Union [int , float , None ] = constants .DEFAULT_TIMEOUT ,
356+ * ,
357+ log_mask_re : typing .Optional [str ] = None ,
344358 ** kwargs : typing .Any ,
345359 ) -> exec_result .ExecResult :
346360 """Execute command and wait for return code.
@@ -351,6 +365,9 @@ def __call__(
351365 :type verbose: bool
352366 :param timeout: Timeout for command execution.
353367 :type timeout: typing.Union[int, float, None]
368+ :param log_mask_re: regex lookup rule to mask command for logger.
369+ all MATCHED groups will be replaced by '<*masked*>'
370+ :type log_mask_re: typing.Optional[str]
354371 :param kwargs: additional parameters for call.
355372 :type kwargs: typing.Any
356373 :return: Execution result
@@ -359,7 +376,7 @@ def __call__(
359376
360377 .. versionadded:: 3.3.0
361378 """
362- return self .execute (command = command , verbose = verbose , timeout = timeout , ** kwargs )
379+ return self .execute (command = command , verbose = verbose , timeout = timeout , log_mask_re = log_mask_re , ** kwargs )
363380
364381 def check_call (
365382 self ,
@@ -370,6 +387,7 @@ def check_call(
370387 expected : typing .Iterable [typing .Union [int , proc_enums .ExitCodes ]] = (proc_enums .EXPECTED ,),
371388 raise_on_err : bool = True ,
372389 * ,
390+ log_mask_re : typing .Optional [str ] = None ,
373391 exception_class : "typing.Type[exceptions.CalledProcessError]" = exceptions .CalledProcessError ,
374392 ** kwargs : typing .Any ,
375393 ) -> exec_result .ExecResult :
@@ -387,6 +405,9 @@ def check_call(
387405 :type expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]]
388406 :param raise_on_err: Raise exception on unexpected return code
389407 :type raise_on_err: bool
408+ :param log_mask_re: regex lookup rule to mask command for logger.
409+ all MATCHED groups will be replaced by '<*masked*>'
410+ :type log_mask_re: typing.Optional[str]
390411 :param exception_class: Exception class for errors. Subclass of CalledProcessError is mandatory.
391412 :type exception_class: typing.Type[exceptions.CalledProcessError]
392413 :param kwargs: additional parameters for call.
@@ -403,7 +424,7 @@ def check_call(
403424 expected_codes : typing .Tuple [typing .Union [int , proc_enums .ExitCodes ], ...] = proc_enums .exit_codes_to_enums (
404425 expected
405426 )
406- result : exec_result .ExecResult = self .execute (command , verbose , timeout , ** kwargs )
427+ result : exec_result .ExecResult = self .execute (command , verbose , timeout , log_mask_re = log_mask_re , ** kwargs )
407428 append : str = error_info + "\n " if error_info else ""
408429 if result .exit_code not in expected_codes :
409430 message = (
@@ -423,6 +444,7 @@ def check_stderr(
423444 error_info : typing .Optional [str ] = None ,
424445 raise_on_err : bool = True ,
425446 * ,
447+ log_mask_re : typing .Optional [str ] = None ,
426448 expected : typing .Iterable [typing .Union [int , proc_enums .ExitCodes ]] = (proc_enums .EXPECTED ,),
427449 exception_class : "typing.Type[exceptions.CalledProcessError]" = exceptions .CalledProcessError ,
428450 ** kwargs : typing .Any ,
@@ -439,6 +461,9 @@ def check_stderr(
439461 :type error_info: typing.Optional[str]
440462 :param raise_on_err: Raise exception on unexpected return code
441463 :type raise_on_err: bool
464+ :param log_mask_re: regex lookup rule to mask command for logger.
465+ all MATCHED groups will be replaced by '<*masked*>'
466+ :type log_mask_re: typing.Optional[str]
442467 :param expected: expected return codes (0 by default)
443468 :type expected: typing.Iterable[typing.Union[int, proc_enums.ExitCodes]]
444469 :param exception_class: Exception class for errors. Subclass of CalledProcessError is mandatory.
@@ -462,6 +487,7 @@ def check_stderr(
462487 raise_on_err = raise_on_err ,
463488 expected = expected ,
464489 exception_class = exception_class ,
490+ log_mask_re = log_mask_re ,
465491 ** kwargs ,
466492 )
467493 append : str = error_info + "\n " if error_info else ""
0 commit comments