Skip to content

Commit 5eec30c

Browse files
author
Tom Augspurger
authored
Feature/sign inplace (#42)
* Added signing inplace * Added sign_inplace
1 parent f7b7cb4 commit 5eec30c

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* `sign` now supports signing URLs that have already been signed.
66
* `sign` now supports signing raw JSON objects, in addition to `pystac` objects.
77
* `sign` now supports signing `Collection` objects.
8+
* Added a `sign_inplace` method for signing by directly mutating objects, rather than copying.
89

910
# 0.4.6
1011

@@ -69,4 +70,4 @@
6970
[gh-25]: https://github.com/microsoft/planetary-computer-sdk-for-python/issues/25
7071
[gh-30]: https://github.com/microsoft/planetary-computer-sdk-for-python/pull/30
7172
[xarray-assets]: https://github.com/stac-extensions/xarray-assets
72-
[kerchunk]: https://fsspec.github.io/kerchunk/
73+
[kerchunk]: https://fsspec.github.io/kerchunk/

planetary_computer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from planetary_computer.sas import (
55
sign,
6+
sign_inplace,
67
sign_url,
78
sign_item,
89
sign_assets,

planetary_computer/sas.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def sign(obj: Any, copy: bool = True) -> Any:
8686
)
8787

8888

89+
def sign_inplace(obj: Any) -> Any:
90+
"""
91+
Sign the object in place.
92+
93+
See :func:`planetary_computer.sign` for more.
94+
"""
95+
return sign(obj, copy=False)
96+
97+
8998
@sign.register(str)
9099
def sign_string(url: str, copy: bool = True) -> str:
91100
"""Sign a URL or VRT-like string containing URLs with a Shared Access (SAS) Token

tests/test_signing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ def test_sign_collection_dict(self) -> None:
316316
result["assets"]["zarr-abfs"]["xarray:open_kwargs"]["storage_options"],
317317
)
318318

319+
def test_sign_inplace(self) -> None:
320+
item = get_sample_item()
321+
result = pc.sign_inplace(item)
322+
self.assertIs(result, item)
323+
self.assertSigned(result.assets["image"].href)
324+
319325

320326
class TestUtils(unittest.TestCase):
321327
def test_parse_adlfs_url(self) -> None:

0 commit comments

Comments
 (0)