brynq-sdk-imanage 2.0.0__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.
@@ -0,0 +1,80 @@
1
+ import requests
2
+ import json
3
+ from typing import List, Union, Literal, Optional
4
+ from brynq_sdk_brynq import BrynQ
5
+
6
+
7
+ from typing import List, Union
8
+ import requests
9
+
10
+ class IManage(BrynQ):
11
+ def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug: bool = False):
12
+ super().__init__()
13
+ self.timeout = 3600
14
+ self.debug = debug
15
+ self.credentials = self.interfaces.credentials.get(system='i-manage-oauth', system_type=system_type)
16
+ self.customer_name = self.subdomain.lower()
17
+ self.imanage_url = 'https://cloudimanage.com'
18
+ self.customer_id, self.customer_url = self._get_customer_id_and_url()
19
+
20
+
21
+ def __get_headers(self):
22
+ return {
23
+ 'X-Auth-Token': f'{self.credentials["data"]["access_token"]}'
24
+ }
25
+
26
+ def _get_customer_id_and_url(self):
27
+ headers = self.__get_headers()
28
+ url = f'{self.imanage_url}/api'
29
+ response = requests.get(url, headers=headers, timeout=self.timeout)
30
+ response.raise_for_status()
31
+ if self.debug:
32
+ print(response.text)
33
+ data = response.json()
34
+
35
+ # Extract customer_id as before
36
+ customer_id = data['data']['user']['customer_id']
37
+ customer_id = str(customer_id)
38
+
39
+ v2_versions = []
40
+
41
+ # Loop through the versions to find 'v2' versions
42
+ versions = data['data']['versions']
43
+ for version in versions:
44
+ if version['name'] == 'v2':
45
+ version_number = version['version'] # This should be a string like '2.1.1160'
46
+ version_url = version['url']
47
+ v2_versions.append((version_number, version_url))
48
+
49
+ # Sort the v2 versions by their version number in descending order to get the newest version first
50
+ v2_versions.sort(key=lambda x: [int(part) for part in x[0].split('.')], reverse=True)
51
+
52
+ # If there are any v2 versions, select the newest one
53
+ if v2_versions:
54
+ customer_url = v2_versions[0][1] # The URL of the newest v2 version
55
+ else:
56
+ # Raise an exception if no v2 version is found
57
+ raise Exception("No 'v2' version found for the customer.")
58
+
59
+ return customer_id, customer_url
60
+
61
+ def get_all_users(self):
62
+ headers = self.__get_headers()
63
+ limit = 100
64
+ offset = 0
65
+ users = []
66
+ payload = {}
67
+ while True:
68
+ url = f'{self.customer_url}/customers/{self.customer_id}/users?require_role=true&limit={limit}&offset={offset}&total=true'
69
+ response = requests.get(url, headers=headers, data = payload, timeout=self.timeout)
70
+ response.raise_for_status()
71
+ if self.debug:
72
+ print(response.text)
73
+ data = response.json()
74
+ users.extend(data['data'])
75
+ if offset >= data['total_count']:
76
+ break
77
+ offset += limit
78
+ return users
79
+
80
+
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: brynq_sdk_imanage
3
+ Version: 2.0.0
4
+ Summary: Imanage wrapper from BrynQ
5
+ Author: BrynQ
6
+ Author-email: support@brynq.com
7
+ License: BrynQ License
8
+ Requires-Dist: brynq-sdk-brynq<5,>=4
9
+ Requires-Dist: pandas<3.0.0,>=2.2.0
10
+ Dynamic: author
11
+ Dynamic: author-email
12
+ Dynamic: description
13
+ Dynamic: license
14
+ Dynamic: requires-dist
15
+ Dynamic: summary
16
+
17
+ Imanage wrapper from BrynQ
@@ -0,0 +1,5 @@
1
+ brynq_sdk_imanage/__init__.py,sha256=4VmP8KN3ICttblLjpUb2KUIA8mF2fb_ojMCT50aANLE,2912
2
+ brynq_sdk_imanage-2.0.0.dist-info/METADATA,sha256=bxXS3perFiwDyfMgCUmJefQqM9V_PiUzJQxXi0cYHq8,383
3
+ brynq_sdk_imanage-2.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
4
+ brynq_sdk_imanage-2.0.0.dist-info/top_level.txt,sha256=_QE8-WwMo4-ju8o2kcfDYXePxC2LiehNavrrBtFhq6A,18
5
+ brynq_sdk_imanage-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ brynq_sdk_imanage