Skip to content

Commit 14285bd

Browse files
author
Tom Augspurger
authored
Feature/no double sign (#39)
* Avoid double-signing URLs * Bump versions, docs * Bump requirements
1 parent 343b171 commit 14285bd

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.4.7
2+
3+
## New Features
4+
5+
* `sign` will now avoid signing URLs that have already been signed.
6+
17
# 0.4.6
28

39
## New Features

planetary_computer/sas.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import warnings
77

88
from functools import singledispatch
9-
from urllib.parse import urlparse
9+
from urllib.parse import urlparse, parse_qs
1010
import requests
1111
from pydantic import BaseModel, Field
1212
from pystac import Asset, Item, ItemCollection
@@ -126,6 +126,11 @@ def sign_url(url: str) -> str:
126126
if not parsed_url.netloc.endswith(BLOB_STORAGE_DOMAIN):
127127
return url
128128

129+
parsed_qs = parse_qs(parsed_url.query)
130+
if set(parsed_qs) & {"st", "se", "sp"}:
131+
# looks like we've already signed it
132+
return url
133+
129134
account, container = parse_blob_url(parsed_url)
130135
token = get_token(account, container)
131136
return token.sign(url).href

planetary_computer/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Library version"""
22

3-
__version__ = "0.4.6"
3+
__version__ = "0.4.7"

requirements-dev.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
black==21.10b0
1+
black==22.6.0
22
flake8==4.0.1
3-
ipdb==0.13.7
4-
mypy==0.910
5-
types-requests==2.26.0
6-
setuptools==58.5.3
3+
ipdb==0.13.9
4+
mypy==0.961
5+
types-requests==2.28.1
6+
setuptools==63.1.0

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = planetary-computer
3-
version = 0.4.6
3+
version = 0.4.7
44
license_file = LICENSE
55
author = microsoft
66
author_email = planetarycomputer@microsoft.com

tests/test_signing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,8 @@ def test_is_fsspec_url(self) -> None:
283283

284284
asset = Asset("adlfs://my-container/my/path.ext")
285285
self.assertFalse(is_fsspec_asset(asset))
286+
287+
def test_no_double_sign_url(self) -> None:
288+
result = pc.sign(SENTINEL_THUMBNAIL)
289+
result2 = pc.sign(result)
290+
assert result == result2

0 commit comments

Comments
 (0)