Skip to content

Commit eba6624

Browse files
authored
Merge pull request #152 from MerginMaps/config-server-type
use new api for server_type and workspace services
2 parents 3e33c82 + 1a2ae1e commit eba6624

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

mergin/client.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def user_service(self):
319319
Requests information about user from /user/service endpoint if such exists in self.url server.
320320
321321
Returns response from server as JSON dict or None if endpoint is not found
322+
This can be removed once our SaaS server is upgraded to support workspaces
322323
"""
323324

324325
try:
@@ -331,6 +332,24 @@ def user_service(self):
331332

332333
return response
333334

335+
def workspace_service(self, workspace_id):
336+
"""
337+
This Requests information about a workspace service from /workspace/{id}/service endpoint,
338+
if such exists in self.url server.
339+
340+
Returns response from server as JSON dict or None if endpoint is not found
341+
"""
342+
343+
try:
344+
response = self.get(f"/v1/workspace/{workspace_id}/service")
345+
except ClientError as e:
346+
self.log.debug(f"Unable to query for /workspace/{workspace_id}/service endpoint")
347+
return
348+
349+
response = json.loads(response.read())
350+
351+
return response
352+
334353
def server_type(self):
335354
"""
336355
Returns the deployment type of the server
@@ -344,11 +363,13 @@ def server_type(self):
344363
try:
345364
resp = self.get("/config")
346365
config = json.load(resp)
347-
if "user_workspaces_allowed" in config:
348-
self._server_type = ServerType.EE
349-
if "global_workspace" in config:
366+
if config["server_type"] == "ce":
350367
self._server_type = ServerType.CE
351-
except ClientError as e:
368+
elif config["server_type"] == "ee":
369+
self._server_type = ServerType.EE
370+
elif config["server_type"] == "saas":
371+
self._server_type = ServerType.SAAS
372+
except (ClientError, KeyError):
352373
self._server_type = ServerType.OLD
353374

354375
return self._server_type

0 commit comments

Comments
 (0)