|
1 | 1 | import copy |
2 | 2 | import io |
| 3 | +import logging |
3 | 4 | from pathlib import Path |
4 | 5 | from typing import Iterable |
5 | 6 | from typing import List |
@@ -43,13 +44,14 @@ def __call__(cls, *args, **kwargs): |
43 | 44 | def get_instance(cls): |
44 | 45 | if cls._instances: |
45 | 46 | return cls._instances[cls] |
| 47 | + return cls() |
46 | 48 |
|
47 | 49 |
|
48 | 50 | class BaseController(metaclass=SingleInstanceMetaClass): |
49 | | - def __init__(self, logger, config_path=constances.CONFIG_FILE_LOCATION): |
| 51 | + def __init__(self, config_path=constances.CONFIG_FILE_LOCATION): |
50 | 52 | self._config_path = None |
51 | 53 | self._backend_client = None |
52 | | - self._logger = logger |
| 54 | + self._logger = logging.getLogger("root") |
53 | 55 | self._s3_upload_auth_data = None |
54 | 56 | self._projects = None |
55 | 57 | self._folders = None |
@@ -93,17 +95,17 @@ def init(self, config_path): |
93 | 95 | self._backend_client.api_url = main_endpoint |
94 | 96 | self._backend_client._auth_token = token |
95 | 97 | self._backend_client.get_session.cache_clear() |
96 | | - token = self.configs.get_one("token").value |
97 | | - self.validate_token(token) |
98 | | - self._team_id = int(token.split("=")[-1]) |
| 98 | + if self.is_valid_token(token): |
| 99 | + self._team_id = int(token.split("=")[-1]) |
99 | 100 | self._team = None |
100 | 101 |
|
101 | 102 | @staticmethod |
102 | | - def validate_token(token: str): |
| 103 | + def is_valid_token(token: str): |
103 | 104 | try: |
104 | | - return int(token.split("=")[-1]) |
| 105 | + int(token.split("=")[-1]) |
| 106 | + return True |
105 | 107 | except Exception: |
106 | | - raise AppException("Invalid token.") |
| 108 | + return False |
107 | 109 |
|
108 | 110 | @property |
109 | 111 | def config_path(self): |
@@ -181,6 +183,8 @@ def configs(self): |
181 | 183 | @property |
182 | 184 | def team_id(self) -> int: |
183 | 185 | if not self._team_id: |
| 186 | + if not self.is_valid_token(self.configs.get_one("token").value): |
| 187 | + raise AppException("Invalid token.") |
184 | 188 | self._team_id = int(self.configs.get_one("token").value.split("=")[-1]) |
185 | 189 | return self._team_id |
186 | 190 |
|
@@ -208,8 +212,8 @@ def s3_repo(self): |
208 | 212 |
|
209 | 213 |
|
210 | 214 | class Controller(BaseController): |
211 | | - def __init__(self, logger, config_path=constances.CONFIG_FILE_LOCATION): |
212 | | - super().__init__(logger, config_path) |
| 215 | + def __init__(self, config_path=constances.CONFIG_FILE_LOCATION): |
| 216 | + super().__init__(config_path) |
213 | 217 | self._team = None |
214 | 218 |
|
215 | 219 | def _get_project(self, name: str): |
|
0 commit comments