Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a new client with SyftClient.login #8159

Merged
merged 9 commits into from
Oct 19, 2023

Conversation

kiendang
Copy link
Contributor

@kiendang kiendang commented Oct 13, 2023

Description

Make SyftClient.login return a new SyftClient instance instead of mutating the current SyftClient instance.

Short changelog example

Before

import syft as sy
guest_client = sy.login(url="", port="")
guest_client.login(...)

# use `guest_client` as the logged in `SyftClient`
guest_client.upload_dataset(...)

After

import syft as sy
guest_client = sy.login_as_guest(url="http://localhost", port="8081")
client = guest_client.login(email="[email protected]", password="changethis")

# use `client` as the logged in `SyftClient` instead of `guest_client`
client.upload_dataset(...)

Before

import syft as sy
# Email and password can be empty and we can proceed to login as guest
guest_client = sy.login(url="http://localhost", port="8081")
guest_client.datasets

After

import syft as sy
# Email is a required field when calling login
client = sy.login(url="http://localhost", port="8081", email="[email protected]", password="changethis")
# To Login as Guest
guest_client = sy.login_as_guest(url="http://localhost", port="8081")

Long changelog example

Before

import syft as sy

node = sy.orchestra.launch(name="test-domain-1", port="auto")
guest_domain_client = node.client

client = guest_domain_client.login(email="[email protected]")

new_project = sy.Project(
    name="my project",
    description="project description",
    members=[client],
)

new_project.start()

project = client.get_project(name="my project")

After

import syft as sy

node = sy.orchestra.launch(name="test-domain-1", port="auto")
guest_client = node.client

guest_client.login(email="[email protected]")

new_project = sy.Project(
    name="my project",
    description="project description",
    members=[guest_client],
)

new_project.start()

project = guest_client.get_project(name="my project")

Affected Dependencies

List any dependencies that are required for this change.

How has this been tested?

  • Describe the tests that you ran to verify your changes.
  • Provide instructions so we can reproduce.
  • List any relevant details for your test configuration.

Checklist

kiendang and others added 2 commits October 18, 2023 15:37
Co-authored-by: Shubham Gupta <[email protected]>
Co-authored-by: Shubham Gupta <[email protected]>
kiendang and others added 2 commits October 18, 2023 15:54
- make email required argument for login
- replace login with login_as_guest
Copy link
Member

@shubham3121 shubham3121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @kiendang !!

@shubham3121 shubham3121 marked this pull request as ready for review October 18, 2023 14:24
@shubham3121 shubham3121 requested a review from tcp October 18, 2023 14:25
email=login_credentials.email,
password=login_credentials.password,
cache=cache,
)
if not _client.authed:
Copy link
Collaborator

@tcp tcp Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is a failed login attempt handled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would return a SyftError

_client = ...
if isinstance(_client, SyftError): return _client

return _client

in both cases we return _client so that check is not needed here

Copy link
Collaborator

@tcp tcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped a question about handling failed login attempts. Overall, nice work!

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@madhavajay
Copy link
Collaborator

@kiendang Can we get a changelog example for the Product Team. For example:

# old code example
# new code example

@kiendang
Copy link
Contributor Author

@madhavajay where should the changelog example be put in?

@kiendang
Copy link
Contributor Author

@madhavajay I put the changelog examples in the description of the PR. 1 short concise example to highlight the change and 1 longer fully runnable one.

@shubham3121 shubham3121 requested a review from tcp October 19, 2023 07:56
@kiendang kiendang merged commit 1bae336 into OpenMined:dev Oct 19, 2023
27 checks passed
@kiendang kiendang deleted the client-login-new branch October 19, 2023 11:50
@madhavajay
Copy link
Collaborator

@kiendang this is really great work! Thank you for your diligence in addressing all the tests as well. 👏 We are still figuring out how to hand off these kinds of API changes but I think it helps to have some code examples for @IrinaMBejan Pylot team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants