Skip to content

Commit a917775

Browse files
committed
Merge branch 'm-kovalsky/addgatewaytoinit'
2 parents 4917d3e + 40bae71 commit a917775

File tree

5 files changed

+186
-26
lines changed

5 files changed

+186
-26
lines changed

src/sempy_labs/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
from sempy_labs._gateways import (
2+
list_gateway_members,
3+
list_gateway_role_assigments,
4+
list_gateways,
5+
delete_gateway,
6+
delete_gateway_member,
7+
delete_gateway_role_assignment,
8+
create_vnet_gateway,
9+
update_vnet_gateway,
10+
update_on_premises_gateway,
11+
)
12+
113
from sempy_labs._authentication import (
214
ServicePrincipalTokenProvider,
315
)
@@ -435,4 +447,13 @@
435447
"create_vnet_connection",
436448
"create_on_prem_connection",
437449
"create_cloud_connection",
450+
"list_gateway_members",
451+
"list_gateway_role_assigments",
452+
"list_gateways",
453+
"delete_gateway",
454+
"delete_gateway_member",
455+
"delete_gateway_role_assignment",
456+
"create_vnet_gateway",
457+
"update_vnet_gateway",
458+
"update_on_premises_gateway",
438459
]

src/sempy_labs/_authentication.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ServicePrincipalTokenProvider(TokenProvider):
1111
"""
1212

1313
def __init__(self, credential: ClientSecretCredential):
14+
1415
self.credential = credential
1516

1617
@classmethod
@@ -53,7 +54,7 @@ def with_azure_key_vault(
5354
"""
5455
Create the ServicePrincipalTokenProvider providing the information with the Service Principal information.
5556
56-
For more information on Azure Key Vault check `About Azure Key Vault <https://learn.microsoft.com/en-us/azure/key-vault/general/overview>`_
57+
For more information on Azure Key Vault check `About Azure Key Vault <https://learn.microsoft.com/en-us/azure/key-vault/general/overview>`_.
5758
5859
Parameters
5960
----------
@@ -71,6 +72,7 @@ def with_azure_key_vault(
7172
sempy.fabric.TokenProvider
7273
Token provider to be used with FabricRestClient or PowerBIRestClient.
7374
"""
75+
7476
import notebookutils
7577

7678
tenant_id = notebookutils.credentials.getSecret(

src/sempy_labs/_connections.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99
from uuid import UUID
1010
import sempy_labs._icons as icons
11-
from sempy_labs._gateways import resolve_gateway_id
11+
from sempy_labs._gateways import _resolve_gateway_id
1212

1313

1414
def delete_connection(connection: str | UUID):
@@ -23,7 +23,7 @@ def delete_connection(connection: str | UUID):
2323
The connection name or ID.
2424
"""
2525

26-
connection_id = resolve_connection_id(connection)
26+
connection_id = _resolve_connection_id(connection)
2727

2828
client = fabric.FabricRestClient()
2929
response = client.delete(f"/v1/connections/{connection_id}")
@@ -48,7 +48,7 @@ def delete_connection_role_assignment(connection: str | UUID, role_assignment_id
4848
The role assignment ID.
4949
"""
5050

51-
connection_id = resolve_connection_id(connection)
51+
connection_id = _resolve_connection_id(connection)
5252

5353
client = fabric.FabricRestClient()
5454
response = client.delete(
@@ -63,7 +63,7 @@ def delete_connection_role_assignment(connection: str | UUID, role_assignment_id
6363
)
6464

6565

66-
def resolve_connection_id(connection: str | UUID) -> UUID:
66+
def _resolve_connection_id(connection: str | UUID) -> UUID:
6767

6868
dfC = list_connections()
6969
if _is_valid_uuid(connection):
@@ -96,7 +96,7 @@ def list_connection_role_assignments(connection: str | UUID) -> pd.DataFrame:
9696
A pandas dataframe showing a list of connection role assignments.
9797
"""
9898

99-
connection_id = resolve_connection_id(connection)
99+
connection_id = _resolve_connection_id(connection)
100100

101101
client = fabric.FabricRestClient()
102102
response = client.get(f"/v1/connections/{connection_id}/roleAssignments")
@@ -277,7 +277,7 @@ def _list_supported_connection_types(
277277

278278
url = f"/v1/connections/supportedConnectionTypes?showAllCreationMethods={show_all_creation_methods}&"
279279
if gateway is not None:
280-
gateway_id = resolve_gateway_id(gateway)
280+
gateway_id = _resolve_gateway_id(gateway)
281281
url += f"gatewayId={gateway_id}"
282282

283283
df = pd.DataFrame(
@@ -434,7 +434,7 @@ def create_on_prem_connection(
434434
If True, skips the test connection.
435435
"""
436436

437-
gateway_id = resolve_gateway_id(gateway)
437+
gateway_id = _resolve_gateway_id(gateway)
438438

439439
request_body = {
440440
"connectivityType": "OnPremisesGateway",
@@ -515,7 +515,7 @@ def create_vnet_connection(
515515
If True, skips the test connection.
516516
"""
517517

518-
gateway_id = resolve_gateway_id(gateway)
518+
gateway_id = _resolve_gateway_id(gateway)
519519

520520
request_body = {
521521
"connectivityType": "VirtualNetworkGateway",

src/sempy_labs/_gateways.py

Lines changed: 154 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313

1414
def list_gateways() -> pd.DataFrame:
15+
"""
16+
Returns a list of all gateways the user has permission for, including on-premises, on-premises (personal mode), and virtual network gateways.
17+
18+
This is a wrapper function for the following API: `Gateways - List Gateways <https://learn.microsoft.com/rest/api/fabric/core/gateways/list-gateways>`_.
19+
20+
Returns
21+
-------
22+
pandas.DataFrame
23+
A pandas dataframe showing a list of all gateways the user has permission for, including on-premises, on-premises (personal mode), and virtual network gateways.
24+
"""
1525

1626
client = fabric.FabricRestClient()
1727
response = client.get("/v1/gateways")
@@ -61,7 +71,7 @@ def list_gateways() -> pd.DataFrame:
6171
return df
6272

6373

64-
def resolve_gateway_id(gateway: str | UUID) -> UUID:
74+
def _resolve_gateway_id(gateway: str | UUID) -> UUID:
6575

6676
dfG = list_gateways()
6777
if _is_valid_uuid(gateway):
@@ -76,8 +86,18 @@ def resolve_gateway_id(gateway: str | UUID) -> UUID:
7686

7787

7888
def delete_gateway(gateway: str | UUID):
89+
"""
90+
Deletes a gateway.
91+
92+
This is a wrapper function for the following API: `Gateways - Delete Gateway <https://learn.microsoft.com/rest/api/fabric/core/gateways/delete-gateway>`_.
93+
94+
Parameters
95+
----------
96+
gateway : str | UUID
97+
The gateway name or ID.
98+
"""
7999

80-
gateway_id = resolve_gateway_id(gateway)
100+
gateway_id = _resolve_gateway_id(gateway)
81101
client = fabric.FabricRestClient()
82102
response = client.delete(f"/v1/gateways/{gateway_id}")
83103

@@ -88,10 +108,25 @@ def delete_gateway(gateway: str | UUID):
88108

89109

90110
def list_gateway_role_assigments(gateway: str | UUID) -> pd.DataFrame:
111+
"""
112+
Returns a list of gateway role assignments.
113+
114+
This is a wrapper function for the following API: `Gateways - List Gateway Role Assignments <https://learn.microsoft.com/rest/api/fabric/core/gateways/list-gateway-role-assignments>`_.
115+
116+
Parameters
117+
----------
118+
gateway : str | UUID
119+
The gateway name or ID.
120+
121+
Returns
122+
-------
123+
pandas.DataFrame
124+
A pandas dataframe showing a list of gateway role assignments.
125+
"""
91126

92-
gateway_id = resolve_gateway_id(gateway)
127+
gateway_id = _resolve_gateway_id(gateway)
93128
client = fabric.FabricRestClient()
94-
response = client.delete(f"/v1/gateways/{gateway_id}/roleAssignments")
129+
response = client.get(f"/v1/gateways/{gateway_id}/roleAssignments")
95130

96131
if response.status_code != 200:
97132
raise FabricHTTPException(response)
@@ -115,8 +150,20 @@ def list_gateway_role_assigments(gateway: str | UUID) -> pd.DataFrame:
115150

116151

117152
def delete_gateway_role_assignment(gateway: str | UUID, role_assignement_id: UUID):
153+
"""
154+
Delete the specified role assignment for the gateway.
118155
119-
gateway_id = resolve_gateway_id(gateway)
156+
This is a wrapper function for the following API: `Gateways - Delete Gateway Role Assignment <https://learn.microsoft.com/rest/api/fabric/core/gateways/delete-gateway-role-assignment>`_.
157+
158+
Parameters
159+
----------
160+
gateway : str | UUID
161+
The gateway name or ID.
162+
role_assignement_id : UUID
163+
The role assignment ID.
164+
"""
165+
166+
gateway_id = _resolve_gateway_id(gateway)
120167
client = fabric.FabricRestClient()
121168
response = client.delete(
122169
f"/v1/gateways/{gateway_id}/roleAssignments/{role_assignement_id}"
@@ -130,9 +177,9 @@ def delete_gateway_role_assignment(gateway: str | UUID, role_assignement_id: UUI
130177
)
131178

132179

133-
def delete_gateway_member(gateway: str | UUID, gateway_member: UUID):
180+
def _resolve_gateway_member_id(gateway: str | UUID, gateway_member: str | UUID) -> UUID:
134181

135-
gateway_id = resolve_gateway_id(gateway)
182+
gateway_id = _resolve_gateway_id(gateway)
136183
dfM = list_gateway_members(gateway=gateway_id)
137184

138185
if _is_valid_uuid(gateway_member):
@@ -143,7 +190,28 @@ def delete_gateway_member(gateway: str | UUID, gateway_member: UUID):
143190
raise ValueError(
144191
f"{icons.red_dot} The '{gateway_member}' gateway member does not exist within the '{gateway}' gateway."
145192
)
146-
member_id = dfM_filt["Member Id"].iloc[0]
193+
194+
return dfM_filt["Member Id"].iloc[0]
195+
196+
197+
def delete_gateway_member(gateway: str | UUID, gateway_member: str | UUID):
198+
"""
199+
Delete gateway member of an on-premises gateway.
200+
201+
This is a wrapper function for the following API: `Gateways - Delete Gateway Member <https://learn.microsoft.com/rest/api/fabric/core/gateways/delete-gateway-member>`_.
202+
203+
Parameters
204+
----------
205+
gateway : str | UUID
206+
The gateway name or ID.
207+
gateway_member : str | UUID
208+
The gateway member name or ID.
209+
"""
210+
211+
gateway_id = _resolve_gateway_id(gateway)
212+
member_id = _resolve_gateway_member_id(
213+
gateway=gateway_id, gateway_member=gateway_member
214+
)
147215

148216
client = fabric.FabricRestClient()
149217
response = client.delete(f"/v1/gateways/{gateway_id}/members/{member_id}")
@@ -157,8 +225,23 @@ def delete_gateway_member(gateway: str | UUID, gateway_member: UUID):
157225

158226

159227
def list_gateway_members(gateway: str | UUID) -> pd.DataFrame:
228+
"""
229+
Lists gateway members of an on-premises gateway.
230+
231+
This is a wrapper function for the following API: `Gateways - List Gateway Members <https://learn.microsoft.com/rest/api/fabric/core/gateways/list-gateway-members>`_.
160232
161-
gateway_id = resolve_gateway_id(gateway)
233+
Parameters
234+
----------
235+
gateway : str | UUID
236+
The gateway name or ID.
237+
238+
Returns
239+
-------
240+
pandas.DataFrame
241+
A pandas dataframe showing a list of gateway members of an on-premises gateway.
242+
"""
243+
244+
gateway_id = _resolve_gateway_id(gateway)
162245
client = fabric.FabricRestClient()
163246
response = client.get(f"/v1/gateways/{gateway_id}/members")
164247

@@ -191,17 +274,43 @@ def list_gateway_members(gateway: str | UUID) -> pd.DataFrame:
191274
bool_cols = ["Enabled"]
192275
df[bool_cols] = df[bool_cols].astype(bool)
193276

277+
return df
278+
194279

195280
def create_vnet_gateway(
196281
name: str,
197282
capacity: str | UUID,
198283
inactivity_minutes_before_sleep: int,
199284
number_of_member_gateways: int,
200-
subscription_id: UUID,
285+
subscription_id: str,
201286
resource_group: str,
202287
virtual_network: str,
203288
subnet: str,
204289
):
290+
"""
291+
Creates a virtual network gateway.
292+
293+
This is a wrapper function for the following API: `Gateways - Create Gateway <https://learn.microsoft.com/rest/api/fabric/core/gateways/create-gateway>`_.
294+
295+
Parameters
296+
----------
297+
name : str
298+
The gateway name.
299+
capacity : str | UUID
300+
The capacity name or Id.
301+
inactivity_minutes_before_sleep : int
302+
The minutes of inactivity before the virtual network gateway goes into auto-sleep. Must be one of the following values: 30, 60, 90, 120, 150, 240, 360, 480, 720, 1440.
303+
number_of_member_gateways: int
304+
The number of member gateways. A number between 1 and 7.
305+
subscription_id : str
306+
The subscription ID.
307+
resource_group : str
308+
The name of the resource group.
309+
virtual_network : str
310+
The name of the virtual network.
311+
subnet : str
312+
The name of the subnet.
313+
"""
205314

206315
client = fabric.FabricRestClient()
207316

@@ -229,17 +338,30 @@ def create_vnet_gateway(
229338
)
230339

231340

232-
# def add_gateway_role_assignment(gateway : str | UUID)\:
233-
234-
235341
def update_on_premises_gateway(
236342
gateway: str,
237343
allow_cloud_connection_refresh: Optional[bool] = None,
238344
allow_custom_connectors: Optional[bool] = None,
239345
load_balancing_setting: Optional[str] = None,
240346
):
347+
"""
348+
Updates an on-premises gateway.
241349
242-
gateway_id = resolve_gateway_id(gateway)
350+
This is a wrapper function for the following API: `Gateways - Update Gateway <https://learn.microsoft.com/rest/api/fabric/core/gateways/update-gateway>`_.
351+
352+
Parameters
353+
----------
354+
gateway : str | UUID
355+
The gateway name or ID.
356+
allow_cloud_connection_refresh : bool, default=None
357+
Whether to allow cloud connections to refresh through this on-premises gateway. True - Allow, False - Do not allow.
358+
allow_custom_connectors : bool, default=None
359+
Whether to allow custom connectors to be used with this on-premises gateway. True - Allow, False - Do not allow.
360+
load_balancing_setting : str, default=None
361+
The `load balancing setting <https://learn.microsoft.com/rest/api/fabric/core/gateways/update-gateway?tabs=HTTP#loadbalancingsetting>`_ of the on-premises gateway.
362+
"""
363+
364+
gateway_id = _resolve_gateway_id(gateway)
243365

244366
payload = {}
245367

@@ -272,8 +394,24 @@ def update_vnet_gateway(
272394
inactivity_minutes_before_sleep: Optional[int] = None,
273395
number_of_member_gateways: Optional[int] = None,
274396
):
275-
276-
gateway_id = resolve_gateway_id(gateway)
397+
"""
398+
Updates a virtual network gateway.
399+
400+
This is a wrapper function for the following API: `Gateways - Update Gateway <https://learn.microsoft.com/rest/api/fabric/core/gateways/update-gateway>`_.
401+
402+
Parameters
403+
----------
404+
gateway : str | UUID
405+
The gateway name or ID.
406+
capacity: str | UUID
407+
The capacity name or ID.
408+
inactivity_minutes_before_sleep : int, default=None
409+
The minutes of inactivity before the virtual network gateway goes into auto-sleep. Must be one of the following values: 30, 60, 90, 120, 150, 240, 360, 480, 720, 1440.
410+
number_of_member_gateways : int, default=None
411+
The number of member gateways. A number between 1 and 7.
412+
"""
413+
414+
gateway_id = _resolve_gateway_id(gateway)
277415

278416
payload = {}
279417

0 commit comments

Comments
 (0)