From cdfdf6eace01569414296445ce0618fefef61c64 Mon Sep 17 00:00:00 2001
From: Cresson Remi <remi.cresson@irstea.fr>
Date: Thu, 30 May 2024 21:30:11 +0200
Subject: [PATCH 1/4] Update 2 files

- /dinamis_sdk/utils.py
- /dinamis_sdk/s3.py
---
 dinamis_sdk/s3.py    | 15 +++++++++++++--
 dinamis_sdk/utils.py | 20 ++++++++++++--------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/dinamis_sdk/s3.py b/dinamis_sdk/s3.py
index fa2e592..f544a13 100644
--- a/dinamis_sdk/s3.py
+++ b/dinamis_sdk/s3.py
@@ -26,8 +26,16 @@ from pystac_client import ItemSearch
 import packaging.version
 import pydantic
 
-from .utils import log, SIGNED_URL_TTL_MARGIN, CREDENTIALS, MAX_URLS, \
-    S3_SIGNING_ENDPOINT, S3_STORAGE_DOMAIN, SIGNED_URL_DURATION_SECONDS
+from .utils import (
+    log,
+    SIGNED_URL_TTL_MARGIN, 
+    CREDENTIALS, 
+    MAX_URLS,
+    S3_SIGNING_ENDPOINT, 
+    S3_STORAGE_DOMAIN, 
+    SIGNED_URL_DURATION_SECONDS,
+    BYPASS_API
+)
 
 _PYDANTIC_2_0 = packaging.version.parse(
     pydantic.__version__
@@ -35,6 +43,7 @@ _PYDANTIC_2_0 = packaging.version.parse(
 
 AssetLike = TypeVar("AssetLike", Asset, Dict[str, Any])
 
+# todo: fix the expression
 asset_xpr = re.compile(
     r"https://(?P<account>[A-z0-9]+?)"
     r"\.minio-dinamis\.apps\.okd\.crocc\.meso\.umontpellier\.fr/"
@@ -443,6 +452,8 @@ def get_signed_urls(
             "dinamis-secret-key": CREDENTIALS.secret_key
         })
         log.debug("Using credentials (access/secret keys)")
+    elif BYPASS_API:
+        log.debug("Using bypass API %s", BYPASS_API)
     else:
         from .auth import get_access_token
         access_token = get_access_token()
diff --git a/dinamis_sdk/utils.py b/dinamis_sdk/utils.py
index 60414d8..e6df8e8 100644
--- a/dinamis_sdk/utils.py
+++ b/dinamis_sdk/utils.py
@@ -6,11 +6,16 @@ import appdirs
 from pydantic import BaseModel  # pylint: disable = no-name-in-module
 import requests
 
+# Env vars
+ENV_TTL_MARGIN = "DINAMIS_SDK_TTL_MARGIN"
+ENV_DURATION_SECS = "DINAMIS_SDK_DURATION_SECONDS"
+ENV_BYPASS_API = "DINAMIS_SDK_BYPASS_API"
+
 logging.basicConfig(level=os.environ.get("LOGLEVEL") or "INFO")
 log = logging.getLogger("dinamis_sdk")
 
 
-def _get_seconds(env_var_name: str, default: int) -> int:
+def _get_seconds(env_var_name: str, default: int = None) -> int:
     val = os.environ.get(env_var_name)
     if val:
         if val.isdigit():
@@ -24,11 +29,8 @@ def _get_seconds(env_var_name: str, default: int) -> int:
 
 
 # Signed TTL margin default to 1800 seconds (30 minutes), or env. var.
-SIGNED_URL_TTL_MARGIN = _get_seconds("DINAMIS_SDK_TTL_MARGIN", 1800)
-SIGNED_URL_DURATION_SECONDS = _get_seconds(
-    "DINAMIS_SDK_DURATION_SECONDS", 
-    None
-)
+SIGNED_URL_TTL_MARGIN = _get_seconds(ENV_TTL_MARGIN, 1800)
+SIGNED_URL_DURATION_SECONDS = _get_seconds(ENV_DURATION_SECS)
 
 MAX_URLS = 64
 S3_STORAGE_DOMAIN = "meso.umontpellier.fr"
@@ -83,12 +85,14 @@ def retrieve_token_endpoint(s3_signing_endpoint: str = S3_SIGNING_ENDPOINT):
     return oauth2_defs["flows"]["password"]["tokenUrl"]
 
 
+BYPASS_API = os.environ.get(ENV_BYPASS_API)
+
 # Token endpoint is typically something like: https://keycloak-dinamis.apps.okd
 # .crocc.meso.umontpellier.fr/auth/realms/dinamis/protocol/openid-connect/token
-TOKEN_ENDPOINT = retrieve_token_endpoint()
+TOKEN_ENDPOINT = None if BYPASS_API else retrieve_token_endpoint()
 # Auth base URL is typically something like: https://keycloak-dinamis.apps.okd.
 # crocc.meso.umontpellier.fr/auth/realms/dinamis/protocol/openid-connect
-AUTH_BASE_URL = TOKEN_ENDPOINT.rsplit('/', 1)[0]
+AUTH_BASE_URL = None if BYPASS_API else TOKEN_ENDPOINT.rsplit('/', 1)[0]
 
 # Token server (optional)
 TOKEN_SERVER = os.environ.get("DINAMIS_SDK_TOKEN_SERVER")
-- 
GitLab


From 3c15747d914d91e8ddaec596b92c869e2fb8118d Mon Sep 17 00:00:00 2001
From: Cresson Remi <remi.cresson@irstea.fr>
Date: Thu, 30 May 2024 21:30:28 +0200
Subject: [PATCH 2/4] Update file setup.py

---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index b10cbd1..ec49f65 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ install_requires = [
 
 setup(
     name="dinamis-sdk",
-    version="0.1.9",
+    version="0.1.10",
     description="DINAMIS SDK",
     python_requires=">=3.8",
     author="Remi Cresson",
-- 
GitLab


From 567cc017c932e618bc848c9ed51167cb8d47ddd4 Mon Sep 17 00:00:00 2001
From: Cresson Remi <remi.cresson@irstea.fr>
Date: Fri, 31 May 2024 10:55:13 +0200
Subject: [PATCH 3/4] Update 2 files

- /dinamis_sdk/auth.py
- /setup.py
---
 dinamis_sdk/auth.py | 2 +-
 setup.py            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/dinamis_sdk/auth.py b/dinamis_sdk/auth.py
index d2fbd21..aa6a2ed 100644
--- a/dinamis_sdk/auth.py
+++ b/dinamis_sdk/auth.py
@@ -59,7 +59,7 @@ class GrantMethodBase:
         """Base payload."""
         return {
             "client_id": self.client_id,
-            "scope": "offline_access"
+            "scope": "offline_access openid"
         }
 
     def refresh_token(self, old_jwt: JWT) -> JWT:
diff --git a/setup.py b/setup.py
index ec49f65..36bf2ad 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ install_requires = [
 
 setup(
     name="dinamis-sdk",
-    version="0.1.10",
+    version="0.1.11",
     description="DINAMIS SDK",
     python_requires=">=3.8",
     author="Remi Cresson",
-- 
GitLab


From 25ce727d44dc00a2901e5e4deb967955b3a1ceaa Mon Sep 17 00:00:00 2001
From: Cresson Remi <remi.cresson@irstea.fr>
Date: Fri, 31 May 2024 11:06:50 +0200
Subject: [PATCH 4/4] Update 2 files

- /setup.py
- /dinamis_sdk/auth.py
---
 dinamis_sdk/auth.py | 2 +-
 setup.py            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/dinamis_sdk/auth.py b/dinamis_sdk/auth.py
index aa6a2ed..16e88aa 100644
--- a/dinamis_sdk/auth.py
+++ b/dinamis_sdk/auth.py
@@ -59,7 +59,7 @@ class GrantMethodBase:
         """Base payload."""
         return {
             "client_id": self.client_id,
-            "scope": "offline_access openid"
+            "scope": "openid"
         }
 
     def refresh_token(self, old_jwt: JWT) -> JWT:
diff --git a/setup.py b/setup.py
index 36bf2ad..ec49f65 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ install_requires = [
 
 setup(
     name="dinamis-sdk",
-    version="0.1.11",
+    version="0.1.10",
     description="DINAMIS SDK",
     python_requires=">=3.8",
     author="Remi Cresson",
-- 
GitLab