-
Notifications
You must be signed in to change notification settings - Fork 59
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
14
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.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9fd9a6b
feat: authentification for desp cache
cauriol 640e646
refactor: remove zarr config parameter
jlahovnik a8ecb50
feat: get auth headers
cauriol 29d551e
feat: tests
cauriol ae75a96
feat: handle zarr in eodag + tests
cauriol 6210b1b
fix: linter
cauriol 58c8d23
feat: move EOProduct._get_storage_options from eodag-cube to eodag
cauriol a772c50
fix: zarr
cauriol 18e4d25
fix: precomit
cauriol a5c677f
fix: exception class
cauriol 5415355
fix: compute state OIDCAuthorizationCodeFlowAuth
cauriol 7707d99
feat: add desp_cache provider
cauriol 80f8a66
fix: tests with desp_cache provider
cauriol 4cca34b
fix: syntax error
jlahovnik 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 |
|---|---|---|
|
|
@@ -37,12 +37,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 | ||
|
|
||
|
|
@@ -83,7 +87,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 ( | ||
| AddressNotFound, | ||
| DownloadError, | ||
| MisconfiguredError, | ||
| ValidationError, | ||
| ) | ||
| from eodag.utils.repr import dict_to_html_table | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -660,6 +669,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 AddressNotFound(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
+723
to
+729
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.
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. method to remove |
||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| desp_cache: | ||
| name: desp_cache | ||
| priority: 0 | ||
| roles: | ||
| - host | ||
| description: Destination Earth Digital Twin for Climate Change Adaptation through Earth Observation (DESP) - Cache | ||
| url: https://data.destination-earth.eu | ||
| search: | ||
| type: StacSearch | ||
| api_endpoint: https://hda.data.destination-earth.eu/stac/v2/search | ||
| pagination: | ||
| max_items_per_page: 1000 | ||
| next_page_token_key: token | ||
| sort: | ||
| sort_by_tpl: '{{"sortby": [ {{"field": "{sort_param}", "direction": "{sort_order}" }} ] }}' | ||
| sort_order_mapping: | ||
| ascending: asc | ||
| descending: desc | ||
| sort_param_mapping: | ||
| id: id | ||
| start_datetime: properties.datetime | ||
| end_datetime: properties.end_datetime | ||
| download: | ||
| type: HTTPDownload | ||
| ssl_verify: true | ||
| no_auth_download: True | ||
| auth_error_code: 401 | ||
| auth: | ||
| type: OIDCAuthorizationCodeFlowAuth | ||
| oidc_config_url: https://auth.destine.eu/realms/desp/.well-known/openid-configuration | ||
| redirect_uri: https://cacheb.dcms.destine.eu/ | ||
| client_id: edh-public | ||
| user_consent_needed: false | ||
| token_exchange_post_data_method: data | ||
| login_form_xpath: //form[@id='kc-form-login'] | ||
| authentication_uri_source: login-form | ||
| token_provision: basic | ||
| products: | ||
| GENERIC_COLLECTION: | ||
| _collection: "{collection}" | ||
| DT_CLIMATE_ADAPTATION_IFS_NEMO: | ||
| _collection: EO.ECMWF.DAT.DT_CLIMATE_ADAPTATION_IFS-NEMO | ||
| DT_CLIMATE_ADAPTATION_ICON: | ||
| _collection: EO.ECMWF.DAT.DT_CLIMATE_ADAPTATION_ICON |
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.
get_storage_optionsimplementation should be done in a separate PRThere 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.
has been extracted to #2276