msfabricpysdkcore 0.0.11__py3-none-any.whl → 0.0.12__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.
@@ -81,10 +81,10 @@ class FabricClientCore(FabricClient):
81
81
  return self.get_workspace_by_name(name)
82
82
  raise ValueError("Either id or name must be provided")
83
83
 
84
- def get_workspace_role_assignments(self, workspace_id):
84
+ def list_workspace_role_assignments(self, workspace_id):
85
85
  """Get role assignments for a workspace"""
86
86
  ws = self.get_workspace_by_id(workspace_id)
87
- return ws.get_role_assignments()
87
+ return ws.list_role_assignments()
88
88
 
89
89
  def create_workspace(self, display_name, capacity_id = None, description = None, exists_ok = True):
90
90
  """Create a workspace"""
@@ -129,20 +129,25 @@ class FabricClientCore(FabricClient):
129
129
  ws = self.get_workspace_by_id(workspace_id)
130
130
  return ws.add_role_assignment(role, principal)
131
131
 
132
- def delete_workspace_role_assignment(self, workspace_id, principal_id):
132
+ def delete_workspace_role_assignment(self, workspace_id, workspace_role_assignment_id):
133
133
  """Delete a role assignment from a workspace"""
134
134
  ws = self.get_workspace_by_id(workspace_id)
135
- return ws.delete_role_assignment(principal_id)
135
+ return ws.delete_role_assignment(workspace_role_assignment_id)
136
136
 
137
137
  def update_workspace(self, workspace_id, display_name = None, description = None):
138
138
  """Update a workspace"""
139
139
  ws = self.get_workspace_by_id(workspace_id)
140
140
  return ws.update(display_name, description)
141
+
142
+ def get_workspace_role_assignment(self, workspace_id, workspace_role_assignment_id):
143
+ """Get a role assignment for a workspace"""
144
+ ws = self.get_workspace_by_id(workspace_id)
145
+ return ws.get_role_assignment(workspace_role_assignment_id)
141
146
 
142
- def update_workspace_role_assignment(self, workspace_id, role, principal_id):
147
+ def update_workspace_role_assignment(self, workspace_id, role, workspace_role_assignment_id):
143
148
  """Update a role assignment for a workspace"""
144
149
  ws = self.get_workspace_by_id(workspace_id)
145
- return ws.update_role_assignment(role, principal_id)
150
+ return ws.update_role_assignment(role, workspace_role_assignment_id)
146
151
 
147
152
  def assign_to_capacity(self, workspace_id, capacity_id):
148
153
  """Assign a workspace to a capacity"""
@@ -153,6 +158,16 @@ class FabricClientCore(FabricClient):
153
158
  """Unassign a workspace from a capacity"""
154
159
  ws = self.get_workspace_by_id(workspace_id)
155
160
  return ws.unassign_from_capacity()
161
+
162
+ def provision_identity(self, workspace_id):
163
+ """Provision an identity for a workspace"""
164
+ ws = self.get_workspace_by_id(workspace_id)
165
+ return ws.provision_identity()
166
+
167
+ def deprovision_identity(self, workspace_id):
168
+ """Deprovision an identity for a workspace"""
169
+ ws = self.get_workspace_by_id(workspace_id)
170
+ return ws.deprovision_identity()
156
171
 
157
172
  def list_capacities(self, continuationToken = None):
158
173
  """List all capacities in the tenant"""
@@ -809,6 +824,11 @@ class FabricClientCore(FabricClient):
809
824
  ws = self.get_workspace_by_id(workspace_id)
810
825
  return ws.update_spark_job_definition_definition(spark_job_definition_id, definition)
811
826
 
827
+ def run_on_demand_spark_job_definition(self, workspace_id, spark_job_definition_id, job_type = "sparkjob"):
828
+ """Run an on demand spark job definition"""
829
+ ws = self.get_workspace_by_id(workspace_id)
830
+ return ws.run_on_demand_spark_job_definition(spark_job_definition_id, job_type)
831
+
812
832
  # warehouses
813
833
 
814
834
  def list_warehouses(self, workspace_id, with_properties = False):
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import requests
3
- from time import sleep
3
+ from time import sleep, time
4
4
 
5
5
  class LongRunningOperation:
6
6
  """Class to represent a workspace in Microsoft Fabric"""
@@ -49,12 +49,17 @@ class LongRunningOperation:
49
49
  def wait_for_completion(self):
50
50
  """Wait for the operation to complete"""
51
51
  max_iter = 20
52
+ start_time = time()
52
53
  while self.state not in ('Succeeded', 'Failed'):
53
54
  self.state = self.get_operation_state()["status"]
55
+ duration = int(time() - start_time)
56
+ if duration > 60:
57
+
58
+ if self.state == "Running":
59
+ print(f"Operation did not complete after {duration} seconds")
60
+ return "Running"
61
+ raise Exception(f"Operation did not complete after {duration} seconds")
54
62
  sleep(3)
55
- if max_iter == 0:
56
- raise Exception("Operation did not complete after 60 seconds")
57
- max_iter -= 1
58
63
  return self.state
59
64
 
60
65
 
@@ -2,6 +2,7 @@ import json
2
2
  from time import sleep
3
3
  import requests
4
4
  from msfabricpysdkcore.item import Item
5
+ from msfabricpysdkcore.long_running_operation import check_long_running_operation
5
6
 
6
7
 
7
8
  class Eventhouse(Item):
@@ -52,6 +53,34 @@ class SparkJobDefinition(Item):
52
53
  def update_definition(self, definition):
53
54
  return super().update_definition(definition=definition, type="sparkJobDefinitions")
54
55
 
56
+ def run_on_demand_spark_job_definition(self, job_type = "sparkjob"):
57
+ # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/sparkJobDefinitions/{sparkJobDefinitionId}/jobs/instances?jobType={jobType}
58
+ """Method to run a spark job definition on demand"""
59
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/sparkJobDefinitions/{self.id}/jobs/instances?jobType={job_type}"
60
+
61
+ for _ in range(10):
62
+ response = requests.post(url=url, headers=self.auth.get_headers())
63
+ if response.status_code == 429:
64
+ print("Too many requests, waiting 10 seconds")
65
+ sleep(10)
66
+ continue
67
+ if response.status_code == 202:
68
+ location = response.headers['Location']
69
+ job_instance_id = location.split('/')[-1]
70
+
71
+ from msfabricpysdkcore import FabricClientCore
72
+ fc = FabricClientCore(silent=True)
73
+ fc.auth = self.auth
74
+ return fc.get_item_job_instance(workspace_id = self.workspace_id,
75
+ item_id = self.id,
76
+ job_instance_id = job_instance_id)
77
+ if response.status_code not in (200, 201, 202, 429):
78
+ raise Exception(f"Error running on demand spark job definition: {response.status_code}, {response.text}")
79
+ break
80
+
81
+ return response
82
+
83
+
55
84
  class Warehouse(Item):
56
85
  """Class to represent a warehouse in Microsoft Fabric"""
57
86
 
@@ -53,8 +53,7 @@ class TestFabricClientCore(unittest.TestCase):
53
53
  "itemType": item["itemType"]}
54
54
  items = [item]
55
55
 
56
-
57
- response = pipe.deploy(source_stage_id=dev_stage.id,target_stage_id=prod_stage.id, items=items)
56
+ response = fc.deploy_stage_content(deployment_pipeline_id=pipe_id, source_stage_id=dev_stage.id,target_stage_id=prod_stage.id, items=items)
58
57
 
59
58
  self.assertEqual(response["status"], "Succeeded")
60
59
 
@@ -30,7 +30,7 @@ class TestFabricClientCore(unittest.TestCase):
30
30
 
31
31
  status_code = self.fc.git_connect(workspace_id=ws2.id, git_provider_details=git_provider_details)
32
32
 
33
- self.assertEqual(status_code, 204)
33
+ self.assertEqual(status_code, 200)
34
34
 
35
35
  initialization_strategy = "PreferWorkspace"
36
36
 
@@ -56,7 +56,7 @@ class TestFabricClientCore(unittest.TestCase):
56
56
 
57
57
  status_code = self.fc.git_disconnect(workspace_id=ws2.id)
58
58
 
59
- self.assertEqual(status_code, 204)
59
+ self.assertEqual(status_code, 200)
60
60
 
61
61
  ws2.delete()
62
62
 
@@ -173,23 +173,24 @@ class TestFabricClientCore(unittest.TestCase):
173
173
 
174
174
  fc = self.fc
175
175
  workspace_id = 'd8a5abe0-9eed-406d-ab46-343bc57ddbe5'
176
-
177
- eventhouse1 = fc.create_eventhouse(workspace_id, display_name="eventhouse1")
178
- self.assertEqual(eventhouse1.display_name, "eventhouse1")
176
+ datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
177
+ eventhouse_name = "evh" + datetime_str
178
+ eventhouse1 = fc.create_eventhouse(workspace_id, display_name=eventhouse_name)
179
+ self.assertEqual(eventhouse1.display_name, eventhouse_name)
179
180
 
180
181
  eventhouses = fc.list_eventhouses(workspace_id)
181
182
  eventhouse_names = [eh.display_name for eh in eventhouses]
182
183
  self.assertGreater(len(eventhouses), 0)
183
- self.assertIn("eventhouse1", eventhouse_names)
184
+ self.assertIn(eventhouse_name, eventhouse_names)
184
185
 
185
- eh = fc.get_eventhouse(workspace_id, eventhouse_name="eventhouse1")
186
+ eh = fc.get_eventhouse(workspace_id, eventhouse_name=eventhouse_name)
186
187
  self.assertIsNotNone(eh.id)
187
- self.assertEqual(eh.display_name, "eventhouse1")
188
-
189
- eh2 = fc.update_eventhouse(workspace_id, eh.id, display_name="eventhouse2")
188
+ self.assertEqual(eh.display_name, eventhouse_name)
189
+ new_display_name = eventhouse_name + "2"
190
+ eh2 = fc.update_eventhouse(workspace_id, eh.id, display_name=new_display_name)
190
191
 
191
192
  eh = fc.get_eventhouse(workspace_id, eventhouse_id=eh.id)
192
- self.assertEqual(eh.display_name, "eventhouse2")
193
+ self.assertEqual(eh.display_name, new_display_name)
193
194
  self.assertEqual(eh.id, eh2.id)
194
195
 
195
196
  status_code = fc.delete_eventhouse(workspace_id, eh.id)
@@ -273,11 +274,11 @@ class TestFabricClientCore(unittest.TestCase):
273
274
  self.assertIsNotNone(mlm.id)
274
275
  self.assertEqual(mlm.display_name, model_name)
275
276
 
276
- # mlm2 = fc.update_ml_model(workspace_id=workspace_id,ml_model_id= mlm.id, description=model_name)
277
+ mlm2 = fc.update_ml_model(workspace_id=workspace_id,ml_model_id= mlm.id, description=model_name)
277
278
 
278
- # mlm = fc.get_ml_model(workspace_id, ml_model_id=mlm.id)
279
- # self.assertEqual(mlm.description, model_name)
280
- # self.assertEqual(mlm.id, mlm2.id)
279
+ mlm = fc.get_ml_model(workspace_id, ml_model_id=mlm.id)
280
+ self.assertEqual(mlm.description, model_name)
281
+ self.assertEqual(mlm.id, mlm2.id)
281
282
 
282
283
  status_code = fc.delete_ml_model(workspace_id, mlm.id)
283
284
  self.assertEqual(status_code, 200)
@@ -385,45 +386,6 @@ class TestFabricClientCore(unittest.TestCase):
385
386
  status_code = fc.delete_semantic_model(workspace_id, sm.id)
386
387
  self.assertEqual(status_code, 200)
387
388
 
388
-
389
- def test_spark_job_definitions(self):
390
-
391
- fc = self.fc
392
- workspace_id = 'd8a5abe0-9eed-406d-ab46-343bc57ddbe5'
393
-
394
- datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
395
- spark_job_definition_name = f"sjd{datetime_str}"
396
-
397
- spark_job_definition_w_content = fc.get_spark_job_definition(workspace_id, spark_job_definition_name="helloworld")
398
-
399
- definition = fc.get_spark_job_definition_definition(workspace_id, spark_job_definition_w_content.id)
400
-
401
- self.assertIsNotNone(definition)
402
- self.assertIn("definition", definition)
403
- definition = definition["definition"]
404
-
405
- spark_job_definition = fc.create_spark_job_definition(workspace_id, display_name=spark_job_definition_name)
406
- fc.update_spark_job_definition_definition(workspace_id, spark_job_definition.id, definition=definition)
407
- spark_job_definition = fc.get_spark_job_definition(workspace_id, spark_job_definition_id=spark_job_definition.id)
408
- self.assertEqual(spark_job_definition.display_name, spark_job_definition_name)
409
- self.assertIsNotNone(spark_job_definition.definition)
410
-
411
- spark_job_definitions = fc.list_spark_job_definitions(workspace_id)
412
- spark_job_definition_names = [sjd.display_name for sjd in spark_job_definitions]
413
- self.assertGreater(len(spark_job_definitions), 0)
414
- self.assertIn(spark_job_definition_name, spark_job_definition_names)
415
-
416
- sjd = fc.get_spark_job_definition(workspace_id, spark_job_definition_name=spark_job_definition_name)
417
- self.assertIsNotNone(sjd.id)
418
- self.assertEqual(sjd.display_name, spark_job_definition_name)
419
-
420
- sjd = fc.update_spark_job_definition(workspace_id, sjd.id, display_name=f"{spark_job_definition_name}2")
421
- sjd = fc.get_spark_job_definition(workspace_id, spark_job_definition_id=sjd.id)
422
- self.assertEqual(sjd.display_name, f"{spark_job_definition_name}2")
423
-
424
- status_code = fc.delete_spark_job_definition(workspace_id, sjd.id)
425
- self.assertEqual(status_code, 200)
426
-
427
389
  def test_warehouses(self):
428
390
 
429
391
  fc = self.fc
@@ -0,0 +1,55 @@
1
+ import unittest
2
+ from datetime import datetime
3
+ from dotenv import load_dotenv
4
+ from msfabricpysdkcore.coreapi import FabricClientCore
5
+
6
+ load_dotenv()
7
+
8
+ class TestFabricClientCore(unittest.TestCase):
9
+
10
+ def __init__(self, *args, **kwargs):
11
+ super(TestFabricClientCore, self).__init__(*args, **kwargs)
12
+ self.fc = FabricClientCore()
13
+
14
+ def test_spark_job_definitions(self):
15
+
16
+ fc = self.fc
17
+ workspace_id = 'd8a5abe0-9eed-406d-ab46-343bc57ddbe5'
18
+
19
+ datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
20
+ spark_job_definition_name = f"sjd{datetime_str}"
21
+
22
+ spark_job_definition_w_content = fc.get_spark_job_definition(workspace_id, spark_job_definition_name="helloworld")
23
+
24
+ result = fc.run_on_demand_spark_job_definition(workspace_id=workspace_id,
25
+ spark_job_definition_id=spark_job_definition_w_content.id,
26
+ job_type="sparkjob")
27
+ self.assertIsNotNone(result)
28
+ self.assertEqual(result.job_type, "sparkjob")
29
+ definition = fc.get_spark_job_definition_definition(workspace_id, spark_job_definition_w_content.id)
30
+
31
+ self.assertIsNotNone(definition)
32
+ self.assertIn("definition", definition)
33
+ definition = definition["definition"]
34
+
35
+ spark_job_definition = fc.create_spark_job_definition(workspace_id, display_name=spark_job_definition_name)
36
+ fc.update_spark_job_definition_definition(workspace_id, spark_job_definition.id, definition=definition)
37
+ spark_job_definition = fc.get_spark_job_definition(workspace_id, spark_job_definition_id=spark_job_definition.id)
38
+ self.assertEqual(spark_job_definition.display_name, spark_job_definition_name)
39
+ self.assertIsNotNone(spark_job_definition.definition)
40
+
41
+ spark_job_definitions = fc.list_spark_job_definitions(workspace_id)
42
+ spark_job_definition_names = [sjd.display_name for sjd in spark_job_definitions]
43
+ self.assertGreater(len(spark_job_definitions), 0)
44
+ self.assertIn(spark_job_definition_name, spark_job_definition_names)
45
+
46
+ sjd = fc.get_spark_job_definition(workspace_id, spark_job_definition_name=spark_job_definition_name)
47
+ self.assertIsNotNone(sjd.id)
48
+ self.assertEqual(sjd.display_name, spark_job_definition_name)
49
+
50
+ sjd = fc.update_spark_job_definition(workspace_id, sjd.id, display_name=f"{spark_job_definition_name}2")
51
+ sjd = fc.get_spark_job_definition(workspace_id, spark_job_definition_id=sjd.id)
52
+ self.assertEqual(sjd.display_name, f"{spark_job_definition_name}2")
53
+
54
+ status_code = fc.delete_spark_job_definition(workspace_id, sjd.id)
55
+ self.assertEqual(status_code, 200)
@@ -10,118 +10,128 @@ class TestFabricClientCore(unittest.TestCase):
10
10
  def __init__(self, *args, **kwargs):
11
11
  super(TestFabricClientCore, self).__init__(*args, **kwargs)
12
12
  self.fc = FabricClientCore()
13
- datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
14
- self.display_name = "testws" + datetime_str
15
- self.workspace_id = None
13
+
16
14
 
17
15
  def test_end_to_end_workspace(self):
18
-
19
- ws_created = self.fc.create_workspace(display_name=self.display_name,
16
+ fc = self.fc
17
+ datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
18
+ display_name = "testws" + datetime_str
19
+ ws_created = fc.create_workspace(display_name=display_name,
20
20
  description="test workspace",
21
21
  exists_ok=False)
22
22
  # Add assertions here to verify the result
23
- self.assertEqual(ws_created.display_name, self.display_name)
24
- self.workspace_id = ws_created.id
25
- ws = self.fc.get_workspace_by_id(id = self.workspace_id)
26
- self.assertEqual(ws.display_name, self.display_name)
23
+ self.assertEqual(ws_created.display_name, display_name)
24
+ workspace_id = ws_created.id
25
+ ws = fc.get_workspace_by_id(id = workspace_id)
26
+ self.assertEqual(ws.display_name, display_name)
27
27
  self.assertEqual(ws.description, "test workspace")
28
28
 
29
29
  # def test_assign_to_capacity(self):
30
30
 
31
- result_status_code = self.fc.assign_to_capacity(workspace_id=ws.id,
31
+ result_status_code = fc.assign_to_capacity(workspace_id=ws.id,
32
32
  capacity_id="41cb829c-c231-4e9f-b4fc-f9042a6f9840")
33
33
  self.assertEqual(result_status_code, 202)
34
34
 
35
35
 
36
36
  # def test_list_workspaces(self):
37
37
 
38
- result = self.fc.list_workspaces()
38
+ result = fc.list_workspaces()
39
39
  display_names = [ws.display_name for ws in result]
40
- self.assertIn(self.display_name, display_names)
40
+ self.assertIn(display_name, display_names)
41
41
 
42
42
  for ws in result:
43
- if ws.display_name == self.display_name:
43
+ if ws.display_name == display_name:
44
44
  self.assertEqual(ws.capacity_id, "41cb829c-c231-4e9f-b4fc-f9042a6f9840")
45
45
 
46
46
 
47
47
  # def test_get_workspace_by_name(self):
48
48
 
49
- workspace_name = self.display_name
50
- ws = self.fc.get_workspace_by_name(name = workspace_name)
51
- self.assertEqual(ws.display_name, self.display_name)
49
+ workspace_name = display_name
50
+ ws = fc.get_workspace_by_name(name = workspace_name)
51
+ self.assertEqual(ws.display_name, display_name)
52
52
 
53
53
  # def test_get_workspace_by_id(self):
54
- ws = self.fc.get_workspace_by_id(id = self.workspace_id)
55
- self.assertEqual(self.display_name, ws.display_name)
54
+ ws = fc.get_workspace_by_id(id = workspace_id)
55
+ self.assertEqual(display_name, ws.display_name)
56
56
 
57
57
 
58
58
  # def test_get_workspace(self):
59
- result = self.fc.get_workspace_by_id(id = self.workspace_id)
60
- self.assertEqual(result.display_name, self.display_name)
59
+ result = fc.get_workspace_by_id(id = workspace_id)
60
+ self.assertEqual(result.display_name, display_name)
61
61
 
62
62
  # def test_add_role_assignment(self):
63
- result_status = self.fc.add_workspace_role_assignment(workspace_id = ws.id,
64
- principal = {"id" : "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69",
65
- "type" : "ServicePrincipal"},
66
- role = 'Member')
63
+ result_status = fc.add_workspace_role_assignment(workspace_id = ws.id,
64
+ principal = {"id" : "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69",
65
+ "type" : "ServicePrincipal"},
66
+ role = 'Member')
67
67
 
68
- self.assertEqual(result_status, 200)
68
+ self.assertEqual(result_status, 201)
69
69
 
70
70
  # def test_get_workspace_role_assignments(self):
71
- result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
72
- self.assertTrue("value" in result)
73
- self.assertTrue(len(result["value"]) == 2)
74
- for user in result["value"]:
71
+ result = fc.list_workspace_role_assignments(workspace_id = ws.id)
72
+ self.assertTrue(len(result) == 2)
73
+ for user in result:
75
74
  if user["principal"]["displayName"] == "fabrictestuser":
76
- self.assertTrue(user["role"] == "Member")
75
+ self.assertEqual(user["role"], "Member")
76
+
77
+ # Get get_workspace_role_assignment
78
+
79
+ result = fc.get_workspace_role_assignment(workspace_id = ws.id,
80
+ workspace_role_assignment_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
81
+
82
+ self.assertEqual(result["role"], "Member")
77
83
 
78
84
  # def test_update_workspace_role_assignment(self):
79
85
 
80
- result_status_code = self.fc.update_workspace_role_assignment(workspace_id = ws.id,
86
+ result_status_code = fc.update_workspace_role_assignment(workspace_id = ws.id,
81
87
  role = "Contributor",
82
- principal_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
88
+ workspace_role_assignment_id= "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
83
89
 
84
90
  self.assertEqual(result_status_code, 200)
85
91
 
86
- result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
87
- self.assertTrue("value" in result)
88
- self.assertTrue(len(result["value"]) == 2)
89
- for user in result["value"]:
92
+ result = fc.list_workspace_role_assignments(workspace_id = ws.id)
93
+ self.assertTrue(len(result) == 2)
94
+ for user in result:
90
95
  if user["principal"]["displayName"] == "fabrictestuser":
91
96
  self.assertTrue(user["role"] == "Contributor")
92
97
 
93
98
  # def test_delete_role_assignment(self):
94
- result_status_code = self.fc.delete_workspace_role_assignment(workspace_id = ws.id,
95
- principal_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
99
+ result_status_code = fc.delete_workspace_role_assignment(workspace_id = ws.id,
100
+ workspace_role_assignment_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
96
101
  self.assertEqual(result_status_code, 200)
97
102
 
98
103
  # def test_get_workspace_role_assignments(self):
99
- result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
100
- self.assertTrue("value" in result)
101
- self.assertTrue(len(result["value"]) == 1)
102
- user = result["value"][0]
104
+ result = fc.list_workspace_role_assignments(workspace_id = ws.id)
105
+ self.assertTrue(len(result) == 1)
106
+ user = result[0]
103
107
  # self.assertTrue(user["principal"]["displayName"] == "fabricapi")
104
108
  self.assertTrue(user["role"] == "Admin")
105
109
 
106
110
  # def test_update_workspace(self):
107
- ws_updated = self.fc.update_workspace(workspace_id=ws.id,
111
+ ws_updated = fc.update_workspace(workspace_id=ws.id,
108
112
  display_name="newn912389u8293",
109
113
  description="new description")
110
114
  self.assertEqual(ws_updated.display_name, "newn912389u8293")
111
115
  self.assertEqual(ws_updated.description, "new description")
112
- ws = self.fc.get_workspace_by_id(id = ws.id)
116
+ ws = fc.get_workspace_by_id(id = ws.id)
113
117
  self.assertEqual(ws.display_name, "newn912389u8293")
114
118
  self.assertEqual(ws.description, "new description")
115
119
 
116
120
  # def test_unassign_from_capacity(self):
117
121
 
118
- result_status_code = self.fc.unassign_from_capacity(workspace_id=ws.id)
122
+ result_status_code = fc.unassign_from_capacity(workspace_id=ws.id)
119
123
  self.assertEqual(result_status_code, 202)
120
- ws = self.fc.get_workspace_by_id(ws.id)
124
+ ws = fc.get_workspace_by_id(ws.id)
121
125
  self.assertEqual(ws.capacity_id, None)
122
126
 
127
+ # result = fc.provision_identity(workspace_id=ws.id)
128
+ # self.assertIsNotNone(result["applicationId"])
129
+ # fc.deprovision_identity(workspace_id=ws.id)
130
+
131
+
132
+
123
133
  # def test_delete_workspace(self):
124
- result_status = self.fc.delete_workspace(display_name="newn912389u8293")
134
+ result_status = fc.delete_workspace(display_name="newn912389u8293")
125
135
  self.assertEqual(result_status, 200)
126
136
 
127
137
  def test_list_capacities(self):
@@ -42,10 +42,13 @@ class Workspace:
42
42
  def __repr__(self) -> str:
43
43
  return self.__str__()
44
44
 
45
- def get_role_assignments(self):
46
- """Get role assignments for the workspace"""
45
+ def list_role_assignments(self, continuationToken = None):
46
+ """List role assignments for the workspace"""
47
47
  url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments"
48
48
 
49
+ if continuationToken:
50
+ url = f"{url}?continuationToken={continuationToken}"
51
+
49
52
  for _ in range(10):
50
53
  response = requests.get(url=url, headers=self.auth.get_headers())
51
54
  if response.status_code == 429:
@@ -58,7 +61,14 @@ class Workspace:
58
61
  raise Exception(f"Error getting role assignments: {response.text}")
59
62
  break
60
63
 
61
- return json.loads(response.text)
64
+ resp_dict = json.loads(response.text)
65
+ role_assignments = resp_dict["value"]
66
+
67
+ if "continuationToken" in resp_dict:
68
+ role_assignments_next = self.list_role_assignments(continuationToken=resp_dict["continuationToken"])
69
+ role_assignments.extend(role_assignments_next)
70
+
71
+ return role_assignments
62
72
 
63
73
  def delete(self):
64
74
  """Delete the workspace"""
@@ -94,7 +104,7 @@ class Workspace:
94
104
  print("Too many requests, waiting 10 seconds")
95
105
  sleep(10)
96
106
  continue
97
- if response.status_code not in (200, 429):
107
+ if response.status_code not in (201, 429):
98
108
  print(response.status_code)
99
109
  print(response.text)
100
110
  raise Exception(f"Error adding role assignments: {response.text}")
@@ -103,9 +113,9 @@ class Workspace:
103
113
  return response.status_code
104
114
 
105
115
 
106
- def delete_role_assignment(self, principal_id):
116
+ def delete_role_assignment(self, workspace_role_assignment_id):
107
117
  """Delete a role assignment from the workspace"""
108
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{principal_id}"
118
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
109
119
 
110
120
  for _ in range(10):
111
121
  response = requests.delete(url=url, headers=self.auth.get_headers())
@@ -150,10 +160,29 @@ class Workspace:
150
160
  self.description = description
151
161
 
152
162
  return self
163
+
164
+ def get_role_assignment(self, workspace_role_assignment_id):
165
+ # GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/roleAssignments/{workspaceRoleAssignmentId}
166
+
167
+ """Get a role assignment from the workspace"""
168
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
169
+
170
+ for _ in range(10):
171
+ response = requests.get(url=url, headers=self.auth.get_headers())
172
+
173
+ if response.status_code == 429:
174
+ print("Too many requests, waiting 10 seconds")
175
+ sleep(10)
176
+ continue
177
+ if response.status_code not in (200, 429):
178
+ raise Exception(f"Error getting role assignments: {response.status_code}, {response.text}")
179
+ break
153
180
 
154
- def update_role_assignment(self, role, principal_id):
181
+ return json.loads(response.text)
182
+
183
+ def update_role_assignment(self, role, workspace_role_assignment_id):
155
184
  """Update a role assignment in the workspace"""
156
- url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{principal_id}"
185
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments/{workspace_role_assignment_id}"
157
186
  body = {
158
187
  'role': role
159
188
  }
@@ -222,6 +251,45 @@ class Workspace:
222
251
  self.capacity_id = None
223
252
  return response.status_code
224
253
 
254
+ def provision_identity(self):
255
+ # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/provisionIdentity
256
+ """Provision identity for the workspace"""
257
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/provisionIdentity"
258
+
259
+ for _ in range(10):
260
+ response = requests.post(url=url, headers=self.auth.get_headers())
261
+ if response.status_code == 429:
262
+ print("Too many requests, waiting 10 seconds")
263
+ sleep(10)
264
+ continue
265
+ if response.status_code == 202:
266
+ return check_long_running_operation( response.headers, self.auth)
267
+ if response.status_code not in (200, 201, 202, 429):
268
+ raise Exception(f"Error provisioning identity: {response.status_code}, {response.text}")
269
+ break
270
+
271
+ return response
272
+
273
+ def deprovision_identity(self):
274
+ # POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/deprovisionIdentity
275
+ """Deprovision identity for the workspace"""
276
+ url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/deprovisionIdentity"
277
+
278
+ for _ in range(10):
279
+ response = requests.post(url=url, headers=self.auth.get_headers())
280
+ if response.status_code == 429:
281
+ print("Too many requests, waiting 10 seconds")
282
+ sleep(10)
283
+ continue
284
+ if response.status_code == 202:
285
+ return check_long_running_operation( response.headers, self.auth)
286
+ if response.status_code not in (200, 201, 202, 429):
287
+ raise Exception(f"Error deprovisioning identity: {response.status_code}, {response.text}")
288
+ break
289
+
290
+ return response
291
+
292
+
225
293
  def get_item_specific(self, item_dict):
226
294
  if item_dict["type"] == "DataPipeline":
227
295
  return self.get_data_pipeline(item_dict["id"])
@@ -1218,6 +1286,11 @@ class Workspace:
1218
1286
  """Update the definition of a spark job definition in a workspace"""
1219
1287
  return self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id).update_definition(definition=definition)
1220
1288
 
1289
+ def run_on_demand_spark_job_definition(self, spark_job_definition_id, job_type = "sparkjob"):
1290
+ """Run on demand spark job definition"""
1291
+ sjd = self.get_spark_job_definition(spark_job_definition_id=spark_job_definition_id)
1292
+ return sjd.run_on_demand_spark_job_definition(job_type=job_type)
1293
+
1221
1294
  # warehouses
1222
1295
 
1223
1296
  def list_warehouses(self, with_properties = False):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: msfabricpysdkcore
3
- Version: 0.0.11
3
+ Version: 0.0.12
4
4
  Summary: A Python SDK for Microsoft Fabric
5
5
  Author: Andreas Rederer
6
6
  Project-URL: Homepage, https://github.com/DaSenf1860/ms-fabric-sdk-core
@@ -148,26 +148,40 @@ ws.add_role_assignment(principal = {"id" : "abadfbafb",
148
148
  role = 'Member')
149
149
 
150
150
 
151
- # Get workspace role assignments
152
- fc.get_workspace_role_assignments(workspace_id = ws.id)
151
+ # List workspace role assignments
152
+ fc.list_workspace_role_assignments(workspace_id = ws.id)
153
153
  # or
154
- ws.get_role_assignments()
154
+ ws.list_role_assignments()
155
155
 
156
156
 
157
+ # Get workspace role assignment
158
+ fc.get_workspace_role_assignment(workspace_id = ws.id,
159
+ workspace_role_assignment_id = "dagdasf")
160
+ # or
161
+ ws.get_role_assignment(workspace_role_assignment_id = "fsgdg")
162
+
157
163
  # Update workspace role assignment
158
164
  fc.update_workspace_role_assignment(workspace_id = ws.id,
159
165
  role = "Contributor",
160
- principal_id = "abadfbafb")
166
+ workspace_role_assignment_id = "abadfbafb")
161
167
  # or
162
168
  ws.update_role_assignment(role = "Contributor",
163
- principal_id = "abadfbafb")
169
+ workspace_role_assignment_id = "abadfbafb")
164
170
 
165
171
 
166
172
  # Delete workspace role assignment
167
173
  fc.delete_workspace_role_assignment(workspace_id = ws.id,
168
- principal_id = "abadfbafb")
174
+ workspace_role_assignment_id = "abadfbafb")
169
175
  # or
170
- ws.delete_role_assignment(principal_id = "abadfbafb")
176
+ ws.delete_role_assignment(workspace_role_assignment_id = "abadfbafb")
177
+
178
+
179
+ # Provision Identity
180
+ result = fc.provision_identity(workspace_id=ws.id)
181
+ print(result["applicationId"]))
182
+
183
+ # Deprovision Identity
184
+ fc.deprovision_identity(workspace_id=ws.id)
171
185
 
172
186
  ```
173
187
 
@@ -5,34 +5,35 @@ msfabricpysdkcore/adminapi.py,sha256=uithaYq_HWDU-9Et_EFBNQfrjcjnI-NW6OCmWoAsZxk
5
5
  msfabricpysdkcore/auth.py,sha256=v5YkI4jA6T7lv5rjqTK-GEPx2ATDPKQ1LVcaCg98oLM,2562
6
6
  msfabricpysdkcore/capacity.py,sha256=Q_2-XrZtdf9F67fY0qU3D0ocEOGQq4KtIXAv9dXjQhI,1761
7
7
  msfabricpysdkcore/client.py,sha256=yOZ1CW2ilL8a7J_SRNa-EQbG8xNlJKW3ygniIrsADsw,1300
8
- msfabricpysdkcore/coreapi.py,sha256=Mjs_YoCISmQXhG7mO4KDWd-4GKZJ7M4hsgis3cee-no,48590
8
+ msfabricpysdkcore/coreapi.py,sha256=IUutbCz_Dag2rFWbmbSVt8AkFnj4CJdP-v-jXOrFrBA,49645
9
9
  msfabricpysdkcore/deployment_pipeline.py,sha256=RFI86rtG-eTpV-_tVl3cXtcTl9ekRvOI5fLsXo9CMVA,9739
10
10
  msfabricpysdkcore/domain.py,sha256=i8jMJEutDRL5XuQ69woCVQEzLS_lm9uUxl4Kp3xtxHc,14722
11
11
  msfabricpysdkcore/environment.py,sha256=ENgy7URz_gJ4E5-OH355QF6vqawBoHjHMbjnoEJfGwM,10072
12
12
  msfabricpysdkcore/item.py,sha256=HIr32drqNtlIKKXkXCcWI2H_TZMDalCxvikTyDHNprA,11428
13
13
  msfabricpysdkcore/job_instance.py,sha256=C9kKsV-BIJSeU6DfoTnLlg4DLp-8RYpovs0A-mKwi4o,2745
14
14
  msfabricpysdkcore/lakehouse.py,sha256=nv95SBz_jsssT5dEw622WqtDHUyh5bFFsVTwiqo8s-c,6055
15
- msfabricpysdkcore/long_running_operation.py,sha256=gcGVTgA0NToPItrl42Zy1M2eVZtx-vx-SdUryNAm53E,2731
15
+ msfabricpysdkcore/long_running_operation.py,sha256=Itm8ohr9fPIdP7UO9_xehQ6wb6t4hsCuvDbcOSzAgVA,2981
16
16
  msfabricpysdkcore/onelakeshortcut.py,sha256=EYZfP-rl60HdCqJD1O1NXrQTgrYTIw-EWisF4hs4bTU,2102
17
- msfabricpysdkcore/otheritems.py,sha256=TsRZHcqYHw1t6tqKMa3yC0LF9uBj3a1Uzc_lLKZ6LVY,10967
17
+ msfabricpysdkcore/otheritems.py,sha256=D-sGriO9ck4pqzsLY6bZLJUDXIBkyNyqCPoJmgextbk,12571
18
18
  msfabricpysdkcore/spark_custom_pool.py,sha256=2H-GkGcDsiKxSpXFSf8Zi7xJI5_krb_8sGdF5vDjEy8,4635
19
- msfabricpysdkcore/workspace.py,sha256=IeT0W0vitc_jH6d9OhRd-SjgDsKYFayQ_g8m9DD0pts,65050
19
+ msfabricpysdkcore/workspace.py,sha256=IdP0qDXD-0JVZnK_cn9VILNQ5-FQGFzGXq-MoCkLyWs,68563
20
20
  msfabricpysdkcore/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  msfabricpysdkcore/tests/test_admin_apis.py,sha256=HTXt72p9FiEf3q9SXyq9aImR6zZo_xIREfB0xPaYazU,2586
22
22
  msfabricpysdkcore/tests/test_datapipelines.py,sha256=rIeZfv-MGewYYscb36jmjL8DLZ3Z1dJWv09foR9z_y8,1812
23
- msfabricpysdkcore/tests/test_deployment_pipeline.py,sha256=XmqKZXbwBY3P-4O_ce9Wupz9qXHaKxWERwS-RZt38Bs,2024
23
+ msfabricpysdkcore/tests/test_deployment_pipeline.py,sha256=7bXqSpnU8Hb7KyKldhA7hVM8QqKHj0WoT9_kC27hsxM,2058
24
24
  msfabricpysdkcore/tests/test_domains.py,sha256=KFGQyl0G2v4JjX_xYHY-vPSjYxeLEx3AcXMdiRZzClc,4620
25
25
  msfabricpysdkcore/tests/test_environments.py,sha256=zSIMhkQscMB7doJEQRBRMvAEBxO1Kl1N85MKXP3yeYI,3120
26
26
  msfabricpysdkcore/tests/test_evenstreams.py,sha256=i6hhsOnDJ-BN7kStg7gQhZVPMVaB73K7KJez6pEKlv0,1628
27
- msfabricpysdkcore/tests/test_git.py,sha256=IZfWggCyZtHpUbYyacNTyIRfy6rofz-fBEmco_8gMZ4,2415
28
- msfabricpysdkcore/tests/test_items_incl_lakehouse.py,sha256=6to6S9ZcRT6Ain7U3LxCpjkKmL7-Uk3VvJ4xfSkrnKg,19910
27
+ msfabricpysdkcore/tests/test_git.py,sha256=pmhVYZGDMEFtgy51hKrDWqtea-MryyeyvPKVCaTsIEA,2415
28
+ msfabricpysdkcore/tests/test_items_incl_lakehouse.py,sha256=zWNmOI_Ysh96d8P-Sm4IOCzMqXTCEBg63lxCDZZ_9b8,17987
29
29
  msfabricpysdkcore/tests/test_jobs.py,sha256=DC1nQTav_Re7uunRA07wD_56giLqe9KOsgm56Il8Zr4,1632
30
30
  msfabricpysdkcore/tests/test_kqldatabases.py,sha256=Oc2ZzpQAVbiJeZ5ytwlP2Jb-tKe-2e9-1oA-upwRKBQ,1921
31
31
  msfabricpysdkcore/tests/test_shortcuts.py,sha256=TqGLzEWsDyiQ0Gf6JpT_qBHUCgcvYXfVwpXxOay7Qz4,2407
32
32
  msfabricpysdkcore/tests/test_spark.py,sha256=5BCAgHRiuXjIRnGrbvNNh9emq0VyZXlvIWgWAEir5ZQ,3437
33
- msfabricpysdkcore/tests/test_workspaces_capacities.py,sha256=X00zIuADhY_7jORIzXrWiXfPBJUhbXUckF-gZJ3m1bQ,6547
34
- msfabricpysdkcore-0.0.11.dist-info/LICENSE,sha256=1NrGuF-zOmzbwzk3iI6lsP9koyDeKO1B0-8OD_tTvOQ,1156
35
- msfabricpysdkcore-0.0.11.dist-info/METADATA,sha256=56ie3TOUCJjsXDapUag0-i5-YmcluBQqgRFIgJODj2A,17455
36
- msfabricpysdkcore-0.0.11.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
37
- msfabricpysdkcore-0.0.11.dist-info/top_level.txt,sha256=3iRonu6ptDGQN4Yl6G76XGM7xbFNsskiEHW-P2gMQGY,18
38
- msfabricpysdkcore-0.0.11.dist-info/RECORD,,
33
+ msfabricpysdkcore/tests/test_sparkjobdefinition.py,sha256=whADi8l4opMaoB4b1W5EbuddyB5tC5OEqGRFKVUYMH4,2820
34
+ msfabricpysdkcore/tests/test_workspaces_capacities.py,sha256=52FqGZRVvHDegLgu71kGX_Tx4cRh9lO_wuK8BG_czkQ,6699
35
+ msfabricpysdkcore-0.0.12.dist-info/LICENSE,sha256=1NrGuF-zOmzbwzk3iI6lsP9koyDeKO1B0-8OD_tTvOQ,1156
36
+ msfabricpysdkcore-0.0.12.dist-info/METADATA,sha256=bK4vYEgjRLyzNJhBUnSSI6I9GlWnZcXIYDoo5z6__TY,17944
37
+ msfabricpysdkcore-0.0.12.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
38
+ msfabricpysdkcore-0.0.12.dist-info/top_level.txt,sha256=3iRonu6ptDGQN4Yl6G76XGM7xbFNsskiEHW-P2gMQGY,18
39
+ msfabricpysdkcore-0.0.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5