-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathusername_password.py
More file actions
94 lines (76 loc) · 2.56 KB
/
Copy pathusername_password.py
File metadata and controls
94 lines (76 loc) · 2.56 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from firebolt.client.auth.base import AuthRequest, FireboltAuthVersion
from firebolt.client.auth.request_auth_base import _RequestBasedAuth
from firebolt.utils.urls import AUTH_URL
class UsernamePassword(_RequestBasedAuth):
"""Username/Password authentication class for Firebolt Database.
Gets authentication token using
provided credentials and updates it when it expires.
Args:
username (str): Username
password (str): Password
use_token_cache (bool): True if token should be cached in filesystem;
False otherwise
Attributes:
username (str): Username
password (str): Password
"""
__slots__ = (
"username",
"password",
"_token",
"_expires",
"_use_token_cache",
"_user_agent",
)
def __init__(
self,
username: str,
password: str,
use_token_cache: bool = True,
):
self.username = username
self.password = password
super().__init__(use_token_cache)
@property
def principal(self) -> str:
"""Get the principal (username) associated with the auth.
Returns:
str: Principal username
"""
return self.username
@property
def secret(self) -> str:
"""Get the secret (password) associated with the auth.
Returns:
str: Secret password
"""
return self.password
def get_firebolt_version(self) -> FireboltAuthVersion:
"""Get Firebolt version from auth.
Returns:
FireboltAuthVersion: V1 for Username Password authentication
"""
return FireboltAuthVersion.V1
def copy(self) -> "UsernamePassword":
"""Make another auth object with same credentials.
Returns:
UsernamePassword: Auth object
"""
return UsernamePassword(self.username, self.password, self._use_token_cache)
def _make_auth_request(self) -> AuthRequest:
"""Get new token using username and password.
Yields:
Request: An http request to get token. Expects Response to be sent back
Raises:
AuthenticationError: Error while authenticating with provided credentials
"""
response = self.request_class(
"POST",
AUTH_URL,
headers={
"Content-Type": "application/json;charset=UTF-8",
"User-Agent": self._user_agent,
},
json={"username": self.username, "password": self.password},
)
return response