-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from golemfactory/blue/pydantic
Port `dapp-runner` to `pydantic`
- Loading branch information
Showing
15 changed files
with
223 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,63 @@ | ||
"""Class definitions for the Dapp Runner's configuration descriptor.""" | ||
import os | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
|
||
from .base import BaseDescriptor | ||
from pydantic import BaseModel, Field, validator | ||
|
||
|
||
@dataclass | ||
class YagnaConfig(BaseDescriptor["YagnaConfig"]): | ||
class YagnaConfig(BaseModel): | ||
"""Yagna daemon configuration properties. | ||
Properties describing the local requestor daemon configuration that | ||
the Dapp Runner will use to run services on Golem. | ||
""" | ||
|
||
def __app_key__factory(value: str): # type: ignore [misc] # noqa | ||
subnet_tag: Optional[str] | ||
api_url: Optional[str] = None | ||
gsb_url: Optional[str] = None | ||
app_key: Optional[str] = None | ||
|
||
class Config: # noqa: D106 | ||
extra = "forbid" | ||
|
||
@validator("app_key", always=True) | ||
def __app_key__extrapolate(cls, v): | ||
# TODO this should be applied uniformly across any fields, | ||
# for now, making an exception for the app key | ||
|
||
if value and value.startswith("$"): | ||
return os.environ[value[1:]] | ||
|
||
return value | ||
if v and v.startswith("$"): | ||
return os.environ[v[1:]] | ||
|
||
subnet_tag: Optional[str] | ||
api_url: Optional[str] = None | ||
gsb_url: Optional[str] = None | ||
app_key: Optional[str] = field(metadata={"factory": __app_key__factory}, default=None) | ||
return v | ||
|
||
|
||
@dataclass | ||
class PaymentConfig: | ||
class PaymentConfig(BaseModel): | ||
"""Requestor's payment config.""" | ||
|
||
budget: float | ||
driver: str | ||
network: str | ||
|
||
class Config: # noqa: D106 | ||
extra = "forbid" | ||
|
||
@dataclass | ||
class LimitsConfig: | ||
|
||
class LimitsConfig(BaseModel): | ||
"""Limits of the running app.""" | ||
|
||
startup_timeout: Optional[int] = None # seconds | ||
max_running_time: Optional[int] = None # seconds | ||
|
||
class Config: # noqa: D106 | ||
extra = "forbid" | ||
|
||
|
||
@dataclass | ||
class Config(BaseDescriptor["Config"]): | ||
class Config(BaseModel): | ||
"""Root configuration descriptor for the Dapp Runner.""" | ||
|
||
yagna: YagnaConfig | ||
payment: PaymentConfig | ||
limits: LimitsConfig = field(default_factory=LimitsConfig) | ||
limits: LimitsConfig = Field(default_factory=LimitsConfig) | ||
|
||
class Config: # noqa: D106 | ||
extra = "forbid" |
Oops, something went wrong.