Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add token provider to admin.list_workspaces #325

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0cba36e
add token provider to admin.list_workspaces
m-kovalsky Dec 2, 2024
4f45203
add to more admin functions
m-kovalsky Dec 2, 2024
3e8399a
added more functions
m-kovalsky Dec 2, 2024
63bb226
completed admin functions
m-kovalsky Dec 2, 2024
5026238
fix
m-kovalsky Dec 2, 2024
4d76eaf
updated to fabricrestclient
m-kovalsky Dec 3, 2024
947d97d
fix
m-kovalsky Dec 3, 2024
af24b11
added to _connections
m-kovalsky Dec 5, 2024
a18a8a1
token_provider for _gateways
m-kovalsky Dec 5, 2024
d76e49e
token_provider deployment_pipelines
m-kovalsky Dec 5, 2024
caaf4db
token_provider _environments
m-kovalsky Dec 5, 2024
8180840
token_provider _eventhouses
m-kovalsky Dec 5, 2024
73a83e7
token_provider _kql_databases
m-kovalsky Dec 5, 2024
bd1a514
token_provider _kql_querysets
m-kovalsky Dec 5, 2024
e73ad00
token_provider _list_functions
m-kovalsky Dec 5, 2024
d742dd6
token_provider _managed_private_endpoints
m-kovalsky Dec 5, 2024
c0c16f9
token_provider _notebooks
m-kovalsky Dec 5, 2024
bc48d7b
token_provider _workspace_identity
m-kovalsky Dec 5, 2024
f17f09f
token_provider _workspaces
m-kovalsky Dec 5, 2024
f2c7816
token_provider _dataflows
m-kovalsky Dec 5, 2024
fd76b6c
token_provider qso
m-kovalsky Dec 5, 2024
82d1554
token_provider _get_lakehouse_tables
m-kovalsky Dec 5, 2024
9d8c1ae
token_provider _shortcuts
m-kovalsky Dec 5, 2024
5513c0a
089
m-kovalsky Dec 5, 2024
27c650a
token_provider _generate_semantic_model
m-kovalsky Dec 8, 2024
c953e4e
clean helper functions
m-kovalsky Dec 8, 2024
fde7db7
added temp file for SL functions with SP
m-kovalsky Dec 11, 2024
f250c94
added _list_datasets
m-kovalsky Dec 12, 2024
ae0baad
updated _list_workspaces to use pbi api
m-kovalsky Dec 12, 2024
a25fc02
updated parameter
m-kovalsky Dec 12, 2024
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Semantic Link Labs

[![PyPI version](https://badge.fury.io/py/semantic-link-labs.svg)](https://badge.fury.io/py/semantic-link-labs)
[![Read The Docs](https://readthedocs.org/projects/semantic-link-labs/badge/?version=0.8.8&style=flat)](https://readthedocs.org/projects/semantic-link-labs/)
[![Read The Docs](https://readthedocs.org/projects/semantic-link-labs/badge/?version=0.8.9&style=flat)](https://readthedocs.org/projects/semantic-link-labs/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Downloads](https://static.pepy.tech/badge/semantic-link-labs)](https://pepy.tech/project/semantic-link-labs)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
project = 'semantic-link-labs'
copyright = '2024, Microsoft and community'
author = 'Microsoft and community'
release = '0.8.8'
release = '0.8.9'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name="semantic-link-labs"
authors = [
{ name = "Microsoft Corporation" },
]
version="0.8.8"
version="0.8.9"
description="Semantic Link Labs for Microsoft Fabric"
readme="README.md"
requires-python=">=3.10,<3.12"
Expand Down
105 changes: 71 additions & 34 deletions src/sempy_labs/_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from sempy_labs._helper_functions import (
pagination,
_is_valid_uuid,
resolve_workspace_name_and_id,
)
from uuid import UUID
import sempy_labs._icons as icons
from sempy_labs._gateways import _resolve_gateway_id


def delete_connection(connection: str | UUID):
"""
def delete_connection(connection: str | UUID, token_provider: Optional[str] = None):
f"""
Delete a connection.

This is a wrapper function for the following API: `Connections - Delete Connection <https://learn.microsoft.com/rest/api/fabric/core/connections/delete-connection>`_.
Expand All @@ -21,11 +22,13 @@ def delete_connection(connection: str | UUID):
----------
connection : str | UUID
The connection name or ID.
token_provider : str, default=None
{icons.token_provider_desc}
"""

connection_id = _resolve_connection_id(connection)
connection_id = _resolve_connection_id(connection, token_provider=token_provider)

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.delete(f"/v1/connections/{connection_id}")

if response.status_code != 200:
Expand All @@ -34,8 +37,12 @@ def delete_connection(connection: str | UUID):
print(f"{icons.green_dot} The '{connection}' connection has been deleted.")


def delete_connection_role_assignment(connection: str | UUID, role_assignment_id: UUID):
"""
def delete_connection_role_assignment(
connection: str | UUID,
role_assignment_id: UUID,
token_provider: Optional[str] = None,
):
f"""
Delete the specified role assignment for the connection.

This is a wrapper function for the following API: `Connections - Delete Connection Role Assignment <https://learn.microsoft.com/rest/api/fabric/core/connections/delete-connection-role-assignment>`_.
Expand All @@ -46,11 +53,13 @@ def delete_connection_role_assignment(connection: str | UUID, role_assignment_id
The connection name or ID.
role_assignment_id : UUID
The role assignment ID.
token_provider : str, default=None
{icons.token_provider_desc}
"""

connection_id = _resolve_connection_id(connection)
connection_id = _resolve_connection_id(connection, token_provider=token_provider)

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.delete(
f"/v1/connections/{connection_id}/roleAssignments/{role_assignment_id}"
)
Expand All @@ -63,24 +72,28 @@ def delete_connection_role_assignment(connection: str | UUID, role_assignment_id
)


def _resolve_connection_id(connection: str | UUID) -> UUID:
def _resolve_connection_id(
connection: str | UUID, token_provider: Optional[str] = None
) -> UUID:

dfC = list_connections()
dfC = list_connections(token_provider=token_provider)
if _is_valid_uuid(connection):
dfC_filt = dfC[dfC["Connection Id"] == connection]
else:
dfC_filt = dfC[dfC["Connection Name"] == connection]

if len(dfC_filt) == 0:
if dfC_filt.empty:
raise ValueError(
f"{icons.red_dot} The '{connection}' is not a valid connection."
)

return dfC_filt["Connection Id"].iloc[0]


def list_connection_role_assignments(connection: str | UUID) -> pd.DataFrame:
"""
def list_connection_role_assignments(
connection: str | UUID, token_provider: Optional[str] = None
) -> pd.DataFrame:
f"""
Returns a list of connection role assignments.

This is a wrapper function for the following API: `Connections - List Connection Role Assignments <https://learn.microsoft.com/rest/api/fabric/core/connections/list-connection-role-assignments>`_.
Expand All @@ -89,16 +102,18 @@ def list_connection_role_assignments(connection: str | UUID) -> pd.DataFrame:
----------
connection : str | UUID
The connection name or ID.
token_provider : str, default=None
{icons.token_provider_desc}

Returns
-------
pandas.DataFrame
A pandas dataframe showing a list of connection role assignments.
"""

connection_id = _resolve_connection_id(connection)
connection_id = _resolve_connection_id(connection, token_provider=token_provider)

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.get(f"/v1/connections/{connection_id}/roleAssignments")

df = pd.DataFrame(
Expand Down Expand Up @@ -129,17 +144,24 @@ def list_connection_role_assignments(connection: str | UUID) -> pd.DataFrame:
return df


def list_connections() -> pd.DataFrame:
"""
def list_connections(token_provider: Optional[str] = None) -> pd.DataFrame:
f"""
Lists all available connections.

Parameters
----------
connection : str | UUID
The connection name or ID.
token_provider : str, default=None
{icons.token_provider_desc}

Returns
-------
pandas.DataFrame
A pandas dataframe showing all available connections.
"""

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.get("/v1/connections")

if response.status_code != 200:
Expand Down Expand Up @@ -205,9 +227,12 @@ def list_connections() -> pd.DataFrame:


def list_item_connections(
item_name: str, item_type: str, workspace: Optional[str] = None
item_name: str,
item_type: str,
workspace: Optional[str] = None,
token_provider: Optional[str] = None,
) -> pd.DataFrame:
"""
f"""
Shows the list of connections that the specified item is connected to.

This is a wrapper function for the following API: `Items - List Item Connections <https://learn.microsoft.com/rest/api/fabric/core/items/list-item-connections>`_.
Expand All @@ -222,21 +247,22 @@ def list_item_connections(
The Fabric workspace name.
Defaults to None which resolves to the workspace of the attached lakehouse
or if no lakehouse attached, resolves to the workspace of the notebook.
token_provider : str, default=None
{icons.token_provider_desc}

Returns
-------
pandas.DataFrame
A pandas dataframe showing the list of connections that the specified item is connected to.
"""

workspace = fabric.resolve_workspace_name(workspace)
workspace_id = fabric.resolve_workspace_id(workspace)
(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)
item_type = item_type[0].upper() + item_type[1:]
item_id = fabric.resolve_item_id(
item_name=item_name, type=item_type, workspace=workspace
)

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.get(f"/v1/workspaces/{workspace_id}/items/{item_id}/connections")

df = pd.DataFrame(
Expand Down Expand Up @@ -272,12 +298,14 @@ def list_item_connections(


def _list_supported_connection_types(
gateway: Optional[str | UUID] = None, show_all_creation_methods: bool = False
gateway: Optional[str | UUID] = None,
show_all_creation_methods: bool = False,
token_provider: Optional[str] = None,
) -> pd.DataFrame:

url = f"/v1/connections/supportedConnectionTypes?showAllCreationMethods={show_all_creation_methods}&"
if gateway is not None:
gateway_id = _resolve_gateway_id(gateway)
gateway_id = _resolve_gateway_id(gateway, token_provider=token_provider)
url += f"gatewayId={gateway_id}"

df = pd.DataFrame(
Expand All @@ -291,7 +319,7 @@ def _list_supported_connection_types(
)

url = url.rstrip("&")
client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.get(url)
if response.status_code != 200:
raise FabricHTTPException(response)
Expand Down Expand Up @@ -330,8 +358,9 @@ def create_cloud_connection(
privacy_level: str,
connection_encryption: str = "NotEncrypted",
skip_test_connection: bool = False,
token_provider: Optional[str] = None,
):
"""
f"""
Creates a shared cloud connection.

This is a wrapper function for the following API: `Connections - Create Connection <https://learn.microsoft.com/rest/api/fabric/core/connections/create-connection>`_.
Expand All @@ -354,6 +383,8 @@ def create_cloud_connection(
The connection encrpytion.
skip_test_connection: bool, default=False
If True, skips the test connection.
token_provider : str, default=None
{icons.token_provider_desc}
"""

request_body = {
Expand Down Expand Up @@ -388,7 +419,7 @@ def create_cloud_connection(
},
}

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.post("/v1/connections", json=request_body)

if response.status_code != 201:
Expand All @@ -406,8 +437,9 @@ def create_on_prem_connection(
privacy_level: str,
connection_encryption: str = "NotEncrypted",
skip_test_connection: bool = False,
token_provider: Optional[str] = None,
):
"""
f"""
Creates an on-premises connection.

This is a wrapper function for the following API: `Connections - Create Connection <https://learn.microsoft.com/rest/api/fabric/core/connections/create-connection>`_.
Expand All @@ -432,9 +464,11 @@ def create_on_prem_connection(
The connection encrpytion.
skip_test_connection: bool, default=False
If True, skips the test connection.
token_provider : str, default=None
{icons.token_provider_desc}
"""

gateway_id = _resolve_gateway_id(gateway)
gateway_id = _resolve_gateway_id(gateway, token_provider=token_provider)

request_body = {
"connectivityType": "OnPremisesGateway",
Expand Down Expand Up @@ -468,7 +502,7 @@ def create_on_prem_connection(
},
}

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.post("/v1/connections", json=request_body)

if response.status_code != 201:
Expand All @@ -487,8 +521,9 @@ def create_vnet_connection(
privacy_level: str,
connection_encryption: Optional[str] = "NotEncrypted",
skip_test_connection: bool = False,
token_provider: Optional[str] = None,
):
"""
f"""
Creates a virtual network gateway connection.

This is a wrapper function for the following API: `Connections - Create Connection <https://learn.microsoft.com/rest/api/fabric/core/connections/create-connection>`_.
Expand All @@ -513,9 +548,11 @@ def create_vnet_connection(
The connection encrpytion.
skip_test_connection: bool, default=False
If True, skips the test connection.
token_provider : str, default=None
{icons.token_provider_desc}
"""

gateway_id = _resolve_gateway_id(gateway)
gateway_id = _resolve_gateway_id(gateway, token_provider=token_provider)

request_body = {
"connectivityType": "VirtualNetworkGateway",
Expand Down Expand Up @@ -550,7 +587,7 @@ def create_vnet_connection(
},
}

client = fabric.FabricRestClient()
client = fabric.FabricRestClient(token_provider=token_provider)
response = client.post("/v1/connections", json=request_body)

if response.status_code != 201:
Expand Down
Loading