-
Notifications
You must be signed in to change notification settings - Fork 43
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
Copy url params in format_parsed_parts #101
Copy url params in format_parsed_parts #101
Conversation
53eac9a
to
ded54d6
Compare
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.
Hi @rahuliyer95
Thank you for opening the PR! ❤️
I think we'll have to check how this fits together with: #88 and #92
As it stands now, I believe the test assumption is wrong, because query parameters have to be provided on a per "file" basis and should not carry over.
I understand though, that this might be a common use case, so maybe we could provide some other way to globally set query parameters...
Cheers,
Andreas 😃
path1 = self.path / f"test_joinpath_dir1?{query}" | ||
assert path1._url.query == query | ||
path2 = path1 / "file1.txt" | ||
assert path2._url.query == query |
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.
This assumption is probably incorrect. See:
>>> import urllib.parse
>>> urllib.parse.urljoin("http://www.example.com/dir/?p1=v1&p2=v2", "file.txt")
'http://www.example.com/dir/file.txt'
Thanks for getting back on this, we are using from upath import UPath
dir1 = UPath("scheme://bucket/dir1?namespace=ns1")
dir2 = UPath("scheme://bucket/dir2?namespace=ns2") now |
Thank you for the additional context! Is there a reason why you chose to implement it via query parameters? Will there ever be multiple namespaces for the same As I understand right now: you were basically looking for a way to encode which credentials to use into the string representation of the url. |
For our use-case this path parameter can be provided by the user and the API contract we set is that the user only needs to provide the right path with a
There could be multiple namespace for the same
Yes, without having to expose actual credentials in the URL itself. |
FYI, I had a very similar situation. We ultimately ended up requiring the user to specify the credentials via an environment variable, because there were too many places the URI could be logged, which would create a security vulnerability. |
To clarify I am not proposing to share the actual credentials in the URL params, just an id or a reference to where the credentials are present; e.g: name of the environment variable to read for the credentials. |
Managed to solve this using class MyS3PathWithNamespace(S3Path):
@classmethod
def _from_parts(
cls,
args: List[Union[str, os.PathLike]],
url: Optional[SplitResult] = None,
**kwargs: Any,
):
if url:
query = parse_qs(url.query)
if namespace := next(iter(query.get("namespace", [])), ""):
kwargs["namespace"] = namespace
return super()._from_parts(args, url=url, **kwargs) |
Similar to #95 I noticed that when creating sub-paths using
/
or__truediv__
we are not copying theurl
params.Example,
This PR attempts to resolve this by copying the query parameters when creating sub-paths using
/
.Results with the fix,