Skip to content

Commit 1b502db

Browse files
feat: add tenant parameter to label management operations (#68)
1 parent d59b96d commit 1b502db

9 files changed

Lines changed: 331 additions & 30 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sap-cloud-sdk"
3-
version = "0.11.1"
3+
version = "0.11.2"
44
description = "SAP Cloud SDK for Python"
55
readme = "README.md"
66
license = "Apache-2.0"

src/sap_cloud_sdk/destination/certificate_client.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,17 @@ def delete_certificate(
307307

308308
@record_metrics(Module.DESTINATION, Operation.CERTIFICATE_GET_LABELS)
309309
def get_certificate_labels(
310-
self, name: str, level: Optional[Level] = Level.SUB_ACCOUNT
310+
self,
311+
name: str,
312+
level: Optional[Level] = Level.SUB_ACCOUNT,
313+
tenant: Optional[str] = None,
311314
) -> List[Label]:
312315
"""Get labels for a certificate.
313316
314317
Args:
315318
name: Certificate name.
316319
level: Scope to query (subaccount by default).
320+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
317321
318322
Returns:
319323
List of labels assigned to the certificate. Returns empty list if none assigned.
@@ -323,7 +327,9 @@ def get_certificate_labels(
323327
"""
324328
try:
325329
path = self._sub_path_for_level(level)
326-
resp = self._http.get(f"{API_V1}/{path}/{name}/labels")
330+
resp = self._http.get(
331+
f"{API_V1}/{path}/{name}/labels", tenant_subdomain=tenant
332+
)
327333
data = resp.json()
328334
if not isinstance(data, list):
329335
raise DestinationOperationError(
@@ -341,14 +347,19 @@ def get_certificate_labels(
341347

342348
@record_metrics(Module.DESTINATION, Operation.CERTIFICATE_UPDATE_LABELS)
343349
def update_certificate_labels(
344-
self, name: str, labels: List[Label], level: Optional[Level] = Level.SUB_ACCOUNT
350+
self,
351+
name: str,
352+
labels: List[Label],
353+
level: Optional[Level] = Level.SUB_ACCOUNT,
354+
tenant: Optional[str] = None,
345355
) -> None:
346356
"""Replace all labels for a certificate.
347357
348358
Args:
349359
name: Certificate name.
350360
labels: List of labels to set (replaces existing labels).
351361
level: Scope where the certificate exists (subaccount by default).
362+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
352363
353364
Raises:
354365
HttpError: Propagated for HTTP errors.
@@ -360,6 +371,7 @@ def update_certificate_labels(
360371
self._http.put(
361372
f"{API_V1}/{path}/{name}/labels",
362373
body=[lbl.to_dict() for lbl in labels],
374+
tenant_subdomain=tenant,
363375
)
364376
except HttpError:
365377
raise
@@ -370,14 +382,19 @@ def update_certificate_labels(
370382

371383
@record_metrics(Module.DESTINATION, Operation.CERTIFICATE_PATCH_LABELS)
372384
def patch_certificate_labels(
373-
self, name: str, patch: PatchLabels, level: Optional[Level] = Level.SUB_ACCOUNT
385+
self,
386+
name: str,
387+
patch: PatchLabels,
388+
level: Optional[Level] = Level.SUB_ACCOUNT,
389+
tenant: Optional[str] = None,
374390
) -> None:
375391
"""Add or remove labels for a certificate.
376392
377393
Args:
378394
name: Certificate name.
379395
patch: PatchLabels with action ("ADD" or "DELETE") and labels to apply.
380396
level: Scope where the certificate exists (subaccount by default).
397+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
381398
382399
Raises:
383400
HttpError: Propagated for HTTP errors.
@@ -389,6 +406,7 @@ def patch_certificate_labels(
389406
self._http.patch(
390407
f"{API_V1}/{path}/{name}/labels",
391408
body=patch.to_dict(),
409+
tenant_subdomain=tenant,
392410
)
393411
except HttpError:
394412
raise

src/sap_cloud_sdk/destination/client.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,17 @@ def delete_destination(
522522

523523
@record_metrics(Module.DESTINATION, Operation.DESTINATION_GET_LABELS)
524524
def get_destination_labels(
525-
self, name: str, level: Optional[Level] = Level.SUB_ACCOUNT
525+
self,
526+
name: str,
527+
level: Optional[Level] = Level.SUB_ACCOUNT,
528+
tenant: Optional[str] = None,
526529
) -> List[Label]:
527530
"""Get labels for a destination.
528531
529532
Args:
530533
name: Destination name.
531534
level: Scope to query (subaccount by default).
535+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
532536
533537
Returns:
534538
List of labels assigned to the destination. Returns empty list if none assigned.
@@ -538,7 +542,9 @@ def get_destination_labels(
538542
"""
539543
try:
540544
path = self._sub_path_for_level(level)
541-
resp = self._http.get(f"{API_V1}/{path}/{name}/labels")
545+
resp = self._http.get(
546+
f"{API_V1}/{path}/{name}/labels", tenant_subdomain=tenant
547+
)
542548
data = resp.json()
543549
if not isinstance(data, list):
544550
raise DestinationOperationError(
@@ -556,14 +562,19 @@ def get_destination_labels(
556562

557563
@record_metrics(Module.DESTINATION, Operation.DESTINATION_UPDATE_LABELS)
558564
def update_destination_labels(
559-
self, name: str, labels: List[Label], level: Optional[Level] = Level.SUB_ACCOUNT
565+
self,
566+
name: str,
567+
labels: List[Label],
568+
level: Optional[Level] = Level.SUB_ACCOUNT,
569+
tenant: Optional[str] = None,
560570
) -> None:
561571
"""Replace all labels for a destination.
562572
563573
Args:
564574
name: Destination name.
565575
labels: List of labels to set (replaces existing labels).
566576
level: Scope where the destination exists (subaccount by default).
577+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
567578
568579
Raises:
569580
HttpError: Propagated for HTTP errors.
@@ -575,6 +586,7 @@ def update_destination_labels(
575586
self._http.put(
576587
f"{API_V1}/{path}/{name}/labels",
577588
body=[lbl.to_dict() for lbl in labels],
589+
tenant_subdomain=tenant,
578590
)
579591
except HttpError:
580592
raise
@@ -585,14 +597,19 @@ def update_destination_labels(
585597

586598
@record_metrics(Module.DESTINATION, Operation.DESTINATION_PATCH_LABELS)
587599
def patch_destination_labels(
588-
self, name: str, patch: PatchLabels, level: Optional[Level] = Level.SUB_ACCOUNT
600+
self,
601+
name: str,
602+
patch: PatchLabels,
603+
level: Optional[Level] = Level.SUB_ACCOUNT,
604+
tenant: Optional[str] = None,
589605
) -> None:
590606
"""Add or remove labels for a destination.
591607
592608
Args:
593609
name: Destination name.
594610
patch: PatchLabels with action ("ADD" or "DELETE") and labels to apply.
595611
level: Scope where the destination exists (subaccount by default).
612+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
596613
597614
Raises:
598615
HttpError: Propagated for HTTP errors.
@@ -604,6 +621,7 @@ def patch_destination_labels(
604621
self._http.patch(
605622
f"{API_V1}/{path}/{name}/labels",
606623
body=patch.to_dict(),
624+
tenant_subdomain=tenant,
607625
)
608626
except HttpError:
609627
raise

src/sap_cloud_sdk/destination/fragment_client.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,17 @@ def delete_fragment(
290290

291291
@record_metrics(Module.DESTINATION, Operation.FRAGMENT_GET_LABELS)
292292
def get_fragment_labels(
293-
self, name: str, level: Optional[Level] = Level.SUB_ACCOUNT
293+
self,
294+
name: str,
295+
level: Optional[Level] = Level.SUB_ACCOUNT,
296+
tenant: Optional[str] = None,
294297
) -> List[Label]:
295298
"""Get labels for a fragment.
296299
297300
Args:
298301
name: Fragment name.
299302
level: Scope to query (subaccount by default).
303+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
300304
301305
Returns:
302306
List of labels assigned to the fragment. Returns empty list if none assigned.
@@ -306,7 +310,9 @@ def get_fragment_labels(
306310
"""
307311
try:
308312
path = self._sub_path_for_level(level)
309-
resp = self._http.get(f"{API_V1}/{path}/{name}/labels")
313+
resp = self._http.get(
314+
f"{API_V1}/{path}/{name}/labels", tenant_subdomain=tenant
315+
)
310316
data = resp.json()
311317
if not isinstance(data, list):
312318
raise DestinationOperationError(
@@ -324,14 +330,19 @@ def get_fragment_labels(
324330

325331
@record_metrics(Module.DESTINATION, Operation.FRAGMENT_UPDATE_LABELS)
326332
def update_fragment_labels(
327-
self, name: str, labels: List[Label], level: Optional[Level] = Level.SUB_ACCOUNT
333+
self,
334+
name: str,
335+
labels: List[Label],
336+
level: Optional[Level] = Level.SUB_ACCOUNT,
337+
tenant: Optional[str] = None,
328338
) -> None:
329339
"""Replace all labels for a fragment.
330340
331341
Args:
332342
name: Fragment name.
333343
labels: List of labels to set (replaces existing labels).
334344
level: Scope where the fragment exists (subaccount by default).
345+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
335346
336347
Raises:
337348
HttpError: Propagated for HTTP errors.
@@ -343,6 +354,7 @@ def update_fragment_labels(
343354
self._http.put(
344355
f"{API_V1}/{path}/{name}/labels",
345356
body=[lbl.to_dict() for lbl in labels],
357+
tenant_subdomain=tenant,
346358
)
347359
except HttpError:
348360
raise
@@ -353,14 +365,19 @@ def update_fragment_labels(
353365

354366
@record_metrics(Module.DESTINATION, Operation.FRAGMENT_PATCH_LABELS)
355367
def patch_fragment_labels(
356-
self, name: str, patch: PatchLabels, level: Optional[Level] = Level.SUB_ACCOUNT
368+
self,
369+
name: str,
370+
patch: PatchLabels,
371+
level: Optional[Level] = Level.SUB_ACCOUNT,
372+
tenant: Optional[str] = None,
357373
) -> None:
358374
"""Add or remove labels for a fragment.
359375
360376
Args:
361377
name: Fragment name.
362378
patch: PatchLabels with action ("ADD" or "DELETE") and labels to apply.
363379
level: Scope where the fragment exists (subaccount by default).
380+
tenant: Optional subscriber tenant subdomain. If provided, the request is scoped to that tenant.
364381
365382
Raises:
366383
HttpError: Propagated for HTTP errors.
@@ -372,6 +389,7 @@ def patch_fragment_labels(
372389
self._http.patch(
373390
f"{API_V1}/{path}/{name}/labels",
374391
body=patch.to_dict(),
392+
tenant_subdomain=tenant,
375393
)
376394
except HttpError:
377395
raise

0 commit comments

Comments
 (0)