sumo-wrapper-python 1.0.22__py3-none-any.whl → 1.0.23__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.
Potentially problematic release.
This version of sumo-wrapper-python might be problematic. Click here for more details.
- sumo/wrapper/_auth_provider.py +34 -6
- sumo/wrapper/_retry_strategy.py +1 -1
- sumo/wrapper/_version.py +2 -2
- sumo/wrapper/sumo_client.py +25 -8
- {sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/METADATA +1 -1
- sumo_wrapper_python-1.0.23.dist-info/RECORD +17 -0
- sumo_wrapper_python-1.0.22.dist-info/RECORD +0 -17
- {sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/LICENSE +0 -0
- {sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/WHEEL +0 -0
- {sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/entry_points.txt +0 -0
- {sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/top_level.txt +0 -0
sumo/wrapper/_auth_provider.py
CHANGED
|
@@ -5,6 +5,7 @@ import stat
|
|
|
5
5
|
import sys
|
|
6
6
|
import time
|
|
7
7
|
from datetime import datetime, timedelta
|
|
8
|
+
from urllib.parse import parse_qs
|
|
8
9
|
|
|
9
10
|
import jwt
|
|
10
11
|
import msal
|
|
@@ -30,20 +31,17 @@ def _maybe_nfs_exception(exception):
|
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
def get_token_dir():
|
|
33
|
-
return os.path.
|
|
34
|
+
return os.path.expanduser("~/.sumo")
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
def get_token_path(resource_id, suffix, case_uuid=None):
|
|
37
38
|
if case_uuid is not None:
|
|
38
39
|
return os.path.join(
|
|
39
|
-
|
|
40
|
-
".sumo",
|
|
40
|
+
get_token_dir(),
|
|
41
41
|
str(resource_id) + "+" + str(case_uuid) + suffix,
|
|
42
42
|
)
|
|
43
43
|
else:
|
|
44
|
-
return os.path.join(
|
|
45
|
-
os.path.expanduser("~"), ".sumo", str(resource_id) + suffix
|
|
46
|
-
)
|
|
44
|
+
return os.path.join(get_token_dir(), str(resource_id) + suffix)
|
|
47
45
|
|
|
48
46
|
|
|
49
47
|
class AuthProvider:
|
|
@@ -91,6 +89,36 @@ class AuthProvider:
|
|
|
91
89
|
) as f:
|
|
92
90
|
f.write(token)
|
|
93
91
|
protect_token_cache(self._resource_id, ".sharedkey", case_uuid)
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
def cleanup_shared_keys(self):
|
|
95
|
+
tokendir = get_token_dir()
|
|
96
|
+
if not os.path.exists(tokendir):
|
|
97
|
+
return
|
|
98
|
+
for f in os.listdir(tokendir):
|
|
99
|
+
ff = os.path.join(tokendir, f)
|
|
100
|
+
if os.path.isfile(ff):
|
|
101
|
+
(name, ext) = os.path.splitext(ff)
|
|
102
|
+
if ext.lower() == ".sharedkey":
|
|
103
|
+
try:
|
|
104
|
+
with open(ff, "r") as file:
|
|
105
|
+
token = file.read()
|
|
106
|
+
pq = parse_qs(token)
|
|
107
|
+
se = pq["se"][0]
|
|
108
|
+
end = datetime.strptime(
|
|
109
|
+
se, "%Y-%m-%dT%H:%M:%S.%fZ"
|
|
110
|
+
)
|
|
111
|
+
now = datetime.utcnow()
|
|
112
|
+
if now > end:
|
|
113
|
+
os.unlink(ff)
|
|
114
|
+
pass
|
|
115
|
+
pass
|
|
116
|
+
pass
|
|
117
|
+
except Exception:
|
|
118
|
+
pass
|
|
119
|
+
pass
|
|
120
|
+
pass
|
|
121
|
+
return
|
|
94
122
|
|
|
95
123
|
def has_case_token(self, case_uuid):
|
|
96
124
|
return os.path.exists(
|
sumo/wrapper/_retry_strategy.py
CHANGED
|
@@ -30,7 +30,7 @@ def _is_retryable_exception(exception):
|
|
|
30
30
|
|
|
31
31
|
# Define the conditions for retrying based on HTTP status codes
|
|
32
32
|
def _is_retryable_status_code(response):
|
|
33
|
-
return response.status_code in [502, 503
|
|
33
|
+
return response.status_code in [502, 503]
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def _return_last_value(retry_state):
|
sumo/wrapper/_version.py
CHANGED
sumo/wrapper/sumo_client.py
CHANGED
|
@@ -34,6 +34,8 @@ class SumoClient:
|
|
|
34
34
|
retry_strategy=RetryStrategy(),
|
|
35
35
|
timeout=DEFAULT_TIMEOUT,
|
|
36
36
|
case_uuid=None,
|
|
37
|
+
http_client=None,
|
|
38
|
+
async_http_client=None,
|
|
37
39
|
):
|
|
38
40
|
"""Initialize a new Sumo object
|
|
39
41
|
|
|
@@ -54,8 +56,19 @@ class SumoClient:
|
|
|
54
56
|
self._verbosity = verbosity
|
|
55
57
|
|
|
56
58
|
self._retry_strategy = retry_strategy
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
if http_client is None:
|
|
60
|
+
self._client = httpx.Client()
|
|
61
|
+
self._borrowed_client = False
|
|
62
|
+
else:
|
|
63
|
+
self._client = http_client
|
|
64
|
+
self._borrowed_client = True
|
|
65
|
+
|
|
66
|
+
if async_http_client is None:
|
|
67
|
+
self._async_client = httpx.AsyncClient()
|
|
68
|
+
self._borrowed_async_client = False
|
|
69
|
+
else:
|
|
70
|
+
self._async_client = async_http_client
|
|
71
|
+
self._borrowed_async_client = True
|
|
59
72
|
|
|
60
73
|
self._timeout = timeout
|
|
61
74
|
|
|
@@ -92,6 +105,8 @@ class SumoClient:
|
|
|
92
105
|
case_uuid=case_uuid,
|
|
93
106
|
)
|
|
94
107
|
|
|
108
|
+
self.auth.cleanup_shared_keys()
|
|
109
|
+
|
|
95
110
|
if env == "localhost":
|
|
96
111
|
self.base_url = "http://localhost:8084/api/v1"
|
|
97
112
|
else:
|
|
@@ -103,7 +118,8 @@ class SumoClient:
|
|
|
103
118
|
return self
|
|
104
119
|
|
|
105
120
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
106
|
-
self.
|
|
121
|
+
if not self._borrowed_client:
|
|
122
|
+
self._client.close()
|
|
107
123
|
self._client = None
|
|
108
124
|
return False
|
|
109
125
|
|
|
@@ -111,16 +127,17 @@ class SumoClient:
|
|
|
111
127
|
return self
|
|
112
128
|
|
|
113
129
|
async def __aexit__(self, exc_type, exc_value, traceback):
|
|
114
|
-
|
|
130
|
+
if not self._borrowed_async_client:
|
|
131
|
+
await self._async_client.aclose()
|
|
115
132
|
self._async_client = None
|
|
116
133
|
return False
|
|
117
134
|
|
|
118
135
|
def __del__(self):
|
|
119
|
-
if self._client is not None:
|
|
136
|
+
if self._client is not None and not self._borrowed_client:
|
|
120
137
|
self._client.close()
|
|
121
|
-
self._client = None
|
|
122
138
|
pass
|
|
123
|
-
|
|
139
|
+
self._client = None
|
|
140
|
+
if self._async_client is not None and not self._borrowed_async_client:
|
|
124
141
|
|
|
125
142
|
async def closeit(client):
|
|
126
143
|
await client.aclose()
|
|
@@ -131,8 +148,8 @@ class SumoClient:
|
|
|
131
148
|
loop.create_task(closeit(self._async_client))
|
|
132
149
|
except RuntimeError:
|
|
133
150
|
pass
|
|
134
|
-
self._async_client = None
|
|
135
151
|
pass
|
|
152
|
+
self._async_client = None
|
|
136
153
|
|
|
137
154
|
def authenticate(self):
|
|
138
155
|
if self.auth is None:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
sumo/__init__.py,sha256=ftS-xRPSH-vU7fIHlnZQaCTWbNvs4owJivNW65kzsIM,85
|
|
2
|
+
sumo/wrapper/__init__.py,sha256=JK6iMAy2Fdrc7iaIHTn60fHPdRvsgNjZwWD6DJtGUYQ,235
|
|
3
|
+
sumo/wrapper/_auth_provider.py,sha256=Fcg62itYF8MfQit9wa191ZA5kFL4tGFobp7ESVi4qy0,15697
|
|
4
|
+
sumo/wrapper/_blob_client.py,sha256=SyfyFZ1hHVWKU4lmgUqSjl5TaK_OJNQ__0wDETrp-ag,1623
|
|
5
|
+
sumo/wrapper/_decorators.py,sha256=3IEi6GXVkkDACHoo8dOeDoBtZh5TlJ6Tw0qlpOVHqLQ,806
|
|
6
|
+
sumo/wrapper/_logging.py,sha256=jOtMpiVJcF38QBM4ER1VDdHom777L5MkfomtOVHXgu8,1060
|
|
7
|
+
sumo/wrapper/_retry_strategy.py,sha256=m4mK-ZQDr0CSOZGN9ZleZyRSR07PjUjAis3WXXR4jwk,2490
|
|
8
|
+
sumo/wrapper/_version.py,sha256=f2afgyfNj59Aqh0DnuaBrzxyqz1K0o3bJu1DsISS4g4,413
|
|
9
|
+
sumo/wrapper/config.py,sha256=6t7qqjrrmd11m4VMlRryiMYw2JDU_R51305woAP1TAs,865
|
|
10
|
+
sumo/wrapper/login.py,sha256=PGYhKnrwV4NorNbwnWj-5LDvCCIKgn-pnvCTeCDvqXA,2375
|
|
11
|
+
sumo/wrapper/sumo_client.py,sha256=pDJNWSxsTolZWo-xON45bjtVuq3TdiJFTq3R2U_kzhU,18330
|
|
12
|
+
sumo_wrapper_python-1.0.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
13
|
+
sumo_wrapper_python-1.0.23.dist-info/METADATA,sha256=__ZBI1la4s9lygtBzmlPEC2U8NlYJCiZBPV9RLaCXiA,14593
|
|
14
|
+
sumo_wrapper_python-1.0.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
15
|
+
sumo_wrapper_python-1.0.23.dist-info/entry_points.txt,sha256=V_vGky2C3He5vohJAxnBdvpt_fqfUDFj5irUm9HtoFc,55
|
|
16
|
+
sumo_wrapper_python-1.0.23.dist-info/top_level.txt,sha256=rLbKyH9rWgCj3PoLeR7fvC5X8vCaUc5LF8-Y_GBWZL0,5
|
|
17
|
+
sumo_wrapper_python-1.0.23.dist-info/RECORD,,
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
sumo/__init__.py,sha256=ftS-xRPSH-vU7fIHlnZQaCTWbNvs4owJivNW65kzsIM,85
|
|
2
|
-
sumo/wrapper/__init__.py,sha256=JK6iMAy2Fdrc7iaIHTn60fHPdRvsgNjZwWD6DJtGUYQ,235
|
|
3
|
-
sumo/wrapper/_auth_provider.py,sha256=rmnqRm_o5D9DLt4XBtiJ_CIWV3PJ-BVbq6lFGaPNtUg,14665
|
|
4
|
-
sumo/wrapper/_blob_client.py,sha256=SyfyFZ1hHVWKU4lmgUqSjl5TaK_OJNQ__0wDETrp-ag,1623
|
|
5
|
-
sumo/wrapper/_decorators.py,sha256=3IEi6GXVkkDACHoo8dOeDoBtZh5TlJ6Tw0qlpOVHqLQ,806
|
|
6
|
-
sumo/wrapper/_logging.py,sha256=jOtMpiVJcF38QBM4ER1VDdHom777L5MkfomtOVHXgu8,1060
|
|
7
|
-
sumo/wrapper/_retry_strategy.py,sha256=qDgl_FLec94fzZaCG__BT8tO4O-D5cZ2_JRYw1zjVTI,2495
|
|
8
|
-
sumo/wrapper/_version.py,sha256=i5YNpOqJi5ga7622RoO_H7qsCctndrnXe5nHT2I-0OA,413
|
|
9
|
-
sumo/wrapper/config.py,sha256=6t7qqjrrmd11m4VMlRryiMYw2JDU_R51305woAP1TAs,865
|
|
10
|
-
sumo/wrapper/login.py,sha256=PGYhKnrwV4NorNbwnWj-5LDvCCIKgn-pnvCTeCDvqXA,2375
|
|
11
|
-
sumo/wrapper/sumo_client.py,sha256=vWmiQgUJG9hE4YCORujSs4HbsPIEasFXBKk3DiL48fY,17708
|
|
12
|
-
sumo_wrapper_python-1.0.22.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
13
|
-
sumo_wrapper_python-1.0.22.dist-info/METADATA,sha256=l63vM35g9ecsxfF6RhCt_oEIMApzBlZHC7HEJ0enrA8,14593
|
|
14
|
-
sumo_wrapper_python-1.0.22.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
15
|
-
sumo_wrapper_python-1.0.22.dist-info/entry_points.txt,sha256=V_vGky2C3He5vohJAxnBdvpt_fqfUDFj5irUm9HtoFc,55
|
|
16
|
-
sumo_wrapper_python-1.0.22.dist-info/top_level.txt,sha256=rLbKyH9rWgCj3PoLeR7fvC5X8vCaUc5LF8-Y_GBWZL0,5
|
|
17
|
-
sumo_wrapper_python-1.0.22.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{sumo_wrapper_python-1.0.22.dist-info → sumo_wrapper_python-1.0.23.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|