Skip to content

Commit 31787f3

Browse files
authored
Merge branch 'master' into non_blocking_push
2 parents 4500d0b + cc5e9d5 commit 31787f3

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Here you can find some tailored Jupyter Notebooks examples on how to interact wi
55
These examples are split into scenarios in order to highlight some of the core capabilities of the Mergin Maps API.
66

77
## [Scenario 1](01_users.ipynb) - Users Management
8-
On this scenario you'll create some random users from an existing CSV into Mergin Maps, change user's `ROLE` on a `WORKSPACE` and `PROJECT` perspective as well remove user's from a specific project.
8+
In this scenario you'll create some random users from an existing CSV into Mergin Maps, change user's `ROLE` on a `WORKSPACE` and `PROJECT` perspective as well remove a user from a specific project.
99

10-
## [Scenario 2](02_sync.ipynb) - Synchronization
11-
On this scenario you'll learn on how to do basic synchronisation (`PUSH`, `PULL`) of projects with the Mergin Maps Python API client.
10+
## [Scenario 2](02_sync.ipynb) - Synchronisation
11+
In this scenario you'll learn how to do basic synchronisation (`PUSH`, `PULL`) of projects with the Mergin Maps Python API client.
1212

1313
## [Scenario 3](03_projects.ipynb) - Projects Management
14-
On this scenario you'll learn how to manage project with the Mergin Maps Python API client, namely how to clone projects and how to separate team members in isolated projects from the cloned template.
14+
In this scenario you'll learn how to manage projects with Mergin Maps Python API client, namely how to clone projects and how to separate team members in isolated projects from the cloned template.

mergin/client.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class TokenError(Exception):
4545
pass
4646

4747

48+
class AuthTokenExpiredError(Exception):
49+
pass
50+
51+
4852
class ServerType(Enum):
4953
OLD = auto() # Server is old and does not support workspaces
5054
CE = auto() # Server is Community Edition
@@ -80,7 +84,15 @@ class MerginClient:
8084
Currently, only HTTP proxies are supported.
8185
"""
8286

83-
def __init__(self, url=None, auth_token=None, login=None, password=None, plugin_version=None, proxy_config=None):
87+
def __init__(
88+
self,
89+
url=None,
90+
auth_token=None,
91+
login=None,
92+
password=None,
93+
plugin_version=None,
94+
proxy_config=None,
95+
):
8496
self.url = (url if url is not None else MerginClient.default_url()).rstrip("/") + "/"
8597
self._auth_params = None
8698
self._auth_session = None
@@ -190,11 +202,19 @@ def wrapper(self, *args):
190202
delta = self._auth_session["expire"] - datetime.now(timezone.utc)
191203
if delta.total_seconds() < 5:
192204
self.log.info("Token has expired - refreshing...")
193-
self.login(self._auth_params["login"], self._auth_params["password"])
205+
if self._auth_params.get("login", None) and self._auth_params.get("password", None):
206+
self.log.info("Token has expired - refreshing...")
207+
self.login(self._auth_params["login"], self._auth_params["password"])
208+
else:
209+
raise AuthTokenExpiredError("Token has expired - please re-login")
194210
else:
195211
# Create a new authorization token
196212
self.log.info(f"No token - login user: {self._auth_params['login']}")
197-
self.login(self._auth_params["login"], self._auth_params["password"])
213+
if self._auth_params.get("login", None) and self._auth_params.get("password", None):
214+
self.login(self._auth_params["login"], self._auth_params["password"])
215+
else:
216+
raise ClientError("Missing login or password")
217+
198218
return f(self, *args)
199219

200220
return wrapper

mergin/test/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,3 +2878,18 @@ def server_config(self):
28782878

28792879
with pytest.raises(ClientError, match="The requested URL was not found on the server"):
28802880
mc.send_logs(logs_path)
2881+
2882+
2883+
def test_mc_without_login():
2884+
2885+
# client without login should be able to access server config
2886+
mc = MerginClient(SERVER_URL)
2887+
config = mc.server_config()
2888+
assert config
2889+
assert isinstance(config, dict)
2890+
assert "server_configured" in config
2891+
assert config["server_configured"]
2892+
2893+
# without login should not be able to access workspaces
2894+
with pytest.raises(ClientError, match="Authentication information is missing or invalid."):
2895+
mc.workspaces_list()

0 commit comments

Comments
 (0)