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

Refactor experimental SQLiteTokenStorage ("v2") to better accord with its parent class #1004

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Jul 12, 2024

These changes are all related, although not necessarily in a perfectly obvious way.

The story runs thusly:

  • First, we agreed that we wanted to move the "ensure dir" dynamics to the parent class, FileTokenStorage.
  • Second, we discovered that this would conflict with use of :memory: databases. (Probably solvable, but a red flag about being a "FileTokenStorage" but not having a file.)
  • Third, we considered whether or not such usages could simply use MemoryTokenStorage. But there are concerns around use of the 'config_storage' area making SQLiteTokenStorage the "only production storage mechanism".
  • Fourth, we agreed upon a resolution trajectory in which, at least until we see evidence to the contrary, we will remove the 'config_storage' table and make these classes more uniform.
  • Fifth, this PR.

One notable addition to the above:

  • This changeset sets the "schema version" to 2 for the database. It's not yet certain, IMO, that this field will be useful, but we could use it to trivially check if config_storage is expected to be present and to manage data migrations.

I have already started to think about what a data migration for globus-cli would look like, and it's definitely nontrivial.
We will need to develop some kind of compatibility layer which migrates data and presents a uniform interface to its callers, but doing so in a way which doesn't break the upgrade-downgrade path will require careful thought.
I'm not certain that this will turn out to be worth the pain, but we could, at the very least, provide a distinct (non-TokenStorage) interface for accessing the config_storage table found in the sqlite DB. That is: the remodeling of classes done here is robust to the possibility of our deciding against a migration of the config_storage table to some other source of truth.


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

@sirosen

This comment was marked as resolved.

@sirosen
Copy link
Member Author

sirosen commented Jul 15, 2024

The above guess is not borne out by the diff. I'm wondering if this has been a standing issue which is somehow now exposed by the slight changes to the testsuite.

Support for the 'config_storage' table, and associated methods, has
been removed after deliberation about the modeling of tokenstorage
adapters and their interchangeability.

The issue with config storage is that none of the other adapters
provide and support this interface. Therefore, what appears to be
generic and pluggable is, in fact, a locked-in decision for certain
applications (e.g., `globus-cli`) and will not allow us to provide
swappable token storage for those applications.

Such extension points can easily be patched into place for migration
purposes in the few applications which need them, conditional on the
presence/absence of the `config_storage` table. Developing migration
workflows is left as a future problem.
Use of a ':memory:' database indicates an opportunity to use the
memory tokenstorage. We now reject ':memory:' with an appropriate and
detailed usage error.

At the same time, various uses of 'dbname' rather than 'filename' have
been conformed to 'filename'. This further reinforces that the
tokenstorage object is meant to refer to some known file, not a pure
memory DB.

Tests which relied on the memory database have been updated to use a
tempfile. One test which needed significant changes was completely
refactored at this time, to provide better and clearer testing.
Rather than this being a specialized characteristic of the
JSONTokenStorage, this is now part of the base class functionality. As
a result, both the JSON and SQLiteTokenStorage inherit this behavior
(with a small change to the SQLiteTokenStorage initializer to call
super() at the right time).

This allows both of these storage adapters to inherit this beneficial
behavior.
@sirosen sirosen force-pushed the experimental-tokenstorage-refactor branch from 8e3c19b to 81bdd27 Compare July 16, 2024 17:13
@sirosen
Copy link
Member Author

sirosen commented Jul 16, 2024

I've rebased onto #1007, and dropped the added commit here which explored that solution for the rmtree issue we had in CI.

@sirosen sirosen merged commit 34f73c5 into globus:main Jul 17, 2024
14 of 15 checks passed
@sirosen sirosen deleted the experimental-tokenstorage-refactor branch July 17, 2024 18:43
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