Skip to content

Commit b36245f

Browse files
committed
update sdk client to accept headers
1 parent ebc2b39 commit b36245f

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

dataspace_sdk/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, base_url: str, auth_client: Any = None):
2525
"""
2626
self.base_url = base_url.rstrip("/")
2727
self.auth_client = auth_client
28+
self.default_headers: Dict[str, str] = {}
2829

2930
def _get_headers(self, additional_headers: Optional[Dict[str, str]] = None) -> Dict[str, str]:
3031
"""
@@ -38,6 +39,9 @@ def _get_headers(self, additional_headers: Optional[Dict[str, str]] = None) -> D
3839
"""
3940
headers = {"Content-Type": "application/json"}
4041

42+
if self.default_headers:
43+
headers.update(self.default_headers)
44+
4145
if self.auth_client and self.auth_client.is_authenticated():
4246
headers["Authorization"] = f"Bearer {self.auth_client.access_token}"
4347

dataspace_sdk/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ def is_authenticated(self) -> bool:
187187
"""
188188
return self._auth.is_authenticated()
189189

190+
def set_organization(self, organization_id: str) -> None:
191+
"""
192+
Set the organization header for all subsequent API requests.
193+
194+
The DataSpace backend reads the 'organization' header to scope
195+
queries to a specific organization.
196+
197+
Args:
198+
organization_id: Organization ID to include in requests
199+
"""
200+
self.datasets.default_headers["organization"] = organization_id
201+
self.aimodels.default_headers["organization"] = organization_id
202+
self.usecases.default_headers["organization"] = organization_id
203+
self.sectors.default_headers["organization"] = organization_id
204+
self.auditors.default_headers["organization"] = organization_id
205+
190206
@property
191207
def user(self) -> Optional[dict]:
192208
"""

dataspace_sdk/resources/auditors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ def __init__(self, base_url: str, auth_client: Any):
2525
"""
2626
self._base_url = base_url.rstrip("/")
2727
self._auth = auth_client
28+
self.default_headers: Dict[str, str] = {}
2829

2930
def _get_headers(self) -> Dict[str, str]:
3031
"""Get request headers with authentication."""
3132
headers = {"Content-Type": "application/json"}
33+
if self.default_headers:
34+
headers.update(self.default_headers)
3235
if self._auth and self._auth.access_token:
3336
headers["Authorization"] = f"Bearer {self._auth.access_token}"
3437
return headers

0 commit comments

Comments
 (0)