Skip to content

Commit

Permalink
Feature/sign inplace (#42)
Browse files Browse the repository at this point in the history
* Added signing inplace

* Added sign_inplace
  • Loading branch information
Tom Augspurger authored Jul 29, 2022
1 parent f7b7cb4 commit 5eec30c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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

0 comments on commit 5eec30c

Please sign in to comment.