Skip to content

Feature/sign inplace #42

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

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* `sign` now supports signing URLs that have already been signed.
* `sign` now supports signing raw JSON objects, in addition to `pystac` objects.
* `sign` now supports signing `Collection` objects.
* Added a `sign_inplace` method for signing by directly mutating objects, rather than copying.

# 0.4.6

Expand Down Expand Up @@ -69,4 +70,4 @@
[gh-25]: https://github.com/microsoft/planetary-computer-sdk-for-python/issues/25
[gh-30]: https://github.com/microsoft/planetary-computer-sdk-for-python/pull/30
[xarray-assets]: https://github.com/stac-extensions/xarray-assets
[kerchunk]: https://fsspec.github.io/kerchunk/
[kerchunk]: https://fsspec.github.io/kerchunk/
1 change: 1 addition & 0 deletions planetary_computer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from planetary_computer.sas import (
sign,
sign_inplace,
sign_url,
sign_item,
sign_assets,
Expand Down
9 changes: 9 additions & 0 deletions planetary_computer/sas.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def sign(obj: Any, copy: bool = True) -> Any:
)


def sign_inplace(obj: Any) -> Any:
"""
Sign the object in place.

See :func:`planetary_computer.sign` for more.
"""
return sign(obj, copy=False)


@sign.register(str)
def sign_string(url: str, copy: bool = True) -> str:
"""Sign a URL or VRT-like string containing URLs with a Shared Access (SAS) Token
Expand Down
6 changes: 6 additions & 0 deletions tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ def test_sign_collection_dict(self) -> None:
result["assets"]["zarr-abfs"]["xarray:open_kwargs"]["storage_options"],
)

def test_sign_inplace(self) -> None:
item = get_sample_item()
result = pc.sign_inplace(item)
self.assertIs(result, item)
self.assertSigned(result.assets["image"].href)


class TestUtils(unittest.TestCase):
def test_parse_adlfs_url(self) -> None:
Expand Down