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

Globus app #986

Merged
merged 6 commits into from
Jun 26, 2024
Merged

Globus app #986

merged 6 commits into from
Jun 26, 2024

Conversation

aaschaer
Copy link
Contributor

@aaschaer aaschaer commented May 30, 2024

Shortcut: https://app.shortcut.com/globus/story/30768/sdk-globusapp-constructs

Change Summary (all in experimental:

  • Adds abstract base class GlobusApp which defines add_scope_requirements, run_login_flow, and get_authorizer as an interface for getting tokens that meet scope requirements
  • Adds UserApp which implements GlobusApp and has a LoginFlowManager for running interactive login flows.
  • Adds ClientApp which implements GlobusApp
  • Adds a first pass GlobusAppConfig, which has its own story https://app.shortcut.com/globus/story/30772/sdk-globusappconfig. I'm not sure to what extent we'll want to expand this so I'm leaving that story as is for now. I mostly added it now because refresh_tokens significantly changes behavior of UserApp, and being able to configure a MemoryTokenStorage is useful for testing.
  • Adds a Scope.merge_scopes method for scope de-duplication. This isn't as comprehensive as what was originally specc'd (https://app.shortcut.com/globus/story/33823/scope-de-duplication) but avoids the issue of how to hash non-static Scopes

Notes:

  • evidently I only didn't hit typing issues with generic abstract base classes because I hadn't rebased as recently as I thought. I added a few type: ignore comments in places I feel should be correct but are still raising mypy errors, but if anyone knows a better way to handle that lmk
  • I chose the filename for the default JSONTokenStorage somewhat arbitrarily, happy to change it if desired

📚 Documentation preview 📚: https://globus-sdk-python--986.org.readthedocs.build/en/986/

@aaschaer aaschaer force-pushed the globus_app branch 2 times, most recently from 79e3777 to b383e12 Compare June 5, 2024 17:42
Comment on lines 51 to 53
return os.path.join(datadir, "globus", app_name, "tokens.json")
else:
return os.path.expanduser(f"~/.globus/{app_name}/tokens.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should namespace these 1 layer deeper to avoid collisions w/ other locally run globus products.
Even today, if a user creates a GlobusApp with the name cli or sharing they'll be colliding with existing names.

What about ~/.globus/globus-app/{app_name}/tokens.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I think I like ~/.globus/app/{app_name}/tokens.json slightly more since removing the extra globus makes it shorter

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy with that (and similar change for the windows variety)

*,
login_flow_manager: LoginFlowManager | None = None,
token_storage: TokenStorage | None = None,
refresh_tokens: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
refresh_tokens: bool = False,
request_refresh_tokens: bool = False,

I suggest this because refresh_tokens could be read as an imperative of "please refresh my tokens" if a user isn't familiar enough with Globus or OAuth.

src/globus_sdk/experimental/globus_app/globus_app.py Outdated Show resolved Hide resolved
src/globus_sdk/experimental/globus_app/globus_app.py Outdated Show resolved Hide resolved
src/globus_sdk/experimental/globus_app/globus_app.py Outdated Show resolved Hide resolved
src/globus_sdk/experimental/globus_app/globus_app.py Outdated Show resolved Hide resolved
Copy link
Contributor

@derek-globus derek-globus left a comment

Choose a reason for hiding this comment

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

2 minor comments about default location & type hints but overall looks very good!

self,
app_name: str,
*,
login_client: AuthLoginClient | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
login_client: AuthLoginClient | None = None,
login_client: ConfidentialAppAuthClient | None = None,

Is there a reason we wouldn't want to encode this runtime requirement in the type info?

client_id: UUIDLike | None = None,
client_secret: str | None = None,
scope_requirements: dict[str, list[Scope]] | None = None,
config: GlobusAppConfig | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

With config being immutable now, we should be able to set the default in the constructor.

Suggested change
config: GlobusAppConfig | None = None,
config: GlobusAppConfig = GlobusAppConfig()

tokens for long lived access.
"""

login_flow_manager: LoginFlowManager | type[LoginFlowManager] | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an elegant solution to my initial thread.

I'm very slightly hesitant about having the constructor interface be mandated like this but I can live with it. If a user is subclassing their own LoginFlowManager, they're 90% going to be pre-instantiating it notgiving it to us to instantiate it.

@aaschaer aaschaer merged commit 3748230 into main Jun 26, 2024
29 checks passed
@aaschaer aaschaer deleted the globus_app branch June 26, 2024 15:44
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.

3 participants