sumo-wrapper-python 1.0.22__py3-none-any.whl → 1.0.24__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.

@@ -4,7 +4,8 @@ import os
4
4
  import stat
5
5
  import sys
6
6
  import time
7
- from datetime import datetime, timedelta
7
+ from datetime import datetime, timedelta, timezone
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,7 @@ class AuthProvider:
91
89
  ) as f:
92
90
  f.write(token)
93
91
  protect_token_cache(self._resource_id, ".sharedkey", case_uuid)
92
+ return
94
93
 
95
94
  def has_case_token(self, case_uuid):
96
95
  return os.path.exists(
@@ -459,3 +458,31 @@ def get_auth_provider(
459
458
  ]
460
459
  ):
461
460
  return AuthProviderManaged(resource_id)
461
+
462
+
463
+ def cleanup_shared_keys():
464
+ tokendir = get_token_dir()
465
+ if not os.path.exists(tokendir):
466
+ return
467
+ for f in os.listdir(tokendir):
468
+ ff = os.path.join(tokendir, f)
469
+ if os.path.isfile(ff):
470
+ (name, ext) = os.path.splitext(ff)
471
+ if ext.lower() == ".sharedkey":
472
+ try:
473
+ with open(ff, "r") as file:
474
+ token = file.read()
475
+ pq = parse_qs(token)
476
+ se = pq["se"][0]
477
+ end = datetime.strptime(se, "%Y-%m-%dT%H:%M:%S.%fZ")
478
+ now = datetime.now(timezone.utc)
479
+ if now.timestamp() > end.timestamp():
480
+ os.unlink(ff)
481
+ pass
482
+ pass
483
+ pass
484
+ except Exception:
485
+ pass
486
+ pass
487
+ pass
488
+ return
@@ -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.22'
16
- __version_tuple__ = version_tuple = (1, 0, 22)
15
+ __version__ = version = '1.0.24'
16
+ __version_tuple__ = version_tuple = (1, 0, 24)
@@ -6,7 +6,7 @@ import re
6
6
  import httpx
7
7
  import jwt
8
8
 
9
- from ._auth_provider import get_auth_provider
9
+ from ._auth_provider import cleanup_shared_keys, get_auth_provider
10
10
  from ._blob_client import BlobClient
11
11
  from ._decorators import (
12
12
  raise_for_status,
@@ -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
 
@@ -81,6 +94,9 @@ class SumoClient:
81
94
  refresh_token = token
82
95
  pass
83
96
  pass
97
+
98
+ cleanup_shared_keys()
99
+
84
100
  self.auth = get_auth_provider(
85
101
  client_id=APP_REGISTRATION[env]["CLIENT_ID"],
86
102
  authority=f"{AUTHORITY_HOST_URI}/{TENANT_ID}",
@@ -103,7 +119,8 @@ class SumoClient:
103
119
  return self
104
120
 
105
121
  def __exit__(self, exc_type, exc_value, traceback):
106
- self._client.close()
122
+ if not self._borrowed_client:
123
+ self._client.close()
107
124
  self._client = None
108
125
  return False
109
126
 
@@ -111,16 +128,17 @@ class SumoClient:
111
128
  return self
112
129
 
113
130
  async def __aexit__(self, exc_type, exc_value, traceback):
114
- await self._async_client.aclose()
131
+ if not self._borrowed_async_client:
132
+ await self._async_client.aclose()
115
133
  self._async_client = None
116
134
  return False
117
135
 
118
136
  def __del__(self):
119
- if self._client is not None:
137
+ if self._client is not None and not self._borrowed_client:
120
138
  self._client.close()
121
- self._client = None
122
139
  pass
123
- if self._async_client is not None:
140
+ self._client = None
141
+ if self._async_client is not None and not self._borrowed_async_client:
124
142
 
125
143
  async def closeit(client):
126
144
  await client.aclose()
@@ -131,8 +149,8 @@ class SumoClient:
131
149
  loop.create_task(closeit(self._async_client))
132
150
  except RuntimeError:
133
151
  pass
134
- self._async_client = None
135
152
  pass
153
+ self._async_client = None
136
154
 
137
155
  def authenticate(self):
138
156
  if self.auth is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: sumo-wrapper-python
3
- Version: 1.0.22
3
+ Version: 1.0.24
4
4
  Summary: Python wrapper for the Sumo API
5
5
  Author: Equinor
6
6
  License: Apache License
@@ -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=kzX83bFB0LSZGmeOk7X25n3BZRSy2feuTvZRBQHaga0,15571
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=PF0E1bK4Ska3SfwaCeUjxIodUQ91NdMItZYbD8cLVXE,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=oeyYUB-sEDXrYcHkoQGGqlJYaB3y9GZ-zuO4-_iiP_U,18342
12
+ sumo_wrapper_python-1.0.24.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
13
+ sumo_wrapper_python-1.0.24.dist-info/METADATA,sha256=aWgVReg8IwBqTQ4YOdCFcW3HWBjexiRZ53s5uO3TNFQ,14593
14
+ sumo_wrapper_python-1.0.24.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
15
+ sumo_wrapper_python-1.0.24.dist-info/entry_points.txt,sha256=V_vGky2C3He5vohJAxnBdvpt_fqfUDFj5irUm9HtoFc,55
16
+ sumo_wrapper_python-1.0.24.dist-info/top_level.txt,sha256=rLbKyH9rWgCj3PoLeR7fvC5X8vCaUc5LF8-Y_GBWZL0,5
17
+ sumo_wrapper_python-1.0.24.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,,