Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sempy_labs/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -167,4 +168,5 @@
"remove_sharing_links",
"bulk_set_labels",
"bulk_remove_labels",
"sync_role_assignments_to_subdomains",
]
77 changes: 71 additions & 6 deletions src/sempy_labs/admin/_domains.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -205,6 +205,8 @@ def create_domain(

This is a wrapper function for the following API: `Domains - Create Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/create-domain>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain_name : str
Expand Down Expand Up @@ -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.")
Expand All @@ -245,6 +251,8 @@ def delete_domain(domain: Optional[str | UUID], **kwargs):

This is a wrapper function for the following API: `Domains - Delete Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/delete-domain>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand All @@ -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.")

Expand All @@ -278,6 +288,8 @@ def update_domain(

This is a wrapper function for the following API: `Domains - Update Domain <https://learn.microsoft.com/rest/api/fabric/admin/domains/update-domain>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand Down Expand Up @@ -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.")

Expand All @@ -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 <https://learn.microsoft.com/rest/api/fabric/admin/domains/assign-domain-workspaces-by-capacities>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand Down Expand Up @@ -381,6 +400,7 @@ def assign_domain_workspaces_by_capacities(
payload=payload,
lro_return_status_code=True,
status_codes=202,
client="fabric_sp",
)

print(
Expand All @@ -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 <https://learn.microsoft.com/rest/api/fabric/admin/domains/assign-domain-workspaces-by-ids>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand Down Expand Up @@ -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(
Expand All @@ -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 <https://learn.microsoft.com/rest/api/fabric/admin/domains/unassign-all-domain-workspaces>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand All @@ -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(
Expand All @@ -477,6 +501,8 @@ def unassign_domain_workspaces(

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>`_.

Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).

Parameters
----------
domain : str | uuid.UUID
Expand Down Expand Up @@ -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 <https://learn.microsoft.com/rest/api/fabric/admin/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."
)
Loading