Skip to content

Git service: attach each service to an allauth provider #11995

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

Merged
merged 12 commits into from
Feb 14, 2025

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 13, 2025

  • With Migrate GitHub OAuth App to GitHub App #11942, there is the need to get an OAuth2 client from an account, so that method was moved outside the UserService class, and it just depends on the social account.
  • provider_id and provider name don't need to be an instance method, and can be extracted from the allauth provider attached to the service class.

This is on top of #11983

With #11942,
a GH app is used to interact with the GH API,
a GH app is not directly tied to a user, so this assumption is not valid anymore.

For most of the operations (except for syncing repos), we don't need to know who is the user
that is performing the action, we just need to know the project that is
being affected.
@stsewd stsewd requested a review from a team as a code owner February 13, 2025 18:38
@stsewd stsewd requested a review from humitos February 13, 2025 18:38
@stsewd stsewd requested a review from ericholscher February 13, 2025 18:46
@stsewd stsewd changed the title Git service: attach each service to a allauth provider Git service: attach each service to an allauth provider Feb 13, 2025
Base automatically changed from refactor-services to main February 13, 2025 21:36
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Looks great overall, just a couple questions.

token_config.update(
{
"refresh_token": token.token_secret,
"expires_in": token_expires,
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little surprised we're setting this internally -- is it so we can update it if needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, allauth doesn't provide an oauth2 client, so we use requests_oauthlib, and we need to glue the token from allauth other lib. Most of this code was just moved.

"""
Update token given data from OAuth response.

Expect the following response into the closure::
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what this is saying -- do you mean that is the expected value of the token arg?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, this is likely the response you get when the request for a new token is made.

log.info("Updated token.", token_id=token.pk)

return _updater
@cached_property
Copy link
Member

Choose a reason for hiding this comment

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

What is caching doing here? Seems a little scary to cache an object like this? Could probably use a comment at least explaining why we aren't just setting this in the __init__ as self.session?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same as we used to have (cache the client at the instance level), but we were manually caching the object.

def get_session(self):
if self.session is None:
self.create_session()
return self.session

@stsewd stsewd merged commit fe18ed2 into main Feb 14, 2025
8 checks passed
@stsewd stsewd deleted the abstract-allauth-from-services branch February 14, 2025 01:56
@stsewd stsewd mentioned this pull request Feb 17, 2025
Copy link

sentry-io bot commented Feb 24, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ConnectionError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /repos/lablup/backend.ai/statuses/e4f042ad97f0950d922f43147b4e036bacd93836 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7fa0789ef220>... readthedocs.builds.tasks.send_build_status View Issue

Did you find this useful? React with a 👍 or 👎

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

Successfully merging this pull request may close these issues.

2 participants