Skip to content

feat(auditlog_ng): auto-inject tenant and user from IAS request context#242

Merged
tiagoek merged 8 commits into
mainfrom
feat/als-tenant-inference
Jul 22, 2026
Merged

feat(auditlog_ng): auto-inject tenant and user from IAS request context#242
tiagoek merged 8 commits into
mainfrom
feat/als-tenant-inference

Conversation

@tiagoek

@tiagoek tiagoek commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds ias/_context.py with a ContextVar-backed set_auth_context / get_auth_context to store IAS claims per async request
  • Refactors StarletteIASTelemetryMiddleware to call set_auth_context(claims) on every request via a unified _parse_request() helper
  • Wires AuditClient.send() to auto-fill common.tenant_id (from app_tid) and common.user_initiator_id (from user_uuid) before protovalidate runs — only when not already set by the caller
  • Documents the new automatic injection behaviour in auditlog_ng/user-guide.md

Test plan

  • Verify _fill_common_from_auth_context fills empty fields from a mocked IAS context
  • Verify explicit caller values are not overwritten
  • Verify no injection when no auth context is set (unauthenticated request)
  • Verify send() still raises ValidationError when tenant_id is absent and no context is set

LucasAlvesSoares and others added 4 commits July 22, 2026 10:41
…uest auth context

When IAS claims are available in the current async context (set by
StarletteIASTelemetryMiddleware), back-fill common.tenant_id from
app_tid and common.user_initiator_id from user_uuid before validation
and sending, so callers don't need to set these fields manually.
Comment thread src/sap_cloud_sdk/core/auditlog_ng/client.py Outdated
tiagoek added 2 commits July 22, 2026 14:20
Per review feedback: accessing event.common triggers protobuf lazy
creation so callers that never touched common still get it populated.
Also sets common.timestamp to utcnow when the caller leaves it at zero.
@tiagoek
tiagoek marked this pull request as ready for review July 22, 2026 14:18
@tiagoek
tiagoek requested a review from a team as a code owner July 22, 2026 14:18
@tiagoek
tiagoek merged commit f30b648 into main Jul 22, 2026
10 of 11 checks passed
@tiagoek
tiagoek deleted the feat/als-tenant-inference branch July 22, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants