Skip to content

Commit b0a1bdc

Browse files
committed
Merge branch 'dev' - ver. 0.2.0
2 parents ce5ba6f + 6c2a185 commit b0a1bdc

25 files changed

Lines changed: 2072 additions & 897 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ config.json
99
# other
1010
**/__pycache__
1111
**/categories.json
12+
**/slots.json

LICENSE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
MIT License
23

3-
Copyright 2025 Emanuele D'Amico
4+
Copyright 2025 Emanuele D'Amico (AMORE), the jQuery Team (jQuery),
5+
SpryMedia Ltd (DataTables.net).
46

57
Permission is hereby granted, free of charge, to any person obtaining
68
a copy of this software and associated documentation files (the “Software”),

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ pip install -r requirements.txt
9191
python3 -m pip install flask requests
9292
```
9393

94-
Last but not least you should write a valid API key in your config file then run Python script `amore/scan_for_categories.py`.
94+
Last but not least you should write a valid API key in your config file then run Python script `amore/scan_elab.py`.
9595

9696
```bash
9797
echo '{ "API_KEY": "<key_here>" }' > ./config.json
98-
python amore/scan_for_categories.py
98+
python amore/scan_elab.py
9999
```
100100

101101
#### Authenticating and running

amore/api/auth.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"""
2020

2121
def check_apikey(KEY=""):
22+
'''
23+
Checks if a given API key is valid and has writing permissions.
24+
If yes it fetches and returns the full name of the user to whom
25+
the key belongs. If not it raises errors accordingly.
26+
'''
2227
# No sense proceeding if the user somehow submitted an empty key...
2328
if KEY == "":
2429
raise Exception('You submitted an empty key.')
@@ -28,11 +33,18 @@ def check_apikey(KEY=""):
2833
"Authorization": KEY,
2934
"Content-Type": "application/json"
3035
}
31-
response = requests.get(
32-
url=endpoint,
33-
headers=header,
34-
verify=ssl_verification,
35-
)
36+
try:
37+
response = requests.get(
38+
url=endpoint,
39+
headers=header,
40+
verify=ssl_verification,
41+
)
42+
except requests.exceptions.ConnectionError as ce:
43+
if "NewConnectionError" in str(ce):
44+
raise ConnectionError("Your eLabFTW server might currently be down.")
45+
else:
46+
raise Exception("General connection error.")
47+
3648
# Check zero: is the request not accepted by the server?
3749
if response.status_code // 100 == 5:
3850
raise Exception("There's a problem on the server. Try asking the sysadmin.")
@@ -48,14 +60,17 @@ def check_apikey(KEY=""):
4860
key_can_write = last_used['rw']
4961
# Last check: is the key read only?
5062
if key_can_write == 0:
51-
raise Exception(f"API key is read-only, not read/write.<br>Please use (eventually create) one with read/write permissions.")
63+
raise PermissionError(f"API key is read-only, not read/write.<br>Please use (eventually create) one with read/write permissions.")
5264

5365
# If AND ONLY IF the key exists, is valid and is not read-only, return user's full name:
5466
endpoint = f"{API_URL}api/v2/users/me/"
5567
response = requests.get(
5668
url=endpoint,
5769
headers=header,
5870
verify=ssl_verification,
59-
)
60-
user = response.json()['fullname']
71+
).json()
72+
user = {
73+
"fullname": response.get("fullname"),
74+
"userid": response.get("userid")
75+
}
6176
return user

0 commit comments

Comments
 (0)