Skip to content

Commit a09224c

Browse files
committed
sync_role_assignments_to_subdomains
1 parent 8210e97 commit a09224c

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

src/sempy_labs/admin/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
resolve_domain_id,
7171
unassign_domain_workspaces,
7272
unassign_all_domain_workspaces,
73+
sync_role_assignments_to_subdomains,
7374
)
7475
from ._items import (
7576
list_item_access_details,
@@ -167,4 +168,5 @@
167168
"remove_sharing_links",
168169
"bulk_set_labels",
169170
"bulk_remove_labels",
171+
"sync_role_assignments_to_subdomains",
170172
]

src/sempy_labs/admin/_domains.py

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, List
1+
from typing import Literal, Optional, List
22
import sempy_labs._icons as icons
33
import pandas as pd
44
from uuid import UUID
@@ -205,6 +205,8 @@ def create_domain(
205205
206206
This is a wrapper function for the following API: `Domains - Create Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/create-domain>`_.
207207
208+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
209+
208210
Parameters
209211
----------
210212
domain_name : str
@@ -232,7 +234,11 @@ def create_domain(
232234
payload["parentDomainId"] = parent_domain_id
233235

234236
_base_api(
235-
request="/v1/admin/domains", method="post", payload=payload, status_codes=201
237+
request="/v1/admin/domains",
238+
method="post",
239+
payload=payload,
240+
status_codes=201,
241+
client="fabric_sp",
236242
)
237243

238244
print(f"{icons.green_dot} The '{domain_name}' domain has been created.")
@@ -245,6 +251,8 @@ def delete_domain(domain: Optional[str | UUID], **kwargs):
245251
246252
This is a wrapper function for the following API: `Domains - Delete Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/delete-domain>`_.
247253
254+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
255+
248256
Parameters
249257
----------
250258
domain : str | uuid.UUID
@@ -261,7 +269,9 @@ def delete_domain(domain: Optional[str | UUID], **kwargs):
261269
raise ValueError(f"{icons.red_dot} Please provide a domain.")
262270

263271
domain_id = resolve_domain_id(domain)
264-
_base_api(request=f"/v1/admin/domains/{domain_id}", method="delete")
272+
_base_api(
273+
request=f"/v1/admin/domains/{domain_id}", method="delete", client="fabric_sp"
274+
)
265275

266276
print(f"{icons.green_dot} The '{domain}' domain has been deleted.")
267277

@@ -278,6 +288,8 @@ def update_domain(
278288
279289
This is a wrapper function for the following API: `Domains - Update Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/update-domain>`_.
280290
291+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
292+
281293
Parameters
282294
----------
283295
domain : str | uuid.UUID
@@ -314,7 +326,12 @@ def update_domain(
314326
if contributors_scope is not None:
315327
payload["contributorsScope"] = contributors_scope
316328

317-
_base_api(request=f"/v1/admin/domains/{domain_id}", method="patch", payload=payload)
329+
_base_api(
330+
request=f"/v1/admin/domains/{domain_id}",
331+
method="patch",
332+
payload=payload,
333+
client="fabric_sp",
334+
)
318335

319336
print(f"{icons.green_dot} The '{domain_name}' domain has been updated.")
320337

@@ -330,6 +347,8 @@ def assign_domain_workspaces_by_capacities(
330347
331348
This is a wrapper function for the following API: `Domains - Assign Domain Workspaces By Capacities <https://learn.microsoft.com/rest/api/fabric/admin/domains/assign-domain-workspaces-by-capacities>`_.
332349
350+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
351+
333352
Parameters
334353
----------
335354
domain : str | uuid.UUID
@@ -381,6 +400,7 @@ def assign_domain_workspaces_by_capacities(
381400
payload=payload,
382401
lro_return_status_code=True,
383402
status_codes=202,
403+
client="fabric_sp",
384404
)
385405

386406
print(
@@ -395,6 +415,8 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str
395415
396416
This is a wrapper function for the following API: `Domains - Assign Domain Workspaces By Ids <https://learn.microsoft.com/rest/api/fabric/admin/domains/assign-domain-workspaces-by-ids>`_.
397417
418+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
419+
398420
Parameters
399421
----------
400422
domain : str | uuid.UUID
@@ -433,6 +455,7 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str
433455
request=f"/v1/admin/domains/{domain_id}/assignWorkspaces",
434456
method="post",
435457
payload=payload,
458+
client="fabric_sp",
436459
)
437460

438461
print(
@@ -447,6 +470,8 @@ def unassign_all_domain_workspaces(domain: str | UUID):
447470
448471
This is a wrapper function for the following API: `Domains - Unassign All Domain Workspaces <https://learn.microsoft.com/rest/api/fabric/admin/domains/unassign-all-domain-workspaces>`_.
449472
473+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
474+
450475
Parameters
451476
----------
452477
domain : str | uuid.UUID
@@ -458,8 +483,7 @@ def unassign_all_domain_workspaces(domain: str | UUID):
458483
_base_api(
459484
request=f"/v1/admin/domains/{domain_id}/unassignAllWorkspaces",
460485
method="post",
461-
lro_return_status_code=True,
462-
status_codes=200,
486+
client="fabric_sp",
463487
)
464488

465489
print(
@@ -477,6 +501,8 @@ def unassign_domain_workspaces(
477501
478502
This is a wrapper function for the following API: `Domains - Unassign Domain Workspaces By Ids <https://learn.microsoft.com/rest/api/fabric/admin/domains/unassign-domain-workspaces-by-ids>`_.
479503
504+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
505+
480506
Parameters
481507
----------
482508
domain : str | uuid.UUID
@@ -515,8 +541,47 @@ def unassign_domain_workspaces(
515541
request=f"/v1/admin/domains/{domain_id}/unassignWorkspaces",
516542
method="post",
517543
payload=payload,
544+
client="fabric_sp",
518545
)
519546

520547
print(
521548
f"{icons.green_dot} The {workspace_names} workspaces assigned to the '{domain}' domain have been unassigned."
522549
)
550+
551+
552+
@log
553+
def sync_role_assignments_to_subdomains(
554+
domain: str | UUID, role: Literal["Admin", "Contributor"]
555+
):
556+
"""
557+
Sync the role assignments from the specified domain to its subdomains.
558+
559+
This is a wrapper function for the following API: `Domains - Sync Role Assignments To Subdomains <https://learn.microsoft.com/rest/api/fabric/admin/domains/sync-role-assignments-to-subdomains>`_.
560+
561+
Parameters
562+
----------
563+
domain : str | uuid.UUID
564+
The domain name or ID.
565+
role : Literal["Admin", "Contributor"]
566+
The role to sync. Valid options: 'Admin', 'Contributor'.
567+
"""
568+
569+
role = role.capitalize()
570+
valid_roles = ["Admin", "Contributor"]
571+
if role not in valid_roles:
572+
raise ValueError(f"{icons.red_dot} Invalid role. Valid options: {valid_roles}.")
573+
574+
domain_id = resolve_domain_id(domain)
575+
576+
payload = {"role": role}
577+
578+
_base_api(
579+
request=f"/v1/admin/domains/{domain_id}/roleAssignments/syncToSubdomains",
580+
method="post",
581+
client="fabric_sp",
582+
payload=payload,
583+
)
584+
585+
print(
586+
f"{icons.green_dot} The '{role}' role assignments for the '{domain}' domain have been synced to its subdomains."
587+
)

0 commit comments

Comments
 (0)