diff --git a/src/sempy_labs/admin/__init__.py b/src/sempy_labs/admin/__init__.py index 25636034..c864fd06 100644 --- a/src/sempy_labs/admin/__init__.py +++ b/src/sempy_labs/admin/__init__.py @@ -70,6 +70,7 @@ resolve_domain_id, unassign_domain_workspaces, unassign_all_domain_workspaces, + sync_role_assignments_to_subdomains, ) from ._items import ( list_item_access_details, @@ -167,4 +168,5 @@ "remove_sharing_links", "bulk_set_labels", "bulk_remove_labels", + "sync_role_assignments_to_subdomains", ] diff --git a/src/sempy_labs/admin/_domains.py b/src/sempy_labs/admin/_domains.py index 7d0c5344..c579bc2d 100644 --- a/src/sempy_labs/admin/_domains.py +++ b/src/sempy_labs/admin/_domains.py @@ -1,4 +1,4 @@ -from typing import Optional, List +from typing import Literal, Optional, List import sempy_labs._icons as icons import pandas as pd from uuid import UUID @@ -205,6 +205,8 @@ def create_domain( This is a wrapper function for the following API: `Domains - Create Domain `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain_name : str @@ -232,7 +234,11 @@ def create_domain( payload["parentDomainId"] = parent_domain_id _base_api( - request="/v1/admin/domains", method="post", payload=payload, status_codes=201 + request="/v1/admin/domains", + method="post", + payload=payload, + status_codes=201, + client="fabric_sp", ) print(f"{icons.green_dot} The '{domain_name}' domain has been created.") @@ -245,6 +251,8 @@ def delete_domain(domain: Optional[str | UUID], **kwargs): This is a wrapper function for the following API: `Domains - Delete Domain `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -261,7 +269,9 @@ def delete_domain(domain: Optional[str | UUID], **kwargs): raise ValueError(f"{icons.red_dot} Please provide a domain.") domain_id = resolve_domain_id(domain) - _base_api(request=f"/v1/admin/domains/{domain_id}", method="delete") + _base_api( + request=f"/v1/admin/domains/{domain_id}", method="delete", client="fabric_sp" + ) print(f"{icons.green_dot} The '{domain}' domain has been deleted.") @@ -278,6 +288,8 @@ def update_domain( This is a wrapper function for the following API: `Domains - Update Domain `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -314,7 +326,12 @@ def update_domain( if contributors_scope is not None: payload["contributorsScope"] = contributors_scope - _base_api(request=f"/v1/admin/domains/{domain_id}", method="patch", payload=payload) + _base_api( + request=f"/v1/admin/domains/{domain_id}", + method="patch", + payload=payload, + client="fabric_sp", + ) print(f"{icons.green_dot} The '{domain_name}' domain has been updated.") @@ -330,6 +347,8 @@ def assign_domain_workspaces_by_capacities( This is a wrapper function for the following API: `Domains - Assign Domain Workspaces By Capacities `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -381,6 +400,7 @@ def assign_domain_workspaces_by_capacities( payload=payload, lro_return_status_code=True, status_codes=202, + client="fabric_sp", ) print( @@ -395,6 +415,8 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str This is a wrapper function for the following API: `Domains - Assign Domain Workspaces By Ids `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -433,6 +455,7 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str request=f"/v1/admin/domains/{domain_id}/assignWorkspaces", method="post", payload=payload, + client="fabric_sp", ) print( @@ -447,6 +470,8 @@ def unassign_all_domain_workspaces(domain: str | UUID): This is a wrapper function for the following API: `Domains - Unassign All Domain Workspaces `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -458,8 +483,7 @@ def unassign_all_domain_workspaces(domain: str | UUID): _base_api( request=f"/v1/admin/domains/{domain_id}/unassignAllWorkspaces", method="post", - lro_return_status_code=True, - status_codes=200, + client="fabric_sp", ) print( @@ -477,6 +501,8 @@ def unassign_domain_workspaces( This is a wrapper function for the following API: `Domains - Unassign Domain Workspaces By Ids `_. + Service Principal Authentication is supported (see `here `_ for examples). + Parameters ---------- domain : str | uuid.UUID @@ -515,8 +541,47 @@ def unassign_domain_workspaces( request=f"/v1/admin/domains/{domain_id}/unassignWorkspaces", method="post", payload=payload, + client="fabric_sp", ) print( f"{icons.green_dot} The {workspace_names} workspaces assigned to the '{domain}' domain have been unassigned." ) + + +@log +def sync_role_assignments_to_subdomains( + domain: str | UUID, role: Literal["Admin", "Contributor"] +): + """ + Sync the role assignments from the specified domain to its subdomains. + + This is a wrapper function for the following API: `Domains - Sync Role Assignments To Subdomains `_. + + Parameters + ---------- + domain : str | uuid.UUID + The domain name or ID. + role : Literal["Admin", "Contributor"] + The role to sync. Valid options: 'Admin', 'Contributor'. + """ + + role = role.capitalize() + valid_roles = ["Admin", "Contributor"] + if role not in valid_roles: + raise ValueError(f"{icons.red_dot} Invalid role. Valid options: {valid_roles}.") + + domain_id = resolve_domain_id(domain) + + payload = {"role": role} + + _base_api( + request=f"/v1/admin/domains/{domain_id}/roleAssignments/syncToSubdomains", + method="post", + client="fabric_sp", + payload=payload, + ) + + print( + f"{icons.green_dot} The '{role}' role assignments for the '{domain}' domain have been synced to its subdomains." + )