Skip to content

Feature/no double sign #39

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 3 commits into from
Jul 13, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.4.7

## New Features

* `sign` will now avoid signing URLs that have already been signed.

# 0.4.6

## New Features
Expand Down
7 changes: 6 additions & 1 deletion planetary_computer/sas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import warnings

from functools import singledispatch
from urllib.parse import urlparse
from urllib.parse import urlparse, parse_qs
import requests
from pydantic import BaseModel, Field
from pystac import Asset, Item, ItemCollection
Expand Down Expand Up @@ -126,6 +126,11 @@ def sign_url(url: str) -> str:
if not parsed_url.netloc.endswith(BLOB_STORAGE_DOMAIN):
return url

parsed_qs = parse_qs(parsed_url.query)
if set(parsed_qs) & {"st", "se", "sp"}:
# looks like we've already signed it
return url

account, container = parse_blob_url(parsed_url)
token = get_token(account, container)
return token.sign(url).href
Expand Down
2 changes: 1 addition & 1 deletion planetary_computer/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Library version"""

__version__ = "0.4.6"
__version__ = "0.4.7"
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
black==21.10b0
black==22.6.0
flake8==4.0.1
ipdb==0.13.7
mypy==0.910
types-requests==2.26.0
setuptools==58.5.3
ipdb==0.13.9
mypy==0.961
types-requests==2.28.1
setuptools==63.1.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = planetary-computer
version = 0.4.6
version = 0.4.7
license_file = LICENSE
author = microsoft
author_email = planetarycomputer@microsoft.com
Expand Down
5 changes: 5 additions & 0 deletions tests/test_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,8 @@ def test_is_fsspec_url(self) -> None:

asset = Asset("adlfs://my-container/my/path.ext")
self.assertFalse(is_fsspec_asset(asset))

def test_no_double_sign_url(self) -> None:
result = pc.sign(SENTINEL_THUMBNAIL)
result2 = pc.sign(result)
assert result == result2