msfabricpysdkcore 0.0.13__py3-none-any.whl → 0.1.1__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/admin_item.py +18 -44
- msfabricpysdkcore/admin_workspace.py +13 -60
- msfabricpysdkcore/adminapi.py +398 -475
- msfabricpysdkcore/client.py +115 -1
- msfabricpysdkcore/coreapi.py +2566 -821
- msfabricpysdkcore/deployment_pipeline.py +34 -146
- msfabricpysdkcore/domain.py +20 -219
- msfabricpysdkcore/environment.py +13 -172
- msfabricpysdkcore/item.py +55 -331
- msfabricpysdkcore/job_instance.py +8 -22
- msfabricpysdkcore/lakehouse.py +9 -118
- msfabricpysdkcore/long_running_operation.py +7 -37
- msfabricpysdkcore/onelakeshortcut.py +7 -21
- msfabricpysdkcore/otheritems.py +66 -91
- msfabricpysdkcore/spark_custom_pool.py +7 -47
- msfabricpysdkcore/tests/test_admin_apis.py +1 -1
- msfabricpysdkcore/tests/test_datapipelines.py +14 -17
- msfabricpysdkcore/tests/test_deployment_pipeline.py +3 -3
- msfabricpysdkcore/tests/test_domains.py +4 -3
- msfabricpysdkcore/tests/test_environments.py +51 -2
- msfabricpysdkcore/tests/test_evenhouses.py +48 -0
- msfabricpysdkcore/tests/test_evenstreams.py +1 -1
- msfabricpysdkcore/tests/test_items.py +80 -0
- msfabricpysdkcore/tests/test_kql_queryset.py +50 -0
- msfabricpysdkcore/tests/test_kqldatabases.py +1 -1
- msfabricpysdkcore/tests/test_lakehouse.py +86 -0
- msfabricpysdkcore/tests/test_ml_experiments.py +48 -0
- msfabricpysdkcore/tests/test_ml_models.py +48 -0
- msfabricpysdkcore/tests/test_notebooks.py +58 -0
- msfabricpysdkcore/tests/test_other_items.py +46 -0
- msfabricpysdkcore/tests/test_reports.py +53 -0
- msfabricpysdkcore/tests/test_semantic_model.py +51 -0
- msfabricpysdkcore/tests/test_spark.py +7 -5
- msfabricpysdkcore/tests/test_sparkjobdefinition.py +1 -1
- msfabricpysdkcore/tests/test_warehouses.py +51 -0
- msfabricpysdkcore/tests/test_workspaces_capacities.py +7 -4
- msfabricpysdkcore/workspace.py +397 -1163
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/METADATA +9 -8
- msfabricpysdkcore-0.1.1.dist-info/RECORD +52 -0
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/WHEEL +1 -1
- msfabricpysdkcore-0.0.13.dist-info/RECORD +0 -41
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.13.dist-info → msfabricpysdkcore-0.1.1.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/client.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
from abc import abstractmethod
|
1
2
|
import os
|
2
3
|
from time import sleep
|
4
|
+
import requests
|
5
|
+
import json
|
3
6
|
|
4
7
|
from msfabricpysdkcore.auth import FabricAuthClient, FabricServicePrincipal, FabricSparkUtilsAuthentication
|
5
8
|
|
@@ -23,4 +26,115 @@ class FabricClient():
|
|
23
26
|
self.auth = FabricServicePrincipal(tenant_id = self.tenant_id,
|
24
27
|
client_id = self.client_id,
|
25
28
|
client_secret = self.client_secret,
|
26
|
-
silent=silent)
|
29
|
+
silent=silent)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def calling_routine(self, url, operation, body = None, headers=None, file_path = None, response_codes = [200], error_message = "Error",
|
34
|
+
continue_on_error_code = False, return_format = "value_json", paging = False,
|
35
|
+
wait_for_completion = True, continuation_token = None):
|
36
|
+
"""Routine to make API calls
|
37
|
+
Args:
|
38
|
+
url (str): The URL of the API
|
39
|
+
operation (str): The operation to perform
|
40
|
+
body (dict): The body of the request
|
41
|
+
response_codes (list): The response codes to expect
|
42
|
+
error_message (str): The error message
|
43
|
+
continue_on_error_code (bool): Whether to continue on error code
|
44
|
+
return_format (str): The format of the return
|
45
|
+
paging (bool): Whether to paginate
|
46
|
+
wait_for_completion (bool): Whether to wait for the operation to complete
|
47
|
+
Returns:
|
48
|
+
dict: The response
|
49
|
+
"""
|
50
|
+
original_url = url
|
51
|
+
|
52
|
+
if continuation_token:
|
53
|
+
last_part_url = url.split("/")[-1]
|
54
|
+
if "?" not in last_part_url:
|
55
|
+
continuation_token = f"?continuationToken={continuation_token}"
|
56
|
+
else:
|
57
|
+
continuation_token = f"&continuationToken={continuation_token}"
|
58
|
+
url = f"{url}{continuation_token}"
|
59
|
+
|
60
|
+
response_codes.append(429)
|
61
|
+
if headers is None:
|
62
|
+
headers = self.auth.get_headers()
|
63
|
+
for _ in range(10):
|
64
|
+
if operation == "GET":
|
65
|
+
response = requests.get(url=url, headers=headers)
|
66
|
+
elif operation == "PATCH":
|
67
|
+
if body is None:
|
68
|
+
response = requests.patch(url=url, headers=headers)
|
69
|
+
else:
|
70
|
+
response = requests.patch(url=url, headers=headers, json=body)
|
71
|
+
elif operation == "POST":
|
72
|
+
if body is not None:
|
73
|
+
response = requests.post(url=url, headers=headers, json=body)
|
74
|
+
elif file_path is not None:
|
75
|
+
headers.pop('Content-Type')
|
76
|
+
with open(file_path, 'rb') as f:
|
77
|
+
files = {"file": f}
|
78
|
+
response = requests.post(url=url, files=files, headers=headers)
|
79
|
+
else:
|
80
|
+
response = requests.post(url=url, headers=headers)
|
81
|
+
elif operation == "PUT":
|
82
|
+
if body is None:
|
83
|
+
response = requests.put(url=url, headers=headers)
|
84
|
+
else:
|
85
|
+
response = requests.put(url=url, headers=headers, json=body)
|
86
|
+
elif operation == "DELETE":
|
87
|
+
response = requests.delete(url=url, headers=headers)
|
88
|
+
else:
|
89
|
+
raise ValueError("Invalid operation")
|
90
|
+
if response.status_code == 429:
|
91
|
+
print("Too many requests, waiting 10 seconds")
|
92
|
+
sleep(10)
|
93
|
+
continue
|
94
|
+
elif response.status_code == 202:
|
95
|
+
if wait_for_completion:
|
96
|
+
operation_result = self.long_running_operation(response.headers)
|
97
|
+
if "operation_result" in return_format:
|
98
|
+
return operation_result
|
99
|
+
return response
|
100
|
+
elif response.status_code not in response_codes:
|
101
|
+
if continue_on_error_code:
|
102
|
+
return response
|
103
|
+
raise Exception(f"{error_message}: {response.status_code} {response.text}")
|
104
|
+
break
|
105
|
+
|
106
|
+
if paging:
|
107
|
+
resp_dict = json.loads(response.text)
|
108
|
+
|
109
|
+
if return_format in ["data", "itemEntities", "Overrides", "accessEntities", "workspaces"]:
|
110
|
+
items = resp_dict[return_format]
|
111
|
+
else:
|
112
|
+
items = resp_dict["value"]
|
113
|
+
|
114
|
+
|
115
|
+
if "continuationToken" in resp_dict and resp_dict["continuationToken"]:
|
116
|
+
continuation_token = resp_dict["continuationToken"]
|
117
|
+
items_next = self.calling_routine(url=original_url, operation=operation, body=body, headers=headers,
|
118
|
+
response_codes=response_codes,
|
119
|
+
error_message=error_message, continuation_token=continuation_token,
|
120
|
+
return_format=return_format, paging=True, wait_for_completion=wait_for_completion)
|
121
|
+
items.extend(items_next)
|
122
|
+
if "etag" in return_format:
|
123
|
+
return items, response.headers.get('ETag')
|
124
|
+
return items
|
125
|
+
|
126
|
+
if "value_json" in return_format:
|
127
|
+
resp_dict = json.loads(response.text)
|
128
|
+
if "etag" in return_format:
|
129
|
+
return resp_dict["value"], response.headers.get('ETag')
|
130
|
+
return resp_dict["value"]
|
131
|
+
|
132
|
+
if "json" in return_format:
|
133
|
+
return json.loads(response.text)
|
134
|
+
|
135
|
+
return response
|
136
|
+
|
137
|
+
@abstractmethod
|
138
|
+
def long_running_operation(self, headers):
|
139
|
+
"""Long running operation"""
|
140
|
+
pass
|