Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions osism/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,29 @@ def _mask_inventory_secrets(data: dict) -> dict:
"""Mask secret values in inventory data before returning via API.

Masks values for keys matching secret patterns (password, secret,
ironic_osism_*) and values that are Ansible Vault encrypted.
ironic_osism_*) and values that are Ansible Vault encrypted, at any
nesting depth inside dicts and lists.
"""
masked: dict = {}
for key, value in data.items():
if _is_secret_key(key):
masked[key] = "***"
elif isinstance(value, str) and value.strip().startswith("$ANSIBLE_VAULT;"):
masked[key] = "***"
elif isinstance(value, dict):
masked[key] = _mask_inventory_secrets(value)
else:
masked[key] = value
masked[key] = _mask_inventory_value(value)
return masked


def _mask_inventory_value(value):
"""Mask secrets in a single inventory value, recursing into containers."""
if isinstance(value, str) and value.strip().startswith("$ANSIBLE_VAULT;"):
return "***"
if isinstance(value, dict):
return _mask_inventory_secrets(value)
if isinstance(value, list):
return [_mask_inventory_value(item) for item in value]
return value


class NotificationBaremetal(BaseModel):
priority: str = Field(..., description="Notification priority level")
event_type: str = Field(..., description="Type of the event")
Expand Down
Loading