Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import os
from copy import deepcopy
from typing import Any, TypeVar
from typing import Annotated, Any, Final, TypeVar

from common_library.errors_classes import OsparcErrorMixin
from models_library.basic_types import ConstrainedStr

from pydantic import BaseModel
from pydantic import BaseModel, Discriminator, PositiveInt, Tag

from .utils.string_substitution import OSPARC_IDENTIFIER_PREFIX

T = TypeVar("T")


class OsparcVariableIdentifier(ConstrainedStr):
class _BaseOsparcVariableIdentifier(ConstrainedStr):
# NOTE: To allow parametrized value, set the type to Union[OsparcVariableIdentifier, ...]
# NOTE: When dealing with str types, to avoid unexpected behavior, the following
# order is suggested `OsparcVariableIdentifier | str`
# NOTE: in below regex `{`` and `}` are respectively escaped with `{{` and `}}`
pattern = (
rf"^\${{1,2}}(?:\{{)?{OSPARC_IDENTIFIER_PREFIX}[A-Za-z0-9_]+(?:\}})?(:-.+)?$"
)

def _get_without_template_markers(self) -> str:
# $VAR
Expand All @@ -42,6 +38,40 @@ def default_value(self) -> str | None:
parts = self._get_without_template_markers().split(":-")
return parts[1] if len(parts) > 1 else None

@staticmethod
def get_pattern(max_dollars: PositiveInt) -> str:
# NOTE: in below regex `{`` and `}` are respectively escaped with `{{` and `}}`
return rf"^\${{1,{max_dollars}}}(?:\{{)?{OSPARC_IDENTIFIER_PREFIX}[A-Za-z0-9_]+(?:\}})?(:-.+)?$"


class PlatformOsparcVariableIdentifier(_BaseOsparcVariableIdentifier):
pattern = _BaseOsparcVariableIdentifier.get_pattern(max_dollars=2)


class OoilOsparcVariableIdentifier(_BaseOsparcVariableIdentifier):
pattern = _BaseOsparcVariableIdentifier.get_pattern(max_dollars=4)


_PLATFORM: Final[str] = "platform"
_OOIL_VERSION: Final[str] = "ooil-version"


def _get_discriminator_value(v: Any) -> str:
_ = v
if os.environ.get("ENABLE_OOIL_OSPARC_VARIABLE_IDENTIFIER", None):
return _OOIL_VERSION

return _PLATFORM


OsparcVariableIdentifier = Annotated[
(
Annotated[PlatformOsparcVariableIdentifier, Tag(_PLATFORM)]
| Annotated[OoilOsparcVariableIdentifier, Tag(_OOIL_VERSION)]
),
Discriminator(_get_discriminator_value),
]


class UnresolvedOsparcVariableIdentifierError(OsparcErrorMixin, TypeError):
msg_template = "Provided argument is unresolved: value={value}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
""" Library to facilitate the integration of user services running in osparc-simcore

"""
"""Library to facilitate the integration of user services running in osparc-simcore"""

from ._meta import __version__
34 changes: 29 additions & 5 deletions packages/service-integration/tests/data/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
paths-mapping:
inputs_path: "/config/workspace/inputs"
outputs_path: "/config/workspace/outputs"
state_paths:
- "/config"
settings:
- name: resources
type: Resources
Expand All @@ -20,3 +15,32 @@ settings:
# - name: environment
# type: string
# -
paths-mapping:
inputs_path: "/config/workspace/inputs"
outputs_path: "/config/workspace/outputs"
state_paths:
- "/config"
callbacks-mapping:
inactivity:
service: container
command: ["python", "/usr/local/bin/service-monitor/activity.py"]
timeout: 1
compose-spec:
version: "3.7"
services:
jupyter-math:
image: $$$${SIMCORE_REGISTRY}/simcore/services/dynamic/jupyter-math:$$$${SERVICE_VERSION}
environment:
- OSPARC_API_HOST=$$$${OSPARC_VARIABLE_API_HOST}
- OSPARC_API_KEY=$$$${OSPARC_VARIABLE_API_KEY}
- OSPARC_API_SECRET=$$$${OSPARC_VARIABLE_API_SECRET}
container-http-entrypoint: jupyter-math
containers-allowed-outgoing-permit-list:
jupyter-math:
- hostname: $$$${OSPARC_VARIABLE_VENDOR_SECRET_LICENSE_SERVER_HOST}
tcp_ports: [$$OSPARC_VARIABLE_VENDOR_SECRET_LICENSE_SERVER_PRIMARY_PORT, $$OSPARC_VARIABLE_VENDOR_SECRET_LICENSE_SERVER_SECONDARY_PORT]
dns_resolver:
address: $$$${OSPARC_VARIABLE_VENDOR_SECRET_LICENSE_DNS_RESOLVER_IP}
port: $$$${OSPARC_VARIABLE_VENDOR_SECRET_LICENSE_DNS_RESOLVER_PORT}
containers-allowed-outgoing-internet:
- jupyter-math
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest
import yaml
from pydantic import BaseModel
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from service_integration.compose_spec_model import BuildItem, Service
from service_integration.osparc_config import (
DockerComposeOverwriteConfig,
Expand All @@ -19,7 +20,13 @@


@pytest.fixture
def settings() -> AppSettings:
def settings(monkeypatch: pytest.MonkeyPatch) -> AppSettings:
setenvs_from_dict(
monkeypatch,
{
"ENABLE_OOIL_OSPARC_VARIABLE_IDENTIFIER": "true",
},
)
return AppSettings()


Expand Down
Loading