Skip to content

🔨 Fix capture osparc variables #172

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
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
4 changes: 3 additions & 1 deletion clients/python/client/osparc/_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
from uuid import UUID

from pydantic import AnyHttpUrl, Field, field_validator
from pydantic import AliasChoices, AnyHttpUrl, Field, field_validator
from pydantic_settings import BaseSettings


Expand All @@ -27,8 +27,10 @@ def _validate_uuids(cls, v: Optional[str]) -> Optional[str]:
class ConfigurationModel(BaseSettings):
"""Model for capturing env vars which should go into the Configuration"""

# Service side: https://github.com/ITISFoundation/osparc-simcore/pull/5966
OSPARC_API_HOST: AnyHttpUrl = Field(
default=...,
validation_alias=AliasChoices("OSPARC_API_BASE_URL", "OSPARC_API_HOST"),
description="OSPARC api url",
examples=["https://api.osparc-master.speag.com/"],
)
Expand Down
21 changes: 19 additions & 2 deletions clients/python/test/test_osparc/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,46 @@ def check_headers(**kwargs):
@pytest.mark.parametrize(
"OSPARC_API_HOST", ["https://api.foo.com", "https://api.bar.com/", None]
)
@pytest.mark.parametrize(
"OSPARC_API_BASE_URL", ["https://api.sdkjbf.com", "https://api.alskjd.com/", None]
)
@pytest.mark.parametrize("OSPARC_API_KEY", ["key", None])
@pytest.mark.parametrize("OSPARC_API_SECRET", ["secret", None])
def test_api_client_constructor(
monkeypatch: pytest.MonkeyPatch,
OSPARC_API_HOST: Optional[str],
OSPARC_API_BASE_URL: Optional[str],
OSPARC_API_KEY: Optional[str],
OSPARC_API_SECRET: Optional[str],
):
with monkeypatch.context() as patch:
patch.delenv("OSPARC_API_HOST", raising=False)
patch.delenv("OSPARC_API_BASE_URL", raising=False)
patch.delenv("OSPARC_API_KEY", raising=False)
patch.delenv("OSPARC_API_SECRET", raising=False)

if OSPARC_API_HOST is not None:
patch.setenv("OSPARC_API_HOST", OSPARC_API_HOST)
if OSPARC_API_BASE_URL is not None:
patch.setenv("OSPARC_API_BASE_URL", OSPARC_API_BASE_URL)
if OSPARC_API_KEY is not None:
patch.setenv("OSPARC_API_KEY", OSPARC_API_KEY)
if OSPARC_API_SECRET is not None:
patch.setenv("OSPARC_API_SECRET", OSPARC_API_SECRET)

if OSPARC_API_HOST and OSPARC_API_KEY and OSPARC_API_SECRET:
if (
(OSPARC_API_HOST or OSPARC_API_BASE_URL)
and OSPARC_API_KEY
and OSPARC_API_SECRET
):
api = ApiClient()
assert api.configuration.host == OSPARC_API_HOST.rstrip("/")
# if OSPARC_API_BASE_URL and OSPARC_API_HOST are both
# in env, the former has preference
if OSPARC_API_BASE_URL is not None:
assert api.configuration.host == OSPARC_API_BASE_URL.rstrip("/")
elif OSPARC_API_HOST is not None:
assert api.configuration.host == OSPARC_API_HOST.rstrip("/")

assert api.configuration.username == OSPARC_API_KEY
assert api.configuration.password == OSPARC_API_SECRET

Expand Down
Loading