Skip to content

Commit

Permalink
feat: login_as_guest added to sy and domain client
Browse files Browse the repository at this point in the history
  • Loading branch information
tcp committed Oct 11, 2023
1 parent 31c4ecb commit 663be62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/syft/src/syft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions packages/syft/src/syft/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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 <client>.login_as_guest() instead"
)

if cache and login_credentials:
_client_cache = SyftClientSessionCache.get_client(
login_credentials.email,
Expand Down

0 comments on commit 663be62

Please sign in to comment.