|
1 | | -import getpass |
| 1 | +# import getpass |
2 | 2 | import pprint |
3 | 3 | from collections.abc import Mapping |
4 | 4 |
|
5 | 5 | import httpx |
6 | 6 |
|
| 7 | +rest_api_method_map = { |
| 8 | + "login": ("POST", "/login"), |
| 9 | +} |
| 10 | + |
7 | 11 |
|
8 | 12 | class RequestParameterError(Exception): ... |
9 | 13 |
|
@@ -53,21 +57,22 @@ def __init__(self, *, base_url, timeout, request_fail_exceptions=True): |
53 | 57 | def ROOT_NODE_UID(self): |
54 | 58 | return self._root_node_uid |
55 | 59 |
|
| 60 | + @staticmethod |
56 | 61 | def gen_auth(username, password): |
57 | 62 | return httpx.BasicAuth(username=username, password=password) |
58 | 63 |
|
59 | 64 | def set_auth(self, *, username, password): |
60 | 65 | self._auth = self.gen_auth(username=username, password=password) |
61 | 66 |
|
62 | | - def set_username_password(self, username=None, password=None): |
63 | | - if not isinstance(username, str): |
64 | | - print("Username: ", end="") |
65 | | - username = input() |
66 | | - if not isinstance(password, str): |
67 | | - password = getpass.getpass() |
| 67 | + # def set_username_password(self, username=None, password=None): |
| 68 | + # if not isinstance(username, str): |
| 69 | + # print("Username: ", end="") |
| 70 | + # username = input() |
| 71 | + # if not isinstance(password, str): |
| 72 | + # password = getpass.getpass() |
68 | 73 |
|
69 | | - self._username = username |
70 | | - self._password = password |
| 74 | + # self._username = username |
| 75 | + # self._password = password |
71 | 76 |
|
72 | 77 | # # TODO: rewrite the logic in this function |
73 | 78 | # def _check_response(self, *, request, response): |
@@ -137,9 +142,10 @@ def _prepare_request( |
137 | 142 | kwargs.update({"auth": auth}) |
138 | 143 | return kwargs |
139 | 144 |
|
140 | | - def login(self, *, username=None, password=None): |
141 | | - params = {"username": self._username, "password": self._password} |
142 | | - self.send_request("POST", "/login", params=params) |
| 145 | + def _prepare_login(self, *, username=None, password=None): |
| 146 | + method, url = rest_api_method_map["login"] |
| 147 | + params = {"username": username, "password": password} |
| 148 | + return method, url, params |
143 | 149 |
|
144 | 150 | def get_node(self, node_uid): |
145 | 151 | return self.send_request("GET", f"/node/{node_uid}") |
|
0 commit comments