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

Loading URL handlers from configuration #222

Merged
merged 2 commits into from
Jan 24, 2023
Merged

Loading URL handlers from configuration #222

merged 2 commits into from
Jan 24, 2023

Conversation

mih
Copy link
Member

@mih mih commented Jan 23, 2023

Here is an example:

[datalad "url-handler.(^|.*::)s3://mybucket/"]
    class = datalad_next.url_operations.fsspec.FsspecUrlOperations
    kwargs = {\"fs_kwargs\": {\"s3\": {\"anon\": false}}}

This defines a dedicated handler for accessing the AWS S3 bucket
'mybucket', and turns off anonymous access for this bucket specifically.

A regex-match expression is directly included in the config subsection
name (following the pattern of the standard Git url.<base>.insteadOf
configuration pattern).

The only mandatory configuration property is class. It points to an
importable class implementing the UrlOperations API.

If necessary, arbitrary keyword-arguments for the class constructur
can be specified, JSON-encoded, in a kwargs configuration item.

On instantiating the AnyUrlOperations handler, the configuration is
parse using the ConfigManager given to the handler, and configuration
based handler specifications overwrite and extend any handlers declare
in the built-in handler registry.

All active handlers are logged at level 8. Invalid handler
configuration is ignore and reported at 'debug' log level.

Closes #217

Note that above example does not actually work in the context of this branch, because FSSPEC support currently is a development draft #215
However, the changes in this PR are also part of that PR to verify that they work in the way presented here. I have factored them out into a separate PR, because it is unknown when #215 would be merged.

mih added 2 commits January 23, 2023 12:56
This prepares for future handlers that can be flexibly adapted for
particular scenarios based on specific arguments, but use the
same general implementation.
Here is an example:

```cfg
[datalad "url-handler.(^|.*::)s3://mybucket/"]
    class = datalad_next.url_operations.fsspec.FsspecUrlOperations
    kwargs = {\"fs_kwargs\": {\"s3\": {\"anon\": false}}}
```

This defines a dedicated handler for accessing the AWS S3 bucket
'mybucket', and turns off anonymous access for this bucket specifically.

A regex-match expression is directly included in the config subsection
name (following the pattern of the standard Git `url.<base>.insteadOf`
configuration pattern).

The only mandatory configuration property is `class`. It points to an
importable class implementing the `UrlOperations` API.

If necessary, arbitrary keyword-arguments for the class constructur
can be specified, JSON-encoded, in a `kwargs` configuration item.

On instantiating the `AnyUrlOperations` handler, the configuration is
parse using the `ConfigManager` given to the handler, and configuration
based handler specifications overwrite and extend any handlers declare
in the built-in handler registry.

All active handlers are logged at level 8. Invalid handler
configuration is ignore and reported at 'debug' log level.

Closes datalad#217
@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

Base: 89.78% // Head: 89.51% // Decreases project coverage by -0.27% ⚠️

Coverage data is based on head (81fa193) compared to base (cf24cdd).
Patch coverage: 51.11% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #222      +/-   ##
==========================================
- Coverage   89.78%   89.51%   -0.27%     
==========================================
  Files          72       72              
  Lines        6804     6841      +37     
==========================================
+ Hits         6109     6124      +15     
- Misses        695      717      +22     
Impacted Files Coverage Δ
datalad_next/url_operations/any.py 72.72% <48.83%> (-23.50%) ⬇️
datalad_next/url_operations/tests/test_any.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mih mih merged commit 814425e into datalad:main Jan 24, 2023
@mih mih deleted the urlcfg branch January 24, 2023 05:27
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.

Allow for URL handler definition in config
1 participant