benchling-sdk 1.11.0a0__py3-none-any.whl → 1.11.0a2__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.
- benchling_sdk/auth/client_credentials_oauth2.py +24 -9
- {benchling_sdk-1.11.0a0.dist-info → benchling_sdk-1.11.0a2.dist-info}/METADATA +1 -1
- {benchling_sdk-1.11.0a0.dist-info → benchling_sdk-1.11.0a2.dist-info}/RECORD +5 -5
- {benchling_sdk-1.11.0a0.dist-info → benchling_sdk-1.11.0a2.dist-info}/LICENSE +0 -0
- {benchling_sdk-1.11.0a0.dist-info → benchling_sdk-1.11.0a2.dist-info}/WHEEL +0 -0
@@ -1,13 +1,17 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import base64
|
2
4
|
from datetime import datetime, timedelta
|
5
|
+
from json import JSONDecodeError
|
3
6
|
import threading
|
4
|
-
from typing import Optional
|
7
|
+
from typing import NoReturn, Optional
|
5
8
|
from urllib.parse import urljoin
|
6
9
|
|
7
10
|
from benchling_api_client.v2.benchling_client import AuthorizationMethod, BenchlingApiClient
|
8
11
|
import httpx
|
9
12
|
|
10
13
|
from benchling_sdk.errors import BenchlingError
|
14
|
+
from benchling_sdk.helpers.logging_helpers import sdk_logger
|
11
15
|
|
12
16
|
MINIMUM_TOKEN_EXPIRY_BUFFER = 60
|
13
17
|
|
@@ -30,7 +34,7 @@ class Token:
|
|
30
34
|
return datetime.now() < self.refresh_time
|
31
35
|
|
32
36
|
@classmethod
|
33
|
-
def from_token_response(cls, token_response):
|
37
|
+
def from_token_response(cls, token_response) -> Token:
|
34
38
|
"""
|
35
39
|
Construct Token from deserializing token endpoint response.
|
36
40
|
|
@@ -107,13 +111,7 @@ class ClientCredentialsOAuth2(AuthorizationMethod):
|
|
107
111
|
as_json = response.json()
|
108
112
|
self._token = Token.from_token_response(as_json)
|
109
113
|
else:
|
110
|
-
|
111
|
-
status_code=response.status_code,
|
112
|
-
headers=response.headers,
|
113
|
-
json=response.json(),
|
114
|
-
content=response.content,
|
115
|
-
parsed=None,
|
116
|
-
)
|
114
|
+
_raise_error_from_response(response)
|
117
115
|
|
118
116
|
def get_authorization_header(self, base_url: str) -> str:
|
119
117
|
"""
|
@@ -127,3 +125,20 @@ class ClientCredentialsOAuth2(AuthorizationMethod):
|
|
127
125
|
self.vend_new_token(base_url)
|
128
126
|
assert self._token is not None
|
129
127
|
return f"Bearer {self._token.access_token}"
|
128
|
+
|
129
|
+
|
130
|
+
def _raise_error_from_response(response: httpx.Response) -> NoReturn:
|
131
|
+
json_content = None
|
132
|
+
# Rather than rely on Content-Type header, try to parse JSON
|
133
|
+
# If the response isn't JSON, just swallow the exception
|
134
|
+
try:
|
135
|
+
json_content = response.json()
|
136
|
+
except JSONDecodeError as e:
|
137
|
+
sdk_logger.debug("Received error response without JSON OAuth vending token", e)
|
138
|
+
raise BenchlingError(
|
139
|
+
status_code=response.status_code,
|
140
|
+
headers=response.headers,
|
141
|
+
json=json_content,
|
142
|
+
content=response.content,
|
143
|
+
parsed=None,
|
144
|
+
)
|
@@ -26,7 +26,7 @@ benchling_sdk/apps/types.py,sha256=TBTfAB3IOoZjZqzTOK25kN3b6RTU9Z7tOMdBbq6u8lA,1
|
|
26
26
|
benchling_sdk/auth/__init__.py,sha256=N4pJYVUnTLzg5HO9ZldHaI-Am97i6AOCdQS0M5QcVpA,120
|
27
27
|
benchling_sdk/auth/api_key_auth.py,sha256=Ui-cnvGMjcwVPV_b2GdBaoTjEyHJIu9CjtZScVBEUvU,641
|
28
28
|
benchling_sdk/auth/bearer_token_auth.py,sha256=nymI8V91evcnK-TWKkBXZwck8U1qSh4WaseyQbvF-Cg,1268
|
29
|
-
benchling_sdk/auth/client_credentials_oauth2.py,sha256=
|
29
|
+
benchling_sdk/auth/client_credentials_oauth2.py,sha256=auHj8FAJxUrDf1HJp9wfmcC_pJ-3rj4tdQbsUIvSUQs,5801
|
30
30
|
benchling_sdk/benchling.py,sha256=eED0ge5hWspr1kFFZ1fOovPvw-JdVKhylAGT-n_GUSA,25943
|
31
31
|
benchling_sdk/docs/__init__.py,sha256=ySHo76PzLndmXOVWrF80VjB5Pi48G82CCQNdzUEzbCY,38
|
32
32
|
benchling_sdk/docs/__main__.py,sha256=1ZlGXdn2gHGC0fAuan5i54mh35VkDf5mhY9VeKNyCRA,244
|
@@ -115,7 +115,7 @@ benchling_sdk/services/v2/v2_alpha_service.py,sha256=vNfYK0Dheml9ozR_0tzTlA3blPD
|
|
115
115
|
benchling_sdk/services/v2/v2_beta_service.py,sha256=0vbjFFfPQNUGUhckR_cnzGjypRMBpBP6c5c49zrA3mk,11564
|
116
116
|
benchling_sdk/services/v2/v2_stable_service.py,sha256=YIc-_0p6x1NQqj7awnWgCTHxbxYO7ZOolePZyW90whc,35246
|
117
117
|
benchling_sdk/services/v2_service.py,sha256=3eoIjYEmGLPdWCpBN0pl7q7_HNWCsUvfvTn3Hcz0wSM,2860
|
118
|
-
benchling_sdk-1.11.
|
119
|
-
benchling_sdk-1.11.
|
120
|
-
benchling_sdk-1.11.
|
121
|
-
benchling_sdk-1.11.
|
118
|
+
benchling_sdk-1.11.0a2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
119
|
+
benchling_sdk-1.11.0a2.dist-info/METADATA,sha256=3EWwCQDYWFZq3y_mtICWlnsZvpAkFk-dPHHveVIjRSA,2126
|
120
|
+
benchling_sdk-1.11.0a2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
121
|
+
benchling_sdk-1.11.0a2.dist-info/RECORD,,
|
File without changes
|
File without changes
|