Skip to content

Commit f0be547

Browse files
committed
do not store _has_auth variable
1 parent 0018fd7 commit f0be547

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

mergin/client.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def __init__(
102102
self.client_version = "Python-client/" + __version__
103103
if plugin_version is not None: # this could be e.g. "Plugin/2020.1 QGIS/3.14"
104104
self.client_version += " " + plugin_version
105-
self._has_auth = auth_token is not None or login is not None or password is not None
106105
self.setup_logging()
107106
if auth_token:
108107
try:
@@ -196,28 +195,24 @@ def user_agent_info(self):
196195
def _check_token(f):
197196
"""Wrapper for creating/renewing authorization token."""
198197

199-
def wrapper(self, *args):
200-
201-
# if user has not provided auth information (token or login/password) it does not make sense to try these checks
202-
# the client without auth can still be used to access public information like server config
203-
if self._has_auth:
204-
if self._auth_session:
205-
# Refresh auth token if it expired or will expire very soon
206-
delta = self._auth_session["expire"] - datetime.now(timezone.utc)
207-
if delta.total_seconds() < 5:
208-
self.log.info("Token has expired - refreshing...")
209-
if self._auth_params.get("login", None) and self._auth_params.get("password", None):
210-
self.log.info("Token has expired - refreshing...")
211-
self.login(self._auth_params["login"], self._auth_params["password"])
212-
else:
213-
raise AuthTokenExpiredError("Token has expired - please re-login")
214-
else:
215-
# Create a new authorization token
216-
self.log.info(f"No token - login user: {self._auth_params.get('login', None)}")
198+
def wrapper(self, *args, **kwargs):
199+
if self._auth_session:
200+
# Refresh auth token if it expired or will expire very soon
201+
delta = self._auth_session["expire"] - datetime.now(timezone.utc)
202+
if delta.total_seconds() < 5:
203+
self.log.info("Token has expired - refreshing...")
217204
if self._auth_params.get("login", None) and self._auth_params.get("password", None):
205+
self.log.info("Token has expired - refreshing...")
218206
self.login(self._auth_params["login"], self._auth_params["password"])
219207
else:
220-
raise ClientError("Missing login or password")
208+
raise AuthTokenExpiredError("Token has expired - please re-login")
209+
else:
210+
# Create a new authorization token
211+
self.log.info(f"No token - login user: {self._auth_params.get('login', None)}")
212+
if self._auth_params.get("login", None) and self._auth_params.get("password", None):
213+
self.login(self._auth_params["login"], self._auth_params["password"])
214+
else:
215+
raise ClientError("Missing login or password")
221216

222217
return f(self, *args)
223218

0 commit comments

Comments
 (0)