-
Notifications
You must be signed in to change notification settings - Fork 76
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
Serve repodata.json with redirect #506
Open
jonashaag
wants to merge
3
commits into
mamba-org:main
Choose a base branch
from
jonashaag:repodata-redirect
base: main
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.
Open
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
from contextlib import contextmanager | ||
from os import PathLike | ||
from threading import Lock | ||
from typing import IO, BinaryIO, List, NoReturn, Tuple, Union | ||
from typing import IO, BinaryIO, List, NoReturn, Optional, Tuple, Union | ||
|
||
import fsspec | ||
from tenacity import retry, retry_if_exception_type, stop_after_attempt | ||
|
@@ -73,7 +73,7 @@ def list_files(self, channel: str) -> List[str]: | |
pass | ||
|
||
@abc.abstractmethod | ||
def url(self, channel: str, src: str, expires: int = 0) -> str: | ||
def url(self, channel: str, src: str, expires: int = 0, content_type=None) -> str: | ||
pass | ||
|
||
@abc.abstractmethod | ||
|
@@ -199,7 +199,11 @@ def list_files(self, channel: str): | |
channel_dir = os.path.join(self.channels_dir, channel) | ||
return [os.path.relpath(f, channel_dir) for f in self.fs.find(channel_dir)] | ||
|
||
def url(self, channel: str, src: str, expires=0): | ||
def url( | ||
self, channel: str, src: str, expires=0, content_type: Optional[str] = None | ||
): | ||
# Note: content_type is ignored because it's not needed | ||
|
||
if self.redirect_enabled: | ||
# generate url + secret if necessary | ||
if self.redirect_secret: | ||
|
@@ -376,7 +380,11 @@ def remove_prefix(text, prefix): | |
with self._get_fs() as fs: | ||
return [remove_prefix(f, channel_bucket) for f in fs.find(channel_bucket)] | ||
|
||
def url(self, channel: str, src: str, expires=3600): | ||
def url( | ||
self, channel: str, src: str, expires=3600, content_type: Optional[str] = None | ||
): | ||
if content_type is not None: | ||
raise NotImplementedError("'content_type' is not supported for S3") | ||
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. TODO: Check what to do with S3. I am not sure if S3 will happily accept non-signed headers or will error out (in the latter case we can't use redirects for |
||
# expires is in seconds, so the default is 60 minutes! | ||
with self._get_fs() as fs: | ||
return fs.url(path.join(self._bucket_map(channel), src), expires) | ||
|
@@ -517,9 +525,12 @@ def remove_prefix(text, prefix): | |
remove_prefix(f, channel_container) for f in fs.find(channel_container) | ||
] | ||
|
||
def url(self, channel: str, src: str, expires=3600): | ||
def url( | ||
self, channel: str, src: str, expires=3600, content_type: Optional[str] = None | ||
): | ||
# expires is in seconds, so the default is 60 minutes! | ||
with self._get_fs() as fs: | ||
# Note: content_type is ignored because it's not needed | ||
return fs.url(path.join(self._container_map(channel), src), expires) | ||
|
||
def get_filemetadata(self, channel: str, src: str): | ||
|
@@ -572,8 +583,6 @@ def __init__(self, config): | |
|
||
@property | ||
def support_redirect(self): | ||
# `gcsfs` currently doesnt support signing yet. Once this is implemented we | ||
# can enable this again. | ||
return True | ||
|
||
@contextlib.contextmanager | ||
|
@@ -668,15 +677,17 @@ def remove_prefix(text, prefix): | |
remove_prefix(f, channel_container) for f in fs.find(channel_container) | ||
] | ||
|
||
def url(self, channel: str, src: str, expires=3600): | ||
def url(self, channel: str, src: str, expires=3600, content_type=None): | ||
# expires is in seconds, so the default is 60 minutes! | ||
with self._get_fs() as fs: | ||
expiration_timestamp = ( | ||
int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) | ||
+ expires | ||
) | ||
redirect_url = fs.sign( | ||
path.join(self._bucket_map(channel), src), expiration_timestamp | ||
path.join(self._bucket_map(channel), src), | ||
expiration_timestamp, | ||
content_type=content_type, | ||
) | ||
return redirect_url | ||
|
||
|
This file contains 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.
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.
did you confirm that this works? Since it redirects to a path with
.gz
attached and I am not sure mamba / conda will handle that correctly.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 probably right, will have to do more testing. I should have done more testing because I've also found two other issues. One is that Conda sets
Content-Type: json
which doesn't work with the GCS signature (I assume you need to sign all the request headers as well, not just the URL?). Plus, if a file is not found, the client will get a 403 from GCS although it would be more helpful to receive a 404.