-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathusers.py
44 lines (32 loc) · 981 Bytes
/
users.py
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
36
37
38
39
40
41
42
43
44
from .util import from_dict
from dataclasses import dataclass
from requests import Session
from typing import Optional
@dataclass
class Role:
id: str
name: str
@dataclass
class User:
"""An authenticated axiom user."""
id: str
name: str
email: str
role: Role
class UsersClient:
"""The UsersClient is a client for the Axiom Users service."""
has_personal_token: bool
def __init__(self, session: Session, has_personal_token: bool):
self.session = session
self.has_personal_token = has_personal_token
def current(self) -> Optional[User]:
"""
Get the current authenticated user.
If your token is not a personal token, this will return None.
See https://axiom.co/docs/restapi/endpoints/getCurrentUser
"""
if not self.has_personal_token:
return None
res = self.session.get("/v2/user")
user = from_dict(User, res.json())
return user