-
Notifications
You must be signed in to change notification settings - Fork 54
feat: Add Zarr v2 metadata access and basic auth support for OIDC-protected assets #2112
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
Draft
cauriol
wants to merge
9
commits into
develop
Choose a base branch
from
auth_destinee
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+378
−13
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9474973
feat: authentification for desp cache
cauriol 4484ac1
refactor: remove zarr config parameter
jlahovnik f622258
feat: get auth headers
cauriol 5197cf4
feat: tests
cauriol cf927f7
feat: handle zarr in eodag + tests
cauriol 7e79434
fix: linter
cauriol f1b150b
feat: move EOProduct._get_storage_options from eodag-cube to eodag
cauriol 585f19d
fix: zarr
cauriol c2f8005
fix: precomit
cauriol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,16 @@ | |
| import geojson | ||
| import orjson | ||
| import requests | ||
| from boto3 import Session | ||
| from boto3.resources.base import ServiceResource | ||
| from pystac import Item | ||
| from requests import RequestException | ||
| from requests import PreparedRequest, RequestException | ||
| from requests.auth import AuthBase | ||
| from requests.structures import CaseInsensitiveDict | ||
| from shapely import geometry | ||
| from shapely.errors import ShapelyError | ||
|
|
||
| from eodag.plugins.authentication.aws_auth import AwsAuth | ||
| from eodag.types.queryables import CommonStacMetadata | ||
| from eodag.types.stac_metadata import create_stac_metadata_model | ||
|
|
||
|
|
@@ -73,7 +77,12 @@ | |
| _import_stac_item_from_known_provider, | ||
| _import_stac_item_from_unknown_provider, | ||
| ) | ||
| from eodag.utils.exceptions import DownloadError, MisconfiguredError, ValidationError | ||
| from eodag.utils.exceptions import ( | ||
| DatasetCreationError, | ||
| DownloadError, | ||
| MisconfiguredError, | ||
| ValidationError, | ||
| ) | ||
| from eodag.utils.repr import dict_to_html_table | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -622,6 +631,65 @@ def stream_download( | |
| **kwargs, | ||
| ) | ||
|
|
||
| def get_storage_options( | ||
| self, | ||
| asset_key: Optional[str] = None, | ||
| ) -> dict[str, Any]: | ||
| """ | ||
| Get fsspec storage_options keyword arguments | ||
| """ | ||
| auth = self.downloader_auth.authenticate() if self.downloader_auth else None | ||
| if self.downloader is None: | ||
| return {} | ||
|
|
||
| # default url and headers | ||
| try: | ||
| url = self.assets[asset_key]["href"] if asset_key else self.location | ||
| except KeyError as e: | ||
| raise DatasetCreationError(f"{asset_key} not found in {self} assets") from e | ||
| headers = {**USER_AGENT} | ||
|
|
||
| if isinstance(auth, ServiceResource) and isinstance( | ||
| self.downloader_auth, AwsAuth | ||
| ): | ||
| auth_kwargs: dict[str, Any] = dict() | ||
| # AwsAuth | ||
| if s3_endpoint := getattr(self.downloader_auth.config, "s3_endpoint", None): | ||
| auth_kwargs["client_kwargs"] = {"endpoint_url": s3_endpoint} | ||
| if creds := cast( | ||
| Session, self.downloader_auth.s3_session | ||
| ).get_credentials(): | ||
| auth_kwargs["key"] = creds.access_key | ||
| auth_kwargs["secret"] = creds.secret_key | ||
| if creds.token: | ||
| auth_kwargs["token"] = creds.token | ||
| if requester_pays := getattr( | ||
| self.downloader_auth.config, "requester_pays", False | ||
| ): | ||
| auth_kwargs["requester_pays"] = requester_pays | ||
| else: | ||
| auth_kwargs["anon"] = True | ||
| return {"path": url, **auth_kwargs} | ||
|
|
||
| if isinstance(auth, AuthBase): | ||
| # update url and headers with auth | ||
| req = PreparedRequest() | ||
| req.url = url | ||
| req.headers = CaseInsensitiveDict(headers) | ||
| if auth: | ||
| auth(req) | ||
| return {"path": req.url, "headers": dict(req.headers)} | ||
|
|
||
| return {"path": url} | ||
|
|
||
| def request_asset( | ||
| self, | ||
| url: str, | ||
| ) -> requests.Response: | ||
| """Perform a GET request to the given URL using product's authentication headers.""" | ||
| headers = self.get_storage_options().get("headers", {}) | ||
| return requests.get(url, headers=headers, stream=True) | ||
|
Comment on lines
+685
to
+691
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use the stream download method from EODAG download plugins instead of creating a new method. |
||
|
|
||
| def _init_progress_bar( | ||
| self, | ||
| progress_callback: Optional[ProgressCallback], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not creating a xarray here. The exception class is not accurate.