-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibapi.py
More file actions
35 lines (22 loc) · 733 Bytes
/
libapi.py
File metadata and controls
35 lines (22 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import libuser
import random
import hashlib
from pathlib import Path
def keygen(username, password=None):
if password:
if not libuser.login(username, password):
return None
key = hashlib.sha256(str(random.getrandbits(2048)).encode()).hexdigest()
for f in Path("/tmp/").glob("vulpy.apikey." + username + ".*"):
print("removing", f)
f.unlink()
keyfile = f"/tmp/vulpy.apikey.{username}.{key}"
Path(keyfile).touch()
return key
def authenticate(request):
if "X-APIKEY" not in request.headers:
return None
key = request.headers["X-APIKEY"]
for f in Path("/tmp/").glob("vulpy.apikey.*." + key):
return f.name.split(".")[2]
return None