biolmai 0.2.4__py2.py3-none-any.whl → 0.2.5__py2.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 biolmai might be problematic. Click here for more details.
- biolmai/__init__.py +1 -1
- biolmai/auth.py +56 -4
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/METADATA +1 -1
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/RECORD +9 -9
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/WHEEL +0 -0
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/entry_points.txt +0 -0
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/licenses/AUTHORS.rst +0 -0
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {biolmai-0.2.4.dist-info → biolmai-0.2.5.dist-info}/top_level.txt +0 -0
biolmai/__init__.py
CHANGED
biolmai/auth.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ast
|
|
1
2
|
import json
|
|
2
3
|
import os
|
|
3
4
|
import pprint
|
|
@@ -9,6 +10,47 @@ import requests
|
|
|
9
10
|
from biolmai.const import ACCESS_TOK_PATH, BASE_DOMAIN, GEN_TOKEN_URL, USER_BIOLM_DIR
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
def parse_credentials_file(file_path):
|
|
14
|
+
"""Parse credentials file, handling JSON, Python dict syntax, and mixed types.
|
|
15
|
+
|
|
16
|
+
Returns a dict with 'access' and 'refresh' keys as strings, or None if parsing fails.
|
|
17
|
+
Uses ast.literal_eval() which is safe and only evaluates Python literals.
|
|
18
|
+
"""
|
|
19
|
+
try:
|
|
20
|
+
with open(file_path, 'r') as f:
|
|
21
|
+
content = f.read().strip()
|
|
22
|
+
|
|
23
|
+
# Try JSON first
|
|
24
|
+
try:
|
|
25
|
+
data = json.loads(content)
|
|
26
|
+
except json.JSONDecodeError:
|
|
27
|
+
# Fall back to safe Python literal evaluation for dict syntax like {access: 123, refresh: 456}
|
|
28
|
+
# ast.literal_eval() is safe - it only evaluates literals, no code execution
|
|
29
|
+
try:
|
|
30
|
+
data = ast.literal_eval(content)
|
|
31
|
+
except (ValueError, SyntaxError):
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
# Ensure we have a dictionary
|
|
35
|
+
if not isinstance(data, dict):
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
# Extract access and refresh, converting to strings
|
|
39
|
+
access = data.get("access")
|
|
40
|
+
refresh = data.get("refresh")
|
|
41
|
+
|
|
42
|
+
# Convert to strings if they exist
|
|
43
|
+
if access is not None:
|
|
44
|
+
access = str(access)
|
|
45
|
+
if refresh is not None:
|
|
46
|
+
refresh = str(refresh)
|
|
47
|
+
|
|
48
|
+
return {"access": access, "refresh": refresh}
|
|
49
|
+
|
|
50
|
+
except Exception:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
12
54
|
def validate_user_auth(api_token=None, access=None, refresh=None):
|
|
13
55
|
"""Validates an API token, to be used as 'Authorization: Token 1235abc'
|
|
14
56
|
authentication method."""
|
|
@@ -61,8 +103,12 @@ def get_auth_status():
|
|
|
61
103
|
elif os.path.exists(ACCESS_TOK_PATH):
|
|
62
104
|
msg = f"Credentials file found {ACCESS_TOK_PATH}. Validating token..."
|
|
63
105
|
click.echo(msg)
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
access_refresh_dict = parse_credentials_file(ACCESS_TOK_PATH)
|
|
107
|
+
if access_refresh_dict is None:
|
|
108
|
+
click.echo(f"Error reading credentials file {ACCESS_TOK_PATH}.")
|
|
109
|
+
click.echo("The file may be corrupted or contain invalid data.")
|
|
110
|
+
click.echo("Please login again by running `biolmai login`.")
|
|
111
|
+
return
|
|
66
112
|
access = access_refresh_dict.get("access")
|
|
67
113
|
refresh = access_refresh_dict.get("refresh")
|
|
68
114
|
resp = validate_user_auth(access=access, refresh=refresh)
|
|
@@ -156,8 +202,14 @@ def get_user_auth_header():
|
|
|
156
202
|
if api_token:
|
|
157
203
|
headers = {"Authorization": f"Token {api_token}"}
|
|
158
204
|
elif os.path.exists(ACCESS_TOK_PATH):
|
|
159
|
-
|
|
160
|
-
|
|
205
|
+
access_refresh_dict = parse_credentials_file(ACCESS_TOK_PATH)
|
|
206
|
+
if access_refresh_dict is None:
|
|
207
|
+
err = (
|
|
208
|
+
f"Error reading credentials file {ACCESS_TOK_PATH}. "
|
|
209
|
+
"The file may be corrupted or contain invalid data. "
|
|
210
|
+
"Please run `biolmai login` to re-authenticate."
|
|
211
|
+
)
|
|
212
|
+
raise AssertionError(err)
|
|
161
213
|
access = access_refresh_dict.get("access")
|
|
162
214
|
refresh = access_refresh_dict.get("refresh")
|
|
163
215
|
headers = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
biolmai/__init__.py,sha256=
|
|
1
|
+
biolmai/__init__.py,sha256=Gt1leXWNTQMB_CEaZP16IqKYBHVx5Rl8gKFmwS_-uSI,693
|
|
2
2
|
biolmai/api.py,sha256=tqxQ-FoZosE88YmLJPQKskjNQdcb5jzZccywGP73lDc,13002
|
|
3
3
|
biolmai/asynch.py,sha256=BVypJhhEEK2Bek2AhqNGn7FIRJehAbJflUdeeslbXFE,9073
|
|
4
|
-
biolmai/auth.py,sha256=
|
|
4
|
+
biolmai/auth.py,sha256=cjU0ZTJAWTg8IdOYYQ1d-jLXinkYN1EbAyt12lJohgg,8317
|
|
5
5
|
biolmai/biolmai.py,sha256=_NxDPiwT7cnKgnRCRoGZvzBd4jVHJ8DNCuSu3FTznCs,4373
|
|
6
6
|
biolmai/cli.py,sha256=bdb4q8QlN73A6Ttz0e-dBIwoct7PYqy5WSc52jCMIyU,1967
|
|
7
7
|
biolmai/client.py,sha256=nD6sjjnQGinn0tzDVxaKWhsw2AQ3VNhgbsX-Smm9ghc,28310
|
|
@@ -10,10 +10,10 @@ biolmai/const.py,sha256=vCSj-itsusZWoLR27DYQSpuq024GQz3-uKJuDUoPF0Y,1153
|
|
|
10
10
|
biolmai/ltc.py,sha256=al7HZc5tLyUR5fmpIb95hOz5ctudVsc0xzjd_c2Ew3M,49
|
|
11
11
|
biolmai/payloads.py,sha256=BOhEKl9kWkKMXy1YiNw2_eC6MJ4Dn6vKNvkhEBsM7Lw,1735
|
|
12
12
|
biolmai/validate.py,sha256=58XMWrdWoDRmfiNAayWqrYaH3_bjRmEpG_yx6XSjTrM,4168
|
|
13
|
-
biolmai-0.2.
|
|
14
|
-
biolmai-0.2.
|
|
15
|
-
biolmai-0.2.
|
|
16
|
-
biolmai-0.2.
|
|
17
|
-
biolmai-0.2.
|
|
18
|
-
biolmai-0.2.
|
|
19
|
-
biolmai-0.2.
|
|
13
|
+
biolmai-0.2.5.dist-info/licenses/AUTHORS.rst,sha256=TB_ACuFPgVmxn1NspYwksTdT6jdZeShcxfafmi-XWKQ,158
|
|
14
|
+
biolmai-0.2.5.dist-info/licenses/LICENSE,sha256=8yt0SdP38I7a3g0zWqZjNe0VSDQhJA4bWLQSqqKtAVg,583
|
|
15
|
+
biolmai-0.2.5.dist-info/METADATA,sha256=oIrF-Bn8ujjYoZmJfbofhQ4alJBzGEQ-vt27pOTWK0s,4619
|
|
16
|
+
biolmai-0.2.5.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
|
17
|
+
biolmai-0.2.5.dist-info/entry_points.txt,sha256=ylQnDpCYrxF1F9z_T7NRQcYMWYF5ia_KsTUuboxjEAM,44
|
|
18
|
+
biolmai-0.2.5.dist-info/top_level.txt,sha256=jyQO45JN3g_jbdI8WqMnb0aEIzf4h1MrmPAZkKgfnwY,8
|
|
19
|
+
biolmai-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|