brynq-sdk-azure 2.0.2__tar.gz → 3.0.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_azure
3
- Version: 2.0.2
3
+ Version: 3.0.0
4
4
  Summary: Azure wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,16 +1,17 @@
1
1
  from brynq_sdk_brynq import BrynQ
2
2
  from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, generate_account_sas, ResourceTypes, AccountSasPermissions
3
- from typing import Union, List, Tuple
3
+ from typing import Union, List, Tuple, Literal, Optional
4
4
  from datetime import datetime, timedelta
5
5
 
6
6
 
7
7
  class BlobStorage(BrynQ):
8
- def __init__(self, label: Union[str, List]):
8
+ def __init__(self, system_type: Optional[Literal['source', 'target']] = None):
9
9
  super().__init__()
10
- self.blob_service_client = self.__get_authentication(label=label)
10
+ self.blob_service_client = self._get_authentication(system_type)
11
11
 
12
- def __get_authentication(self, label):
13
- credentials = self.get_system_credential(system='azure-blob-storage', label=label)
12
+ def _get_authentication(self, system_type):
13
+ credentials = self.interfaces.credentials.get(system='azure-blob-storage', system_type=system_type)
14
+ credentials = credentials.get('data')
14
15
  storage_account_name = credentials['storage_account_name']
15
16
  storage_account_key = credentials['storage_account_key']
16
17
  sas_token = generate_account_sas(
@@ -8,18 +8,20 @@ import json
8
8
  import pandas as pd
9
9
  from pandas import json_normalize
10
10
  from msal import ConfidentialClientApplication
11
- from typing import Union, List
11
+ from typing import Union, List, Literal, Optional
12
12
  import os
13
13
 
14
14
  class Entra(BrynQ):
15
15
 
16
- def __init__(self, label: Union[str, List], debug: bool = False):
16
+ def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug: bool = False):
17
17
  super().__init__()
18
- self.headers = self.__get_headers(label=label)
18
+ self.headers = self.__get_headers(system_type)
19
19
  self.endpoint = "https://graph.microsoft.com/v1.0"
20
+ self.timeout = 3600
20
21
 
21
- def __get_headers(self, label):
22
- credentials = self.get_system_credential(system='azure-entra-token', label=label)
22
+ def __get_headers(self, system_type):
23
+ credentials = self.interfaces.credentials.get(system='azure-entra-token', system_type=system_type)
24
+ credentials = credentials.get('data')
23
25
  tenant_id = credentials['tenant_id']
24
26
  client_id = credentials['client_id']
25
27
  client_secret = credentials['client_secret']
@@ -44,7 +46,7 @@ class Entra(BrynQ):
44
46
  def __add_attribute_information(self, payload, custom_attributes):
45
47
  # First get the official name of the custom attribute and all the other information
46
48
  payload.update({"customSecurityAttributes": {}})
47
- metadata = requests.get('https://graph.microsoft.com/v1.0/directory/customSecurityAttributeDefinitions', headers=self.headers).json()
49
+ metadata = requests.get('https://graph.microsoft.com/v1.0/directory/customSecurityAttributeDefinitions', headers=self.headers, timeout=self.timeout).json()
48
50
  # Now loop through the given metadata and add the corresponding metadata and the values itself to the payload
49
51
  for attr, value in custom_attributes.items():
50
52
  for meta in metadata["value"]:
@@ -106,7 +108,7 @@ class Entra(BrynQ):
106
108
  loop = True
107
109
  url = f"{endpoint}/groups"
108
110
  while loop:
109
- response = requests.get(url, headers=self.headers)
111
+ response = requests.get(url, headers=self.headers, timeout=self.timeout)
110
112
  groups = response.json()['value']
111
113
  df_temp = pd.json_normalize(groups)
112
114
  df = pd.concat([df, df_temp], ignore_index=True)
@@ -126,7 +128,7 @@ class Entra(BrynQ):
126
128
  group_url = "https://graph.microsoft.com/v1.0/groups/"
127
129
  df = pd.DataFrame()
128
130
  while group_url:
129
- graph_r = requests.get(group_url, headers=self.headers)
131
+ graph_r = requests.get(group_url, headers=self.headers, timeout=self.timeout)
130
132
  graph_json = graph_r.json()
131
133
  groups = graph_json.get('value')
132
134
  for group in groups:
@@ -134,7 +136,7 @@ class Entra(BrynQ):
134
136
  # Get users in each group
135
137
  next_url_members = f"https://graph.microsoft.com/v1.0/groups/{group['id']}/members"
136
138
  while next_url_members:
137
- members_r = requests.get(next_url_members, headers=self.headers)
139
+ members_r = requests.get(next_url_members, headers=self.headers, timeout=self.timeout)
138
140
  members_json = members_r.json()
139
141
  members = members_json.get('value')
140
142
  df_temp = pd.json_normalize(members)
@@ -167,7 +169,7 @@ class Entra(BrynQ):
167
169
  "mailNickname": f"{mail_nickname}",
168
170
  "securityEnabled": security_enabled
169
171
  }
170
- response = requests.post(endpoint, headers=self.headers, json=payload)
172
+ response = requests.post(endpoint, headers=self.headers, json=payload, timeout=self.timeout)
171
173
  return response
172
174
 
173
175
  def update_group(self, id: int, name: str = '', description: str = '', mail_enabled: bool = False, mail_nickname: str = '', security_enabled: bool = True):
@@ -189,7 +191,7 @@ class Entra(BrynQ):
189
191
  "mailNickname": f"{mail_nickname}",
190
192
  "securityEnabled": security_enabled
191
193
  }
192
- response = requests.patch(endpoint, headers=self.headers, json=payload)
194
+ response = requests.patch(endpoint, headers=self.headers, json=payload, timeout=self.timeout)
193
195
  return response
194
196
 
195
197
  def delete_group(self, group_id):
@@ -199,7 +201,7 @@ class Entra(BrynQ):
199
201
  :return: Response of the request
200
202
  """
201
203
  endpoint = f"https://graph.microsoft.com/v1.0/groups/{group_id}"
202
- response = requests.delete(endpoint, headers=self.headers)
204
+ response = requests.delete(endpoint, headers=self.headers, timeout=self.timeout)
203
205
  return response
204
206
 
205
207
  def get_users(self, extra_fields: list = [], custom_attributes: bool = False, expand: str = '', expand_select: str = '') -> pd.DataFrame:
@@ -224,7 +226,7 @@ class Entra(BrynQ):
224
226
 
225
227
  df = pd.DataFrame()
226
228
  while endpoint:
227
- response = requests.get(endpoint, headers=self.headers)
229
+ response = requests.get(endpoint, headers=self.headers, timeout=self.timeout)
228
230
  endpoint = response.json().get('@odata.nextLink')
229
231
  data = response.json().get('value')
230
232
  df_temp = json_normalize(data, sep='.')
@@ -265,7 +267,7 @@ class Entra(BrynQ):
265
267
  # If there are any custom attributes, add them to the payload. But since the endpoint needs extra metadata, we need to do some extra work
266
268
  if len(custom_attributes) > 0:
267
269
  payload = self.__add_attribute_information(payload, custom_attributes)
268
- response = requests.post(endpoint, headers=self.headers, json=payload)
270
+ response = requests.post(endpoint, headers=self.headers, json=payload, timeout=self.timeout)
269
271
  return response
270
272
 
271
273
  def update_user(self, user_id, fields_to_update: dict = {}, custom_attributes: dict = {}, update_password: bool = False):
@@ -286,7 +288,7 @@ class Entra(BrynQ):
286
288
  }})
287
289
  if len(custom_attributes) > 0:
288
290
  payload = self.__add_attribute_information(payload, custom_attributes)
289
- response = requests.patch(endpoint, headers=self.headers, json=payload)
291
+ response = requests.patch(endpoint, headers=self.headers, json=payload, timeout=self.timeout)
290
292
  return response
291
293
 
292
294
  def delete_user(self, user_id, delete=False):
@@ -297,10 +299,10 @@ class Entra(BrynQ):
297
299
  """
298
300
  endpoint = f"https://graph.microsoft.com/v1.0/users/{user_id}"
299
301
  if delete:
300
- response = requests.delete(endpoint, headers=self.headers)
302
+ response = requests.delete(endpoint, headers=self.headers, timeout=self.timeout)
301
303
  else:
302
304
  payload = {"accountEnabled": False}
303
- response = requests.patch(endpoint, headers=self.headers, data=json.dumps(payload))
305
+ response = requests.patch(endpoint, headers=self.headers, data=json.dumps(payload), timeout=self.timeout)
304
306
  return response
305
307
 
306
308
  def assign_user_to_group(self, user_id, group_id):
@@ -312,7 +314,7 @@ class Entra(BrynQ):
312
314
  """
313
315
  url = f"https://graph.microsoft.com/v1.0/groups/{group_id}/members/$ref"
314
316
  data = {"@odata.id": f"https://graph.microsoft.com/v1.0/directoryObjects/{user_id}"}
315
- response = requests.post(url, headers=self.headers, data=json.dumps(data))
317
+ response = requests.post(url, headers=self.headers, data=json.dumps(data), timeout=self.timeout)
316
318
  return response
317
319
 
318
320
  def update_manager(self, user_id, manager_id):
@@ -324,7 +326,7 @@ class Entra(BrynQ):
324
326
  """
325
327
  url = f"https://graph.microsoft.com/v1.0/users/{user_id}/manager/$ref"
326
328
  content ={f"@odata.id": f"https://graph.microsoft.com/v1.0/users/{manager_id}"}
327
- response = requests.put(url, headers=self.headers, data=json.dumps(content))
329
+ response = requests.put(url, headers=self.headers, data=json.dumps(content), timeout=self.timeout)
328
330
  return response
329
331
 
330
332
  def remove_user_from_group(self, user_id, group_id):
@@ -335,5 +337,5 @@ class Entra(BrynQ):
335
337
  return: response
336
338
  """
337
339
  url = f"https://graph.microsoft.com/v1.0/groups/{group_id}/members/{user_id}/$ref"
338
- response = requests.delete(url, headers=self.headers)
340
+ response = requests.delete(url, headers=self.headers, timeout=self.timeout)
339
341
  return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-azure
3
- Version: 2.0.2
3
+ Version: 3.0.0
4
4
  Summary: Azure wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,4 +1,4 @@
1
- brynq-sdk-brynq>=2
1
+ brynq-sdk-brynq<5,>=4
2
2
  azure-storage-file-share>=12.6.0
3
3
  azure-storage-blob>=12.16.0
4
4
  msal==1.22.0
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name='brynq_sdk_azure',
5
- version='2.0.2',
5
+ version='3.0.0',
6
6
  description='Azure wrapper from BrynQ',
7
7
  long_description='Azure wrapper from BrynQ',
8
8
  author='BrynQ',
@@ -10,7 +10,7 @@ setup(
10
10
  packages=find_namespace_packages(include=['brynq_sdk*']),
11
11
  license='BrynQ License',
12
12
  install_requires=[
13
- 'brynq-sdk-brynq>=2',
13
+ 'brynq-sdk-brynq>=4,<5',
14
14
  'azure-storage-file-share>=12.6.0',
15
15
  'azure-storage-blob>=12.16.0',
16
16
  'msal==1.22.0'