[Bugfix] Redact api_key in non-default args log (#52523)
Signed-off-by: LuckyStep <67696304+Andy365-365@users.noreply.github.com>
This commit is contained in:
@@ -267,9 +267,23 @@ def jsonify_non_default_args(
|
||||
return {key: _jsonify_arg_value(value) for key, value in non_default_args.items()}
|
||||
|
||||
|
||||
# Fields whose values must never be logged verbatim.
|
||||
_SENSITIVE_ARG_FIELDS = frozenset({"api_key"})
|
||||
|
||||
|
||||
def _redact_sensitive_args(args: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Return a copy of `args` with sensitive values redacted for logging."""
|
||||
if not any(key in _SENSITIVE_ARG_FIELDS for key in args):
|
||||
return args
|
||||
return {
|
||||
key: ("***" if key in _SENSITIVE_ARG_FIELDS else value)
|
||||
for key, value in args.items()
|
||||
}
|
||||
|
||||
|
||||
def log_non_default_args(args: Namespace | EngineArgs):
|
||||
non_default_args = get_non_default_args(args)
|
||||
logger.info("non-default args: %s", non_default_args)
|
||||
logger.info("non-default args: %s", _redact_sensitive_args(non_default_args))
|
||||
|
||||
|
||||
def should_include_usage(
|
||||
|
||||
Reference in New Issue
Block a user