Skip to content
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
8 changes: 5 additions & 3 deletions openhexa/sdk/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import requests

from openhexa.sdk.utils import Iterator, Page, graphql, read_content
from openhexa.sdk.utils import Iterator, Page, Settings, graphql, read_content


class DatasetFile:
Expand All @@ -38,7 +38,7 @@ def __init__(

def read(self):
"""Download the file content and return it."""
response = requests.get(self.download_url, stream=True)
response = requests.get(self.download_url, stream=True, verify=Settings.verify_ssl())
response.raise_for_status()
return response.content

Expand Down Expand Up @@ -261,7 +261,9 @@ def add_file(

upload_url = upload_url_result["generateDatasetUploadUrl"]["uploadUrl"]
with read_content(source) as content:
response = requests.put(upload_url, data=content, headers={"Content-Type": mime_type})
response = requests.put(
upload_url, data=content, headers={"Content-Type": mime_type}, verify=Settings.verify_ssl()
)
response.raise_for_status()

data = graphql(
Expand Down
3 changes: 2 additions & 1 deletion openhexa/sdk/pipelines/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import requests
from multiprocess import get_context # NOQA

from openhexa.sdk.utils import Environment, get_environment
from openhexa.sdk.utils import Environment, Settings, get_environment

from .parameter import FunctionWithParameter, Parameter, ParameterValueError
from .task import PipelineWithTask, Task
Expand Down Expand Up @@ -186,6 +186,7 @@ def _update_progress(self, progress: int):
"query": query,
"variables": {"input": {"percent": progress}},
},
verify=Settings.verify_ssl(),
)
r.raise_for_status()
else:
Expand Down
4 changes: 4 additions & 0 deletions openhexa/sdk/pipelines/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Parameter,
validate_parameters,
)
from openhexa.sdk.utils import Settings

from .pipeline import Pipeline

Expand Down Expand Up @@ -91,11 +92,14 @@ def download_pipeline(url: str, token: str, run_id: str, target_dir: str) -> Non
"""

try:
import os

response = requests.post(
f"{url}/graphql/",
headers={"Authorization": f"Bearer {token}"},
json={"query": query, "variables": {"id": run_id}},
timeout=30,
verify=Settings.verify_ssl(),
)
response.raise_for_status()

Expand Down
20 changes: 16 additions & 4 deletions openhexa/sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
from openhexa.utils import create_requests_session


class Settings:
"""Centralized settings for the OpenHexa SDK."""

@staticmethod
def verify_ssl() -> bool:
"""Return the SSL verification flag from environment variables."""
return os.getenv("HEXA_VERIFY_SSL", "True").lower() not in ("0", "false")

@staticmethod
def debug() -> bool:
"""Return the debug flag from environment variables."""
return bool(os.getenv("DEBUG") or os.getenv("HEXA_DEBUG"))


class Environment(enum.Enum):
"""Enumeration of supported runtime environments."""

Expand All @@ -35,7 +49,7 @@ def graphql(operation: str, variables: dict[str | typing.Any] | None = None) ->
"HEXA_TOKEN"
] # Works for notebooks with the membership token and pipelines with the run token
headers = {"Authorization": f"Bearer {auth_token}"}
session = create_requests_session()
session = create_requests_session(verify=Settings.verify_ssl())

req = session.post(
f"{os.environ['HEXA_SERVER_URL'].rstrip('/')}/graphql/",
Expand Down Expand Up @@ -66,9 +80,7 @@ def __init__(self, token: str | None = None, server_url: str | None = None):
url = server_url or f"{os.environ['HEXA_SERVER_URL'].rstrip('/')}/graphql/"
token = token or os.getenv("HEXA_TOKEN")

verify_ssl = os.getenv("HEXA_VERIFY_SSL", "True").lower() not in ("0", "false")

super().__init__(url=url, token=token, verify=verify_ssl)
super().__init__(url=url, token=token, verify=Settings.verify_ssl())


class Iterator(metaclass=abc.ABCMeta):
Expand Down
Loading