feat: support for import/export masked_encrypted_extra (backend) (#38077)

This commit is contained in:
Vitor Avila
2026-03-04 16:26:28 -03:00
committed by GitHub
parent 63e7ee70bf
commit 8c9efe5659
16 changed files with 799 additions and 2 deletions

View File

@@ -302,3 +302,46 @@ def reveal_sensitive(
match.context.value[match.path.fields[0]] = old_value[0].value
return revealed_payload
def get_masked_fields(
payload: dict[str, Any],
sensitive_fields: set[str],
) -> list[str]:
"""
Returns masked fields in JSON config.
:param payload: The payload to check
:param sensitive_fields: The set of fields to check, as JSONPath expressions
:returns: List of JSONPath expressions for fields that are masked
"""
masked = []
for json_path in sensitive_fields:
jsonpath_expr = parse(json_path)
for match in jsonpath_expr.find(payload):
if match.value == PASSWORD_MASK:
# Using `match.full_path` instead of json_path to account
# for wildcards
masked.append(f"$.{match.full_path}")
return masked
def set_masked_fields(
payload: dict[str, Any],
path_values: dict[str, Any],
) -> dict[str, Any]:
"""
Sets values at JSONPath locations in a payload.
:param payload: The payload to modify
:param path_values: A dict mapping JSONPath expressions to values
:returns: The modified payload (copy)
"""
result = copy.deepcopy(payload)
for json_path, value in path_values.items():
jsonpath_expr = parse(json_path)
for match in jsonpath_expr.find(result):
match.context.value[match.path.fields[0]] = value
return result