fix(specklepy): small tweaks to the url handling of accounts (#452)
Publish Python Package / test (push) Has been cancelled
Publish Python Package / Build and Publish Python Package (push) Has been cancelled

* set url post query

* Use canonical url if available

* format

* revert canonical url changes

* quick tweak

* small tweak again

* Add test
This commit is contained in:
Jedd Morgan
2025-09-11 17:34:06 +01:00
committed by GitHub
parent ec67f5ba48
commit 2594ce0382
3 changed files with 19 additions and 14 deletions
+1
View File
@@ -142,6 +142,7 @@ class SpeckleClient:
self.account.userInfo.avatar = userData.avatar
self.account.serverInfo = self.server.get()
self.account.serverInfo.url = self.url
def authenticate_with_account(self, account: Account) -> None:
"""Authenticate the client using an Account object
+7 -6
View File
@@ -97,10 +97,11 @@ def initialise_tracker(account: Account | None = None):
if not METRICS_TRACKER:
METRICS_TRACKER = MetricsTracker()
if account and account.userInfo.email:
METRICS_TRACKER.set_last_user(account.userInfo.email)
if account and account.serverInfo.url:
METRICS_TRACKER.set_last_server(account.serverInfo.url)
if not account:
return
METRICS_TRACKER.set_last_user(account.userInfo.email)
METRICS_TRACKER.set_last_server(account.serverInfo.url)
class Singleton(type):
@@ -132,12 +133,12 @@ class MetricsTracker(metaclass=Singleton):
if node and user:
self.last_user = f"@{self.hash(f'{node}-{user}')}"
def set_last_user(self, email: str):
def set_last_user(self, email: str | None):
if not email:
return
self.last_user = f"@{self.hash(email)}"
def set_last_server(self, server: str):
def set_last_server(self, server: str | None):
if not server:
return
self.last_server = self.hash(server)
+11 -8
View File
@@ -8,11 +8,12 @@ import requests
from specklepy.api.client import SpeckleClient
from specklepy.core.api import operations
from specklepy.core.api.credentials import Account, UserInfo
from specklepy.core.api.enums import ProjectVisibility
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
from specklepy.core.api.inputs.version_inputs import CreateVersionInput
from specklepy.core.api.models import Version
from specklepy.core.api.models.current import Project
from specklepy.core.api.models.current import Project, ServerInfo
from specklepy.logging import metrics
from specklepy.objects.base import Base
from specklepy.objects.geometry import Point
@@ -89,13 +90,15 @@ def second_user_dict(host: str) -> Dict[str, str]:
def create_client(host: str, token: str) -> SpeckleClient:
client = SpeckleClient(host=host, use_ssl=False)
client.authenticate_with_token(token)
user = client.active_user.get()
assert user
client.account.userInfo.id = user.id
client.account.userInfo.email = user.email
client.account.userInfo.name = user.name
client.account.userInfo.company = user.company
client.account.userInfo.avatar = user.avatar
assert isinstance(client.account, Account)
assert isinstance(client.account.userInfo, UserInfo)
assert client.account.userInfo.id
assert client.account.userInfo.name
assert isinstance(client.account.serverInfo, ServerInfo)
assert client.account.serverInfo.url
assert client.account.serverInfo.name
return client