Skip to content

Commit

Permalink
Merge pull request #511 from sentinel-hub/develop
Browse files Browse the repository at this point in the history
Release 3.10.0
  • Loading branch information
zigaLuksic authored Dec 8, 2023
2 parents 34193fd + 6616e79 commit 500cf5c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [Version 3.10.0] - 2023-12-07

- Adjust session caching to mirror changes to the core services. Older version might no longer correctly cache sessions.

## [Version 3.9.5] - 2023-12-07

- The `SentinelHubDownloadClient` class now has a `default_retry_time` parameter, which allows control over the waiting time when a request gets a 429 TOO_MANY_REQUESTS response without a specific retry time in the headers. The default value for this behavior has been changed from 0s to 30s to avoid edge-cases where SH services were bombarded with requests.
Expand Down
2 changes: 1 addition & 1 deletion sentinelhub/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of the sentinelhub package."""

__version__ = "3.9.5"
__version__ = "3.10.0"
2 changes: 1 addition & 1 deletion sentinelhub/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _SHConfig:
sh_client_secret: str = ""
sh_base_url: str = "https://services.sentinel-hub.com"
sh_auth_base_url: str | None = None
sh_token_url: str = "https://services.sentinel-hub.com/oauth/token"
sh_token_url: str = "https://services.sentinel-hub.com/auth/realms/main/protocol/openid-connect/token"
geopedia_wms_url: str = "https://service.geopedia.world"
geopedia_rest_url: str = "https://www.geopedia.world/rest"
aws_access_key_id: str = ""
Expand Down
2 changes: 1 addition & 1 deletion sentinelhub/download/sentinelhub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_cache_key(config_or_session: SentinelHubSession | SHConfig) -> tuple[st
base_url = config_or_session.config.sh_base_url

# If session was generated from token then config_or_session.config.sh_client_id could have wrong client id.
sh_client_id = config_or_session.info().get("aud", "")
sh_client_id = config_or_session.info().get("azp", "")
if not sh_client_id:
warnings.warn(
"Failed to read client ID from OAuth token. Session caching might not work correctly.",
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any

import pytest
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
from oauthlib.oauth2.rfc6749.errors import InvalidClientError
from shapely.geometry import Polygon

from sentinelhub import (
Expand Down Expand Up @@ -483,7 +483,7 @@ def test_bad_credentials() -> None:
bad_credentials_config.sh_client_id = "test"

request = SentinelHubRequest(**request_params, config=bad_credentials_config)
with pytest.raises(CustomOAuth2Error):
with pytest.raises(InvalidClientError):
request.get_data()

missing_credentials_config = SHConfig()
Expand Down
23 changes: 6 additions & 17 deletions tests/download/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

import pytest
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error, InvalidClientError
from requests_mock import Mocker

from sentinelhub import SentinelHubSession, SHConfig, __version__
Expand Down Expand Up @@ -48,15 +48,12 @@ def test_session(session: SentinelHubSession) -> None:

@pytest.mark.sh_integration()
def test_token_info(session: SentinelHubSession) -> None:
info = session.info()

for key in ["sub", "aud", "jti", "exp", "name", "email", "sid", "org", "did", "aid", "d"]:
assert key in info
assert "azp" in session.info()


def test_session_content_and_headers(fake_config: SHConfig, fake_token: dict[str, Any], requests_mock: Mocker) -> None:
"""Make sure correct content and headers are passed to the service."""
requests_mock.post(url="/oauth/token", response_list=[{"json": fake_token}])
requests_mock.post(url=fake_config.sh_token_url, response_list=[{"json": fake_token}])
call_time = time.time()
token = SentinelHubSession(config=fake_config).token
# "expires_at" is derived from "expires_in" and not read from the response field "expires_at"
Expand Down Expand Up @@ -108,7 +105,7 @@ def test_refreshing_procedure(fake_token: JsonDict, fake_config: SHConfig) -> No
assert session.token == fake_token

session = SentinelHubSession(config=fake_config, refresh_before_expiry=500, _token=fake_token)
with pytest.raises(CustomOAuth2Error):
with pytest.raises(InvalidClientError):
_ = session.token


Expand All @@ -128,11 +125,7 @@ def test_oauth_compliance_hook_4xx(
expected_exception: type[Exception],
fake_config: SHConfig,
) -> None:
requests_mock.post(
"https://services.sentinel-hub.com/oauth/token",
json=response_payload,
status_code=status_code,
)
requests_mock.post(fake_config.sh_token_url, json=response_payload, status_code=status_code)

with pytest.raises(expected_exception):
SentinelHubSession(config=fake_config)
Expand All @@ -151,11 +144,7 @@ def test_oauth_compliance_hook_4xx(
def test_oauth_compliance_hook_5xx(
requests_mock: Mocker, status_code: int, response_payload: JsonDict | None, fake_config: SHConfig
) -> None:
requests_mock.post(
"https://services.sentinel-hub.com/oauth/token",
json=response_payload,
status_code=status_code,
)
requests_mock.post(fake_config.sh_token_url, json=response_payload, status_code=status_code)

fake_config.max_download_attempts = 10
fake_config.download_sleep_time = 0
Expand Down

0 comments on commit 500cf5c

Please sign in to comment.