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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenStorage (v2) #980

Merged
merged 4 commits into from
May 17, 2024
Merged

TokenStorage (v2) #980

merged 4 commits into from
May 17, 2024

Conversation

aaschaer
Copy link
Contributor

@aaschaer aaschaer commented Apr 25, 2024

Shortcut: https://app.shortcut.com/globus/story/33154/sdk-storageadapterv2

Change Summary (all in experimental):

  • Adds TokenStorage which expands upon StorageAdapter by adding namespace support and requires implementing classes to support remove_tokens_for_resource_server. It also allows passing token data as a dict in addition to a OAuthTokenResponse and removes on_refresh as that was only ever an alias for store
  • Adds TokenData which is a data class for tokens and metadata, notably including identity_id which is needed by ValidatingTokenStorage
  • Adds FileTokenStorage which is nearly much identical to FileAdapter beyond implementing StorageAdapterV2 instead of StorageAdapterV2
  • Adds MemoryTokenStorage which remains fairly simple.
  • Adds JSONTokenStorage which now stores data under namespaced keys and has logic for migrating storage from a SimpleJSONFileAdapter
  • Adds SQLiteTokenStorage which is very similar SQLiteAdapter beyond implementing StorageAdapterV2. Both classes should even be able to use the same storage without causing issues
  • Changes ValidatingStorageAdapater to ValidatingTokenStorage which now implements TokenStorage instead of StorageAdapter
  • Removes IdentifiedOAuthTokenResponse as its functionality is now covered by TokenData

Notes:

  • the default namespace is "DEFAULT" instead of None as originally spec'd this was to not require data migration for SQLiteTokenStorage to use storage previously used by SQLiteAdapter
  • namespace is defined at class initialization rather than passed to each function as originally spec'd. This was to minimize needed changes for SQLiteAdapter and better conform with GlobusApp which will also have one namespace per instance.
  • Its not clear to me that adding namespace support to MemoryTokenStorage changed anything since initializing another MemoryAdapter already partitioned the data in memory. Maybe that value should just be ignored?

馃摎 Documentation preview 馃摎: https://globus-sdk-python--980.org.readthedocs.build/en/980/

src/globus_sdk/experimental/tokenstorage_v2/base.py Outdated Show resolved Hide resolved
"""

@abc.abstractmethod
def remove_tokens_for_resource_server(self, resource_server: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this name is coming from the current sqliteadapater but I wonder, could we actually just change this? It's way more verbose than the other method names.

  • "store" doesn't mention tokens at all
  • "get" mentions tokens but not that it's for a resource server
  • "remove" mentions tokens and that it's for a resource server

I guess store isn't bounded to a particular resource server and get/remove are so maybe remove_token_data(resource_server: str) to mirror get_token_data(resource_server: str)?

Copy link
Member

Choose a reason for hiding this comment

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

I would like us to reevaluate all of the names in play, for the record. That goes for the class name as well, per one of your other comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with

store_response
store_token_data_by_resource_server
get_token_data_by_resource_server
get_token_data
remove_token_data

Open to suggestions for changes, but it should at least be more uniform now

src/globus_sdk/experimental/tokenstorage_v2/base.py Outdated Show resolved Hide resolved
Comment on lines 66 to 67
"format_version": self.format_version,
"globus-sdk.version": __version__,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the difference in delimiter here? _ vs -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is the only comment that didn't get addressed in my last commit/rebase.

Essentially I just wanted to keep the value used by SimpleJSONStorageAdapter so there was one less thing for users to worry about when migrating.

As for why it was like this originally 馃し

@aaschaer aaschaer changed the title StorageAdapterV2 TokenStorage (v2) May 6, 2024
@aaschaer aaschaer requested a review from derek-globus May 7, 2024 16:30
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.

Haven't finished reviewing; posting comments now though for conversation.

src/globus_sdk/experimental/tokenstorage_v2/__init__.py Outdated Show resolved Hide resolved
src/globus_sdk/experimental/tokenstorage_v2/base.py Outdated Show resolved Hide resolved
src/globus_sdk/experimental/tokenstorage_v2/base.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.

I like the place this ended up.

Thanks again for iterating on it to refine it to this point!

@aaschaer aaschaer merged commit 5d05ea9 into main May 17, 2024
29 checks passed
@aaschaer aaschaer deleted the storage_adapter_v2 branch May 17, 2024 18:29
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.

None yet

3 participants