Skip to content

Commit

Permalink
pass tenant context to discovery session
Browse files Browse the repository at this point in the history
  • Loading branch information
byewokko committed Oct 3, 2024
1 parent eefb4b2 commit 178fa44
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions asab/api/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
jwcrypto = None

from .. import Service
from ..contextvars import Tenant


L = logging.getLogger(__name__)
Expand Down Expand Up @@ -404,6 +405,12 @@ def session(self, base_url=None, auth=None, headers=None, **kwargs) -> aiohttp.C
"Only instances of aiohttp.ClientRequest or the literal string 'internal' are allowed. "
"Found {}.".format(type(auth))
)

# Set tenant header if we are in tenant context
tenant = Tenant.get()
if tenant is not None:
headers["X-Tenant"] = tenant

return aiohttp.ClientSession(
base_url,
connector=aiohttp.TCPConnector(resolver=DiscoveryResolver(self)),
Expand Down

0 comments on commit 178fa44

Please sign in to comment.