msfabricpysdkcore 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msfabricpysdkcore/__init__.py +2 -1
- msfabricpysdkcore/admin_item.py +106 -0
- msfabricpysdkcore/admin_workspace.py +127 -0
- msfabricpysdkcore/adminapi.py +535 -0
- msfabricpysdkcore/capacity.py +56 -0
- msfabricpysdkcore/client.py +4 -265
- msfabricpysdkcore/coreapi.py +324 -0
- msfabricpysdkcore/domain.py +378 -0
- msfabricpysdkcore/item.py +19 -1
- msfabricpysdkcore/job_instance.py +3 -0
- msfabricpysdkcore/lakehouse.py +96 -0
- msfabricpysdkcore/onelakeshortcut.py +3 -0
- msfabricpysdkcore/tests/__init__.py +0 -0
- msfabricpysdkcore/tests/test_admin_apis.py +69 -0
- msfabricpysdkcore/tests/test_domains.py +125 -0
- msfabricpysdkcore/tests/test_git.py +62 -0
- msfabricpysdkcore/tests/test_items_incl_lakehouse.py +69 -0
- msfabricpysdkcore/tests/test_jobs.py +39 -0
- msfabricpysdkcore/tests/test_shortcuts.py +53 -0
- msfabricpysdkcore/tests/test_workspaces_capacities.py +146 -0
- msfabricpysdkcore/workspace.py +47 -7
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/METADATA +201 -19
- msfabricpysdkcore-0.0.4.dist-info/RECORD +28 -0
- msfabricpysdkcore-0.0.2.dist-info/RECORD +0 -13
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/WHEEL +0 -0
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/__init__.py
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
from .
|
1
|
+
from .coreapi import FabricClientCore
|
2
|
+
from .adminapi import FabricClientAdmin
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import json
|
2
|
+
from time import sleep
|
3
|
+
|
4
|
+
import requests
|
5
|
+
|
6
|
+
|
7
|
+
class AdminItem:
|
8
|
+
"""Class to represent a item in Microsoft Fabric"""
|
9
|
+
|
10
|
+
def __init__(self, id, type, name, workspace_id, state, description, last_updated_date, capacity_id, creator_principal, auth) -> None:
|
11
|
+
"""Constructor for the Item class
|
12
|
+
|
13
|
+
Args:
|
14
|
+
id (str): The ID of the item
|
15
|
+
type (str): The type of the item
|
16
|
+
name (str): The name of the item
|
17
|
+
workspace_id (str): The ID of the workspace
|
18
|
+
state (str): The state of the item
|
19
|
+
description (str): The description of the item
|
20
|
+
last_updated_date (str): The last updated date of the item
|
21
|
+
capacity_id (str): The ID of the capacity
|
22
|
+
creator_principal (dict): The creator principal of the item
|
23
|
+
auth (Auth): The Auth object
|
24
|
+
Returns:
|
25
|
+
Item: The Item object
|
26
|
+
"""
|
27
|
+
self.id = id
|
28
|
+
self.type = type
|
29
|
+
self.name = name
|
30
|
+
self.workspace_id = workspace_id
|
31
|
+
self.state = state
|
32
|
+
self.description = description
|
33
|
+
self.last_updated_date = last_updated_date
|
34
|
+
self.capacity_id = capacity_id
|
35
|
+
self.creator_principal = creator_principal
|
36
|
+
self.auth = auth
|
37
|
+
|
38
|
+
|
39
|
+
def __str__(self) -> str:
|
40
|
+
"""Return a string representation of the workspace object
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
str: The string representation of the workspace object
|
44
|
+
"""
|
45
|
+
dict_ = {
|
46
|
+
'id': self.id,
|
47
|
+
'type': self.type,
|
48
|
+
'name': self.name,
|
49
|
+
'workspace_id': self.workspace_id,
|
50
|
+
'state': self.state,
|
51
|
+
'description': self.description,
|
52
|
+
'last_updated_date': self.last_updated_date,
|
53
|
+
'capacity_id': self.capacity_id,
|
54
|
+
'creator_principal': self.creator_principal
|
55
|
+
}
|
56
|
+
return json.dumps(dict_, indent=2)
|
57
|
+
|
58
|
+
|
59
|
+
def __repr__(self) -> str:
|
60
|
+
return self.__str__()
|
61
|
+
|
62
|
+
def from_dict(item_dict, auth):
|
63
|
+
"""Create Item object from dictionary
|
64
|
+
|
65
|
+
Args:
|
66
|
+
item_dict (dict): The dictionary containing the item information
|
67
|
+
auth (Auth): The Auth object
|
68
|
+
Returns:
|
69
|
+
Item: The Item object"""
|
70
|
+
return AdminItem(
|
71
|
+
id = item_dict['id'],
|
72
|
+
type = item_dict['type'],
|
73
|
+
name = item_dict['name'],
|
74
|
+
workspace_id = item_dict['workspaceId'],
|
75
|
+
state = item_dict['state'],
|
76
|
+
description = item_dict.get('description', None),
|
77
|
+
last_updated_date = item_dict['lastUpdatedDate'],
|
78
|
+
capacity_id = item_dict['capacityId'],
|
79
|
+
creator_principal = item_dict['creatorPrincipal'],
|
80
|
+
auth = auth
|
81
|
+
)
|
82
|
+
|
83
|
+
def get_item_access_details(self, type=None):
|
84
|
+
"""Get the access details of the item
|
85
|
+
|
86
|
+
Returns:
|
87
|
+
dict: The access details of the item"""
|
88
|
+
|
89
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.workspace_id}/items/{self.id}/users"
|
90
|
+
|
91
|
+
if type:
|
92
|
+
url += f"?type={self.type}"
|
93
|
+
|
94
|
+
for _ in range(10):
|
95
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
96
|
+
if response.status_code == 429:
|
97
|
+
print("Too many requests, waiting 10 seconds")
|
98
|
+
sleep(10)
|
99
|
+
continue
|
100
|
+
if response.status_code not in (200, 429):
|
101
|
+
print(response.status_code)
|
102
|
+
print(response.text)
|
103
|
+
raise Exception(f"Error getting item: {response.text}")
|
104
|
+
break
|
105
|
+
|
106
|
+
return json.loads(response.text)
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import json
|
2
|
+
from time import sleep
|
3
|
+
|
4
|
+
import requests
|
5
|
+
|
6
|
+
from msfabricpysdkcore.admin_item import AdminItem
|
7
|
+
|
8
|
+
|
9
|
+
class AdminWorkspace:
|
10
|
+
"""Class to represent a workspace in Microsoft Fabric"""
|
11
|
+
|
12
|
+
def __init__(self, id, type, name, state, capacity_id, auth) -> None:
|
13
|
+
"""Constructor for the Workspace class
|
14
|
+
|
15
|
+
Args:
|
16
|
+
id (str): The ID of the workspace
|
17
|
+
type (str): The type of the workspace
|
18
|
+
name (str): The name of the workspace
|
19
|
+
state (str): The state of the workspace
|
20
|
+
capacity_id (str): The ID of the capacity
|
21
|
+
auth (Auth): The Auth object
|
22
|
+
Returns:
|
23
|
+
Workspace: The Workspace object
|
24
|
+
"""
|
25
|
+
self.id = id
|
26
|
+
self.type = type
|
27
|
+
self.name = name
|
28
|
+
self.state = state
|
29
|
+
self.capacity_id = capacity_id
|
30
|
+
self.auth = auth
|
31
|
+
|
32
|
+
|
33
|
+
def __str__(self) -> str:
|
34
|
+
"""Return a string representation of the workspace object
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
str: The string representation of the workspace object
|
38
|
+
"""
|
39
|
+
dict_ = {
|
40
|
+
'id': self.id,
|
41
|
+
'type': self.type,
|
42
|
+
'name': self.name,
|
43
|
+
'state': self.state,
|
44
|
+
'capacity_id': self.capacity_id
|
45
|
+
}
|
46
|
+
return json.dumps(dict_, indent=2)
|
47
|
+
|
48
|
+
|
49
|
+
def __repr__(self) -> str:
|
50
|
+
return self.__str__()
|
51
|
+
|
52
|
+
def from_dict(item_dict, auth):
|
53
|
+
"""Create Workspace object from dictionary
|
54
|
+
|
55
|
+
Args:
|
56
|
+
item_dict (dict): The dictionary representing the workspace
|
57
|
+
auth (Auth): The Auth object
|
58
|
+
Returns:
|
59
|
+
Workspace: The Workspace object
|
60
|
+
"""
|
61
|
+
return AdminWorkspace(
|
62
|
+
id=item_dict['id'],
|
63
|
+
type=item_dict['type'],
|
64
|
+
name=item_dict['name'],
|
65
|
+
state=item_dict['state'],
|
66
|
+
capacity_id=item_dict['capacityId'],
|
67
|
+
auth=auth
|
68
|
+
)
|
69
|
+
|
70
|
+
def get_workspace_access_details(self):
|
71
|
+
"""Get the access details of the workspace
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
dict: The access details of the workspace
|
75
|
+
"""
|
76
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.id}/users"
|
77
|
+
|
78
|
+
for _ in range(10):
|
79
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
80
|
+
if response.status_code == 429:
|
81
|
+
print("Too many requests, waiting 10 seconds")
|
82
|
+
sleep(10)
|
83
|
+
continue
|
84
|
+
if response.status_code not in (200, 429):
|
85
|
+
print(response.status_code)
|
86
|
+
print(response.text)
|
87
|
+
raise Exception(f"Error getting workspace: {response.text}")
|
88
|
+
break
|
89
|
+
|
90
|
+
return json.loads(response.text)
|
91
|
+
|
92
|
+
def get_item(self, item_id, type = None):
|
93
|
+
"""Get an item from the workspace
|
94
|
+
|
95
|
+
Args:
|
96
|
+
item_id (str): The ID of the item
|
97
|
+
type (str): The type of the item
|
98
|
+
Returns:
|
99
|
+
AdminItem: The item object
|
100
|
+
"""
|
101
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.id}/items/{item_id}"
|
102
|
+
if type:
|
103
|
+
url += f"?type={type}"
|
104
|
+
for _ in range(10):
|
105
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
106
|
+
if response.status_code == 429:
|
107
|
+
print("Too many requests, waiting 10 seconds")
|
108
|
+
sleep(10)
|
109
|
+
continue
|
110
|
+
if response.status_code not in (200, 429):
|
111
|
+
print(response.status_code)
|
112
|
+
print(response.text)
|
113
|
+
raise Exception(f"Error getting item: {response.text}")
|
114
|
+
break
|
115
|
+
item_dict = json.loads(response.text)
|
116
|
+
return AdminItem.from_dict(item_dict, self.auth)
|
117
|
+
|
118
|
+
def get_item_access_details(self, item_id, type=None):
|
119
|
+
"""Get the access details of the item
|
120
|
+
|
121
|
+
Args:
|
122
|
+
item_id (str): The ID of the item
|
123
|
+
type (str): The type of the item
|
124
|
+
Returns:
|
125
|
+
dict: The access details of the item
|
126
|
+
"""
|
127
|
+
return self.get_item(item_id, type).get_item_access_details()
|