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

[WIP] Rework of Storages Registry based approach #17881

Draft
wants to merge 34 commits into
base: dev
Choose a base branch
from

Conversation

mereghost
Copy link
Contributor

@mereghost mereghost commented Feb 10, 2025

⚠️ This is a labor of love, not related to any Work Package.

This is a large chunk of code. No, it can't be done piecemeal.

It can be reviewed piecemeal tho. :P

What is this?

For a long time we experimented and introduced ideas to the Storages codebase that were left half-baked, half implemented or outright abandoned.

This work tries to extrapolate these ideas and move forward with this type of implementation.

Why?

Storages code will forever get more complexity as we support more and more features and should, by all means, be invisible to the outside. Outside code should just call a couple of services and work with their results using the already familiar ServiceResult abstraction.

Module internal code should need to keep this level of promises. Besides we came up with a bunch of other abstractions (input data, result objects) that we never ended up implementing for all the cases.

What has changed?

For storages client code? Hopefully nothing. Storages module has been radically transformed tho.

@mereghost mereghost self-assigned this Feb 10, 2025
- Working to makes test pass
- Slow removal of already migrated code
@mereghost mereghost force-pushed the refactor/redesign-storage-interactions branch from d6231a3 to 200fd3a Compare February 10, 2025 15:31
Copy link
Member

@Kharonus Kharonus left a comment

Choose a reason for hiding this comment

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

Some first comments

class StrategyContract < Dry::Validation::Contract
params do
# The included list need to be made dynamic
required(:key).filled(:symbol, included_in?: %i[noop basic_auth oauth_client_credentials oauth_user_token])
Copy link
Member

Choose a reason for hiding this comment

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

🟡 how so "dynamic"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Goood question. Ideally we could have this somewhere and just reference it. XD


# TODO: Add tests for this - 2025-01-15 @mereghost
def self.authorization_state(storage:, user:)
auth_strategy = Input::Strategy.build(user:, key: :oauth_user_token)
Copy link
Member

Choose a reason for hiding this comment

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

this is still a result at this point. this is missing error handling, right?

Or, you could now probably build a real monadic chain, right? As I see two results - the strategy.build and the auth_check.call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the idea, the monadic chain.

The code that's asking for this will be touched soon, so I'll have to take a better look at it.

Copy link
Member

Choose a reason for hiding this comment

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

🟢 the rework of the strategies looks quite nice

include Dry::Monads::Result(Results::Error)

def self.call(storage:, auth_strategy:, input_data:)
new(storage).call(auth_strategy: auth_strategy, input_data: input_data)
Copy link
Member

Choose a reason for hiding this comment

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

🟡 shorthand for parameters in .call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦🏼 Somehow I missed this.

Copy link
Member

Choose a reason for hiding this comment

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

🟢 nice, so the base class replaces the util class

Copy link
Member

Choose a reason for hiding this comment

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

❓ Why did you dissolve the idea of the internal namespace? Now I'd stumble across the fact, that the propfind query has a fully different interface then its brethren. It even overrides self.call and stuff like this.

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 wasn't a conscious choice... it kinda happened. I played with the idea of making the interface the same but never fully committed to it.

They aren't exposed by the registry, so the interface is a lesser issue to me. I might still reintroduce the namespace.

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

Successfully merging this pull request may close these issues.

2 participants