From 0e649209bc27b7d751940317f26e46aeca8aa601 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 15:56:51 +0100 Subject: [PATCH 01/16] Add userinfo feature --- dinamis_sdk/__init__.py | 2 +- dinamis_sdk/http.py | 22 ++++++++++++++++++---- dinamis_sdk/oauth2.py | 11 +++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dinamis_sdk/__init__.py b/dinamis_sdk/__init__.py index 3d58f79..2d20a64 100644 --- a/dinamis_sdk/__init__.py +++ b/dinamis_sdk/__init__.py @@ -14,7 +14,7 @@ from dinamis_sdk.signing import ( ) # noqa from .oauth2 import OAuth2Session # noqa from .upload import push -from .http import get_headers +from .http import get_headers, get_userinfo try: __version__ = version("dinamis_sdk") diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 37c0ac3..630e9f9 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -1,10 +1,10 @@ """HTTP connections with various methods.""" -from typing import Dict +from typing import Dict, Any from ast import literal_eval from pydantic import BaseModel, ConfigDict from .utils import get_logger_for, create_session -from .oauth2 import OAuth2Session +from .oauth2 import OAuth2Session, retrieve_token_endpoint from .model import ApiKey from .settings import ENV, SIGNING_ENDPOINT @@ -75,6 +75,15 @@ class HTTPSession: self.prepare_connection_method() return self._method + def get_userinfo(self): + """Get the userinfo endpoint.""" + openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") + + _session = create_session() + self.get_method() + res = _session.get(openapi_url, timeout=10, headers=self._method.get_headers()) + return res.json() + def prepare_connection_method(self): """Set the connection method.""" # Custom server without authentication method @@ -110,6 +119,11 @@ class HTTPSession: session = HTTPSession() -def get_headers(): - """Return the headers.""" +def get_headers() -> dict[str, Any]: + """Return the headers needed to authentificate on the system.""" return session.get_method().get_headers() + + +def get_userinfo() -> dict[str, str]: + """Return userinfo.""" + return session.get_userinfo() diff --git a/dinamis_sdk/oauth2.py b/dinamis_sdk/oauth2.py index 5469da4..5857b2a 100644 --- a/dinamis_sdk/oauth2.py +++ b/dinamis_sdk/oauth2.py @@ -55,6 +55,17 @@ class GrantMethodBase: "scope": "openid offline_access", } + def get_userinfo(self): + """Get the userinfo endpoint.""" + if not self._token_endpoint: + self._token_endpoint = retrieve_token_endpoint() + openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") + + _session = create_session() + res = _session.get(openapi_url, timeout=10, headers=self.headers) + print(res.content) + return + def refresh_token(self, old_jwt: JWT) -> JWT: """Refresh the token.""" log.debug("Refreshing token") -- GitLab From 185dc6a03ad61115842374f7c161bcc65b977a79 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:20:33 +0100 Subject: [PATCH 02/16] Fix linter --- dinamis_sdk/oauth2.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dinamis_sdk/oauth2.py b/dinamis_sdk/oauth2.py index 5857b2a..7d1a402 100644 --- a/dinamis_sdk/oauth2.py +++ b/dinamis_sdk/oauth2.py @@ -63,8 +63,7 @@ class GrantMethodBase: _session = create_session() res = _session.get(openapi_url, timeout=10, headers=self.headers) - print(res.content) - return + return res.json() def refresh_token(self, old_jwt: JWT) -> JWT: """Refresh the token.""" -- GitLab From 697e35ecb69eaa057880855e4151104c9bcea586 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:25:24 +0100 Subject: [PATCH 03/16] Add coverage --- .gitignore | 3 +++ .gitlab-ci.yml | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b3d3402..b44d133 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ dist/ *venv/ .vscode/ _version.py +*.xml +.coverage +htmlcov diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 741ca8a..02606e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,6 +39,7 @@ pylint: OAuth2 Tests: extends: .tests_base script: + - dinamis_cli list - python tests/test_spot_6_7_drs.py - python tests/test_super_s2.py - python tests/test_push.py @@ -47,18 +48,33 @@ OAuth2 Tests: API key Tests: extends: .tests_base script: + - pip install coverage - dinamis_cli register - - python tests/test_headers.py access-key + - coverage run tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ - - python tests/test_spot_6_7_drs.py - - python tests/test_super_s2.py - - python tests/test_push.py + - coverage run tests/test_spot_6_7_drs.py + - coverage run tests/test_super_s2.py + - coverage run tests/test_push.py # Test API key from environment variables - export DINAMIS_SDK_ACCESS_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f4) - export DINAMIS_SDK_SECRET_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f8) - rm /root/.config/dinamis_sdk_auth/.apikey # ensure that we use env. vars. - - python tests/test_spot_6_7_drs.py + - coverage run tests/test_spot_6_7_drs.py # bring back oauth2 credentials so we can revoke the API key - mv /root/.config/dinamis_sdk_auth/.jwt_ /root/.config/dinamis_sdk_auth/.jwt - dinamis_cli revoke ${DINAMIS_SDK_ACCESS_KEY} + - coverage report + - coverage xml + - coverage html + coverage: '/^TOTAL.+?(\d+\%)$/' + artifacts: + paths: + - htmlcov/ + when: always + reports: + coverage_report: + coverage_format: cobertura + path: coverage.xml + junit: report.xml + -- GitLab From 027f1b4ad97346fea659677c637c145e4bab96a1 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:25:45 +0100 Subject: [PATCH 04/16] Fix typo --- dinamis_sdk/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 630e9f9..1c485fe 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -120,7 +120,7 @@ session = HTTPSession() def get_headers() -> dict[str, Any]: - """Return the headers needed to authentificate on the system.""" + """Return the headers needed to authenticate on the system.""" return session.get_method().get_headers() -- GitLab From b519eba908e8cf74676e8fbf776d4c53ce7cb02f Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:31:09 +0100 Subject: [PATCH 05/16] Add misc tests --- .gitlab-ci.yml | 2 ++ tests/test_misc.py | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/test_misc.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02606e3..9402a1a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,6 +43,7 @@ OAuth2 Tests: - python tests/test_spot_6_7_drs.py - python tests/test_super_s2.py - python tests/test_push.py + - python tests/test_misc.py - python tests/test_headers.py authorization API key Tests: @@ -56,6 +57,7 @@ API key Tests: - coverage run tests/test_spot_6_7_drs.py - coverage run tests/test_super_s2.py - coverage run tests/test_push.py + - coverage run tests/test_misc.py # Test API key from environment variables - export DINAMIS_SDK_ACCESS_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f4) - export DINAMIS_SDK_SECRET_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f8) diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 0000000..d4e3ae4 --- /dev/null +++ b/tests/test_misc.py @@ -0,0 +1,11 @@ +"""Misc test module.""" + +import dinamis_sdk + + +def test_userinfo(): + """Test userinfo method.""" + dinamis_sdk.get_userinfo() + + +test_userinfo() -- GitLab From da960992f755d097541647cfff1a5db53d6d8ef3 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:37:34 +0100 Subject: [PATCH 06/16] Fix cov accumulation --- .gitlab-ci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9402a1a..cdde249 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,15 +54,15 @@ API key Tests: - coverage run tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ - - coverage run tests/test_spot_6_7_drs.py - - coverage run tests/test_super_s2.py - - coverage run tests/test_push.py - - coverage run tests/test_misc.py + - coverage run -a tests/test_spot_6_7_drs.py + - coverage run -a tests/test_super_s2.py + - coverage run -a tests/test_push.py + - coverage run -a tests/test_misc.py # Test API key from environment variables - export DINAMIS_SDK_ACCESS_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f4) - export DINAMIS_SDK_SECRET_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f8) - rm /root/.config/dinamis_sdk_auth/.apikey # ensure that we use env. vars. - - coverage run tests/test_spot_6_7_drs.py + - coverage run -a tests/test_spot_6_7_drs.py # bring back oauth2 credentials so we can revoke the API key - mv /root/.config/dinamis_sdk_auth/.jwt_ /root/.config/dinamis_sdk_auth/.jwt - dinamis_cli revoke ${DINAMIS_SDK_ACCESS_KEY} @@ -78,5 +78,4 @@ API key Tests: coverage_report: coverage_format: cobertura path: coverage.xml - junit: report.xml -- GitLab From fd77b97049109c2bee99d21076f6b8535612284e Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:52:46 +0100 Subject: [PATCH 07/16] Up --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cdde249..ff3f924 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,7 +51,7 @@ API key Tests: script: - pip install coverage - dinamis_cli register - - coverage run tests/test_headers.py access-key + - python tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ - coverage run -a tests/test_spot_6_7_drs.py -- GitLab From cee44d2eb8805afca093381c04e22f5caea455bb Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 16:58:08 +0100 Subject: [PATCH 08/16] Up --- dinamis_sdk/http.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 1c485fe..9a724f3 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -82,6 +82,7 @@ class HTTPSession: _session = create_session() self.get_method() res = _session.get(openapi_url, timeout=10, headers=self._method.get_headers()) + print(res.content) return res.json() def prepare_connection_method(self): -- GitLab From 57ce8150497d1ff5a62d551a9f54313da6cc5919 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 17:08:44 +0100 Subject: [PATCH 09/16] Up --- .gitlab-ci.yml | 2 +- dinamis_sdk/http.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff3f924..81ff22d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -54,10 +54,10 @@ API key Tests: - python tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ + - coverage run -a tests/test_misc.py - coverage run -a tests/test_spot_6_7_drs.py - coverage run -a tests/test_super_s2.py - coverage run -a tests/test_push.py - - coverage run -a tests/test_misc.py # Test API key from environment variables - export DINAMIS_SDK_ACCESS_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f4) - export DINAMIS_SDK_SECRET_KEY=$(cat /root/.config/dinamis_sdk_auth/.apikey | cut -d'"' -f8) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 9a724f3..1c485fe 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -82,7 +82,6 @@ class HTTPSession: _session = create_session() self.get_method() res = _session.get(openapi_url, timeout=10, headers=self._method.get_headers()) - print(res.content) return res.json() def prepare_connection_method(self): -- GitLab From 199752c1b4cd2ee6767931babeeab6ecbd3c52be Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 17:20:36 +0100 Subject: [PATCH 10/16] Fix tests --- dinamis_sdk/http.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 1c485fe..259ac42 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -80,9 +80,8 @@ class HTTPSession: openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") _session = create_session() - self.get_method() - res = _session.get(openapi_url, timeout=10, headers=self._method.get_headers()) - return res.json() + headers = OAuth2ConnectionMethod().get_headers() + return _session.get(openapi_url, timeout=10, headers=headers).json() def prepare_connection_method(self): """Set the connection method.""" -- GitLab From fb3ac721fdd573c1c1105c09fa06aef7bdc273ab Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 17:36:06 +0100 Subject: [PATCH 11/16] Merge tests to one --- .gitlab-ci.yml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 81ff22d..1d70c26 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,23 +35,20 @@ pylint: - pip install pylint - pylint dinamis_sdk tests - -OAuth2 Tests: - extends: .tests_base - script: - - dinamis_cli list - - python tests/test_spot_6_7_drs.py - - python tests/test_super_s2.py - - python tests/test_push.py - - python tests/test_misc.py - - python tests/test_headers.py authorization - -API key Tests: +Tests: extends: .tests_base script: - pip install coverage - - dinamis_cli register - - python tests/test_headers.py access-key + + - echo "Starting OAuth2 tests" + - coverage run -a tests/test_spot_6_7_drs.py + - coverage run -a tests/test_super_s2.py + - coverage run -a tests/test_push.py + - coverage run -a tests/test_misc.py + - coverage run -a tests/test_headers.py authorization + + - echo "Starting API key tests" + - coverage run -a tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ - coverage run -a tests/test_misc.py @@ -66,6 +63,7 @@ API key Tests: # bring back oauth2 credentials so we can revoke the API key - mv /root/.config/dinamis_sdk_auth/.jwt_ /root/.config/dinamis_sdk_auth/.jwt - dinamis_cli revoke ${DINAMIS_SDK_ACCESS_KEY} + - coverage report - coverage xml - coverage html -- GitLab From c640739170005a03fa11178a00199b736670479d Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Thu, 27 Feb 2025 17:40:47 +0100 Subject: [PATCH 12/16] Up --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1d70c26..517425c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,6 +48,7 @@ Tests: - coverage run -a tests/test_headers.py authorization - echo "Starting API key tests" + - dinamis_cli register - coverage run -a tests/test_headers.py access-key # ensure that we une only API key from now - mv /root/.config/dinamis_sdk_auth/.jwt /root/.config/dinamis_sdk_auth/.jwt_ -- GitLab From 540d585ae467025b301f16d921d7830849a7b4d2 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Fri, 28 Feb 2025 10:33:23 +0100 Subject: [PATCH 13/16] Move get_userinfo to connectionmethod --- dinamis_sdk/http.py | 22 +++++++++++++--------- tests/test_misc.py | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 259ac42..e6299e1 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -40,6 +40,14 @@ class OAuth2ConnectionMethod(BareConnectionMethod): """Return the headers.""" return {"authorization": f"bearer {self.oauth2_session.get_access_token()}"} + def get_userinfo(self): + """Get the userinfo endpoint.""" + openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") + + _session = create_session() + headers = OAuth2ConnectionMethod().get_headers() + return _session.get(openapi_url, timeout=10, headers=headers).json() + class ApiKeyConnectionMethod(BareConnectionMethod): """API key connection method.""" @@ -50,6 +58,10 @@ class ApiKeyConnectionMethod(BareConnectionMethod): """Return the headers.""" return self.api_key.to_dict() + def get_userinfo(self): + """User info method for API key. Not available.""" + raise NotImplementedError("No userinfo available with API key method.") + class HTTPSession: """HTTP session class.""" @@ -75,14 +87,6 @@ class HTTPSession: self.prepare_connection_method() return self._method - def get_userinfo(self): - """Get the userinfo endpoint.""" - openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") - - _session = create_session() - headers = OAuth2ConnectionMethod().get_headers() - return _session.get(openapi_url, timeout=10, headers=headers).json() - def prepare_connection_method(self): """Set the connection method.""" # Custom server without authentication method @@ -125,4 +129,4 @@ def get_headers() -> dict[str, Any]: def get_userinfo() -> dict[str, str]: """Return userinfo.""" - return session.get_userinfo() + return OAuth2ConnectionMethod().get_userinfo() diff --git a/tests/test_misc.py b/tests/test_misc.py index d4e3ae4..2adceed 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -5,7 +5,7 @@ import dinamis_sdk def test_userinfo(): """Test userinfo method.""" - dinamis_sdk.get_userinfo() + print(dinamis_sdk.get_userinfo()) test_userinfo() -- GitLab From ca560f72eff1950d990b8dead6f84903700caf42 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Fri, 28 Feb 2025 11:28:59 +0100 Subject: [PATCH 14/16] Simplify headers retrieval --- dinamis_sdk/http.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index e6299e1..86974fd 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -45,8 +45,7 @@ class OAuth2ConnectionMethod(BareConnectionMethod): openapi_url = retrieve_token_endpoint().replace("/token", "/userinfo") _session = create_session() - headers = OAuth2ConnectionMethod().get_headers() - return _session.get(openapi_url, timeout=10, headers=headers).json() + return _session.get(openapi_url, timeout=10, headers=self.get_headers()).json() class ApiKeyConnectionMethod(BareConnectionMethod): -- GitLab From e15f458b816730d5d8c7a92f248081a1ca579f77 Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Mon, 3 Mar 2025 15:35:40 +0100 Subject: [PATCH 15/16] Make signing endpoint a variable --- dinamis_sdk/http.py | 8 ++++---- dinamis_sdk/oauth2.py | 4 ++-- dinamis_sdk/settings.py | 20 ++++++++++++++------ tests/test_spot_6_7_drs.py | 11 ++++++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/dinamis_sdk/http.py b/dinamis_sdk/http.py index 86974fd..9ab1160 100644 --- a/dinamis_sdk/http.py +++ b/dinamis_sdk/http.py @@ -6,7 +6,7 @@ from pydantic import BaseModel, ConfigDict from .utils import get_logger_for, create_session from .oauth2 import OAuth2Session, retrieve_token_endpoint from .model import ApiKey -from .settings import ENV, SIGNING_ENDPOINT +from .settings import ENV log = get_logger_for(__name__) @@ -16,7 +16,7 @@ class BareConnectionMethod(BaseModel): """Bare connection method, no extra headers.""" model_config = ConfigDict(arbitrary_types_allowed=True) - endpoint: str = SIGNING_ENDPOINT + endpoint: str = ENV.dinamis_sdk_signing_endpoint def get_headers(self) -> Dict[str, str]: """Get the headers.""" @@ -89,9 +89,9 @@ class HTTPSession: def prepare_connection_method(self): """Set the connection method.""" # Custom server without authentication method - if ENV.dinamis_sdk_bypass_auth_api: + if ENV.dinamis_sdk_digning_disable_auth: self._method = BareConnectionMethod( - endpoint=ENV.dinamis_sdk_bypass_auth_api + endpoint=ENV.dinamis_sdk_signing_endpoint ) # API key method diff --git a/dinamis_sdk/oauth2.py b/dinamis_sdk/oauth2.py index 7d1a402..92338cb 100644 --- a/dinamis_sdk/oauth2.py +++ b/dinamis_sdk/oauth2.py @@ -8,14 +8,14 @@ from typing import Dict import qrcode # type: ignore from .utils import create_session, get_logger_for from .model import JWT, DeviceGrantResponse -from .settings import SIGNING_ENDPOINT +from .settings import ENV log = get_logger_for(__name__) def retrieve_token_endpoint(): """Retrieve the token endpoint from the s3 signing endpoint.""" - openapi_url = SIGNING_ENDPOINT + "openapi.json" + openapi_url = ENV.dinamis_sdk_signing_endpoint + "openapi.json" log.debug("Fetching OAuth2 endpoint from openapi url %s", openapi_url) _session = create_session() res = _session.get( diff --git a/dinamis_sdk/settings.py b/dinamis_sdk/settings.py index 63c722e..d36df84 100644 --- a/dinamis_sdk/settings.py +++ b/dinamis_sdk/settings.py @@ -8,25 +8,33 @@ from .utils import get_logger_for log = get_logger_for(__name__) +# Constants +APP_NAME = "dinamis_sdk_auth" +MAX_URLS = 64 +S3_STORAGE_DOMAIN = "meso.umontpellier.fr" +DEFAULT_SIGNING_ENDPOINT = ( + "https://s3-signing-cdos.apps.okd.crocc.meso.umontpellier.fr/" +) + class Settings(BaseSettings): """Environment variables.""" dinamis_sdk_ttl_margin: NonNegativeInt = 1800 dinamis_sdk_url_duration: NonNegativeInt = 0 - dinamis_sdk_bypass_auth_api: str = "" # Endpoint with no authentication. dinamis_sdk_config_dir: str = "" dinamis_sdk_access_key: str = "" dinamis_sdk_secret_key: str = "" dinamis_sdk_retry_total: PositiveInt = 10 dinamis_sdk_retry_backoff_factor: PositiveFloat = 0.8 + dinamis_sdk_digning_disable_auth: bool = False + dinamis_sdk_signing_endpoint: str = DEFAULT_SIGNING_ENDPOINT + + def model_post_init(self, __context): + if not self.dinamis_sdk_signing_endpoint.endswith("/"): + self.dinamis_sdk_signing_endpoint = self.dinamis_sdk_signing_endpoint + "/" -# Constants -APP_NAME = "dinamis_sdk_auth" -MAX_URLS = 64 -S3_STORAGE_DOMAIN = "meso.umontpellier.fr" -SIGNING_ENDPOINT = "https://s3-signing-cdos.apps.okd.crocc.meso.umontpellier.fr/" ENV = Settings() diff --git a/tests/test_spot_6_7_drs.py b/tests/test_spot_6_7_drs.py index 90ff1c3..e7568c9 100755 --- a/tests/test_spot_6_7_drs.py +++ b/tests/test_spot_6_7_drs.py @@ -1,11 +1,12 @@ """Spot 6/7 STAC items retrieval test.""" -import requests +import time import pystac_client import dinamis_sdk +start = time.time() api = pystac_client.Client.open( "https://stacapi-cdos.apps.okd.crocc.meso.umontpellier.fr", modifier=dinamis_sdk.sign_inplace, @@ -19,5 +20,9 @@ urls = [item.assets["src_xs"].href for item in res.items()] print(f"{len(urls)} items found") assert len(urls) > 1000 -response = requests.get(urls[0], timeout=10) -assert response.status_code == 200 +assert "Amz" in urls[0] + +print(urls[0]) + +elapsed = time.time() - start +print(f"Took {round(elapsed, 2)} s") -- GitLab From f62980221d066e9b190de7f4b2671088b293605f Mon Sep 17 00:00:00 2001 From: Pablo Boizeau <pablo.boizeau@ird.fr> Date: Mon, 3 Mar 2025 15:38:43 +0100 Subject: [PATCH 16/16] Fix linter --- dinamis_sdk/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dinamis_sdk/settings.py b/dinamis_sdk/settings.py index d36df84..be2d4a7 100644 --- a/dinamis_sdk/settings.py +++ b/dinamis_sdk/settings.py @@ -31,6 +31,7 @@ class Settings(BaseSettings): dinamis_sdk_signing_endpoint: str = DEFAULT_SIGNING_ENDPOINT def model_post_init(self, __context): + """Signing endpoint validation module.""" if not self.dinamis_sdk_signing_endpoint.endswith("/"): self.dinamis_sdk_signing_endpoint = self.dinamis_sdk_signing_endpoint + "/" -- GitLab