From 663be627c4653680f506884f0d7e90b35cf2d059 Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Wed, 11 Oct 2023 22:42:08 +0200 Subject: [PATCH] feat: login_as_guest added to sy and domain client --- packages/syft/src/syft/__init__.py | 1 + packages/syft/src/syft/client/client.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/syft/src/syft/__init__.py b/packages/syft/src/syft/__init__.py index 001c6b81dd4..1dc85763e43 100644 --- a/packages/syft/src/syft/__init__.py +++ b/packages/syft/src/syft/__init__.py @@ -12,6 +12,7 @@ from .abstract_node import NodeType # noqa: F401 from .client.client import connect # noqa: F401 from .client.client import login # noqa: F401 +from .client.client import login_as_guest #noqa: F401 from .client.client import register # noqa: F401 from .client.deploy import Orchestra # noqa: F401 from .client.domain_client import DomainClient # noqa: F401 diff --git a/packages/syft/src/syft/client/client.py b/packages/syft/src/syft/client/client.py index fe4a4238e0e..4e0fae32932 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -593,6 +593,17 @@ def me(self) -> Optional[Union[UserView, SyftError]]: return self.api.services.user.get_current_user() return None + def login_as_guest(self) -> Self: + _guest_client = self.guest() + + print( + f"Logged into <{self.name}: {self.metadata.node_side_type.capitalize()}-side " + f"{self.metadata.node_type.capitalize()}> as GUEST" + ) + + return _guest_client + + def login( self, email: str, password: str, cache: bool = True, register=False, **kwargs ) -> Self: @@ -833,12 +844,13 @@ def login( port: Optional[int] = None, email: Optional[str] = None, password: Optional[str] = None, - cache: bool = True, - verbose: bool = True, + cache: bool = True ) -> SyftClient: _client = connect(url=url, node=node, port=port) + if isinstance(_client, SyftError): return _client + connection = _client.connection login_credentials = None @@ -848,11 +860,6 @@ def login( password = getpass("Password: ") login_credentials = UserLoginCredentials(email=email, password=password) - if login_credentials is None: - return SyftError( - message="If you want to login as guest, use .login_as_guest() instead" - ) - if cache and login_credentials: _client_cache = SyftClientSessionCache.get_client( login_credentials.email,