diff --git a/packages/hagrid/hagrid/orchestra.py b/packages/hagrid/hagrid/orchestra.py index 9a9de5fd43b..099bd5e1f91 100644 --- a/packages/hagrid/hagrid/orchestra.py +++ b/packages/hagrid/hagrid/orchestra.py @@ -163,7 +163,7 @@ def __init__( def client(self) -> Any: if self.port: sy = get_syft_client() - return sy.login(url=self.url, port=self.port, verbose=False) # type: ignore + return sy.login(url=self.url, port=self.port) # type: ignore elif self.deployment_type == DeploymentType.PYTHON: return self.python_node.get_guest_client(verbose=False) # type: ignore else: @@ -171,6 +171,16 @@ def client(self) -> Any: f"client not implemented for the deployment type:{self.deployment_type}" ) + def login_as_guest(self, **kwargs: Any) -> Optional[Any]: + client = self.client + + session = client.login_as_guest(**kwargs) + + if isinstance(session, SyftError): + return session + + return session + def login( self, email: Optional[str] = None, password: Optional[str] = None, **kwargs: Any ) -> Optional[Any]: @@ -182,6 +192,7 @@ def login( password = getpass.getpass("Password: ") session = client.login(email=email, password=password, **kwargs) + if isinstance(session, SyftError): return session diff --git a/packages/syft/src/syft/__init__.py b/packages/syft/src/syft/__init__.py index 001c6b81dd4..1f95ce2cfa3 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 53687d36381..38bc3e6d2ac 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -593,6 +593,16 @@ 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: @@ -805,6 +815,27 @@ def register( ) +@instrument +def login_as_guest( + url: Union[str, GridURL] = DEFAULT_PYGRID_ADDRESS, + node: Optional[AbstractNode] = None, + port: Optional[int] = None, + verbose: bool = True, +): + _client = connect(url=url, node=node, port=port) + + if isinstance(_client, SyftError): + return _client + + if verbose: + print( + f"Logged into <{_client.name}: {_client.metadata.node_side_type.capitalize()}-" + f"side {_client.metadata.node_type.capitalize()}> as GUEST" + ) + + return _client.guest() + + @instrument def login( url: Union[str, GridURL] = DEFAULT_PYGRID_ADDRESS, @@ -813,11 +844,12 @@ def login( email: Optional[str] = None, password: Optional[str] = None, cache: bool = True, - verbose: bool = True, ) -> SyftClient: _client = connect(url=url, node=node, port=port) + if isinstance(_client, SyftError): return _client + connection = _client.connection login_credentials = None @@ -827,14 +859,6 @@ def login( password = getpass("Password: ") login_credentials = UserLoginCredentials(email=email, password=password) - if login_credentials is None: - if verbose: - print( - f"Logged into <{_client.name}: {_client.metadata.node_side_type.capitalize()}-" - f"side {_client.metadata.node_type.capitalize()}> as GUEST" - ) - return _client.guest() - if cache and login_credentials: _client_cache = SyftClientSessionCache.get_client( login_credentials.email,