-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparameters.py
More file actions
70 lines (52 loc) · 1.9 KB
/
parameters.py
File metadata and controls
70 lines (52 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Simvue Configuration File Models
================================
Pydantic models for elements of the Simvue configuration file
"""
import logging
import time
import pydantic
import typing
import pathlib
import simvue.models as sv_models
from simvue.utilities import get_expiry
from simvue.api.url import URL
logger = logging.getLogger(__file__)
class ServerSpecifications(pydantic.BaseModel):
url: pydantic.AnyHttpUrl | None
token: pydantic.SecretStr | None
@pydantic.field_validator("url")
@classmethod
def url_to_api_url(cls, v: typing.Any) -> str | None:
if not v:
return
if f"{v}".endswith("/api"):
return f"{v}"
_url = URL(f"{v}") / "api"
return f"{_url}"
@pydantic.field_validator("token")
def check_token(cls, v: typing.Any) -> str | None:
if not v:
return
value = v.get_secret_value()
if not (expiry := get_expiry(value)):
raise AssertionError("Failed to parse Simvue token - invalid token form")
if time.time() - expiry > 0:
raise AssertionError("Simvue token has expired")
return v
class OfflineSpecifications(pydantic.BaseModel):
cache: pathlib.Path | None = None
country_iso_code: str | None = None
class MetricsSpecifications(pydantic.BaseModel):
resources_metrics_interval: pydantic.PositiveInt | None = -1
emission_metrics_interval: pydantic.PositiveInt | None = None
enable_emission_metrics: bool = False
class DefaultRunSpecifications(pydantic.BaseModel):
name: str | None = None
description: str | None = None
tags: list[str] | None = None
folder: str = pydantic.Field("/", pattern=sv_models.FOLDER_REGEX)
metadata: dict[str, str | int | float | bool] | None = None
mode: typing.Literal["offline", "disabled", "online"] = "online"
class ClientGeneralOptions(pydantic.BaseModel):
debug: bool = False