sumo-wrapper-python 1.0.21__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.

@@ -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.join(os.path.expanduser("~"), ".sumo")
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
- os.path.expanduser("~"),
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(
@@ -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, 504]
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
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.0.21'
16
- __version_tuple__ = version_tuple = (1, 0, 21)
15
+ __version__ = version = '1.0.23'
16
+ __version_tuple__ = version_tuple = (1, 0, 23)
@@ -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
- self._client = httpx.Client()
58
- self._async_client = httpx.AsyncClient()
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._client.close()
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
- await self._async_client.aclose()
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
- if self._async_client is not None:
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:
@@ -1,9 +1,9 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: sumo-wrapper-python
3
- Version: 1.0.21
3
+ Version: 1.0.23
4
4
  Summary: Python wrapper for the Sumo API
5
5
  Author: Equinor
6
- License: Apache License
6
+ License: Apache License
7
7
  Version 2.0, January 2004
8
8
  http://www.apache.org/licenses/
9
9
 
@@ -208,7 +208,7 @@ License: Apache License
208
208
  Project-URL: Repository, https://github.com/equinor/sumo-wrapper-python
209
209
  Classifier: License :: OSI Approved :: Apache Software License
210
210
  Classifier: Programming Language :: Python
211
- Requires-Python: >=3.8
211
+ Requires-Python: >=3.9
212
212
  Description-Content-Type: text/markdown
213
213
  License-File: LICENSE
214
214
  Requires-Dist: msal>=1.20.0
@@ -217,18 +217,18 @@ Requires-Dist: pyjwt>=2.4.0
217
217
  Requires-Dist: httpx>=0.24.1
218
218
  Requires-Dist: tenacity!=8.4.0,>=8.2.2
219
219
  Requires-Dist: azure-identity>=1.13.0
220
- Provides-Extra: dev
221
- Requires-Dist: ruff; extra == "dev"
222
- Requires-Dist: pre-commit; extra == "dev"
220
+ Provides-Extra: test
221
+ Requires-Dist: pytest; extra == "test"
222
+ Requires-Dist: PyYAML; extra == "test"
223
223
  Provides-Extra: docs
224
224
  Requires-Dist: sphinx==7.1.2; extra == "docs"
225
225
  Requires-Dist: sphinx-rtd-theme; extra == "docs"
226
226
  Requires-Dist: autoapi; extra == "docs"
227
227
  Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
228
228
  Requires-Dist: sphinxcontrib-apidoc; extra == "docs"
229
- Provides-Extra: test
230
- Requires-Dist: pytest; extra == "test"
231
- Requires-Dist: PyYAML; extra == "test"
229
+ Provides-Extra: dev
230
+ Requires-Dist: ruff; extra == "dev"
231
+ Requires-Dist: pre-commit; extra == "dev"
232
232
 
233
233
  # sumo-wrapper-python
234
234
 
@@ -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,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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=9dn53xHvp9AcyvqzxPz05pNmF5wMs3xSD36JDF3TqOY,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.21.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
- sumo_wrapper_python-1.0.21.dist-info/METADATA,sha256=ubC5TldHlD_okArIUYzpDFo0NgWgo3CHnFY3IbJmOMc,14560
14
- sumo_wrapper_python-1.0.21.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
15
- sumo_wrapper_python-1.0.21.dist-info/entry_points.txt,sha256=V_vGky2C3He5vohJAxnBdvpt_fqfUDFj5irUm9HtoFc,55
16
- sumo_wrapper_python-1.0.21.dist-info/top_level.txt,sha256=rLbKyH9rWgCj3PoLeR7fvC5X8vCaUc5LF8-Y_GBWZL0,5
17
- sumo_wrapper_python-1.0.21.dist-info/RECORD,,