-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,38 @@ | ||
from typing import Dict, Optional | ||
from functools import cached_property | ||
from typing import Dict | ||
|
||
from pydantic import BaseSettings, Extra, validator | ||
from pydantic.networks import AnyUrl | ||
from pydantic.types import PositiveInt, SecretStr | ||
from pydantic.types import SecretStr | ||
|
||
from .base import BaseCustomSettings | ||
from .basic_types import PortInt | ||
|
||
|
||
class RabbitDsn(AnyUrl): | ||
allowed_schemes = {"amqp"} | ||
|
||
|
||
class RabbitConfig(BaseSettings): | ||
class RabbitConfig(BaseCustomSettings): | ||
# host | ||
host: str = "rabbit" | ||
port: PositiveInt = 5672 | ||
RABBIT_HOST: str = "rabbit" | ||
RABBIT_PORT: PortInt = 5672 | ||
|
||
# auth | ||
user: str = "simcore" | ||
password: SecretStr = SecretStr("simcore") | ||
|
||
dsn: Optional[RabbitDsn] = None | ||
RABBIT_USER: str = "simcore" | ||
RABBIT_PASSWORD: SecretStr = SecretStr("simcore") | ||
|
||
# channels | ||
channels: Dict[str, str] = { | ||
RABBIT_CHANNELS: Dict[str, str] = { | ||
"log": "comp.backend.channels.log", | ||
"instrumentation": "comp.backend.channels.instrumentation", | ||
} | ||
|
||
@validator("dsn", pre=True) | ||
@classmethod | ||
def autofill_dsn(cls, v, values): | ||
if not v and all( | ||
key in values for key in cls.__fields__ if key not in ["dsn", "channels"] | ||
): | ||
return RabbitDsn.build( | ||
scheme="amqp", | ||
user=values["user"], | ||
password=values["password"].get_secret_value(), | ||
host=values["host"], | ||
port=f"{values['port']}", | ||
) | ||
return v | ||
|
||
class Config: | ||
env_prefix = "RABBIT_" | ||
extra = Extra.forbid | ||
@cached_property | ||
def dsn(self) -> str: | ||
return RabbitDsn.build( | ||
scheme="amqp", | ||
user=self.RABBIT_USER, | ||
password=self.RABBIT_PASSWORD.get_secret_value(), | ||
host=self.RABBIT_HOST, | ||
port=f"{self.RABBIT_PORT}", | ||
) |
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,39 +1,34 @@ | ||
from functools import cached_property | ||
from typing import Optional | ||
|
||
from pydantic import BaseSettings, PositiveInt, validator | ||
from pydantic.networks import RedisDsn | ||
from pydantic.types import SecretStr | ||
|
||
from .base import BaseCustomSettings | ||
from .basic_types import PortInt | ||
|
||
class RedisConfig(BaseSettings): | ||
|
||
class RedisConfig(BaseCustomSettings): | ||
# host | ||
host: str = "redis" | ||
port: PositiveInt = 6789 | ||
REDIS_HOST: str = "redis" | ||
REDIS_PORT: PortInt = 6789 | ||
|
||
# auth | ||
user: Optional[str] = None | ||
password: Optional[SecretStr] = None | ||
REDIS_USER: Optional[str] = None | ||
REDIS_PASSWORD: Optional[SecretStr] = None | ||
|
||
# db | ||
db: Optional[str] = "0" | ||
|
||
dsn: Optional[RedisDsn] = None | ||
|
||
@validator("dsn", pre=True) | ||
@classmethod | ||
def autofill_dsn(cls, v, values): | ||
if not v and all(key in values for key in cls.__fields__ if key != "dsn"): | ||
return RedisDsn.build( | ||
scheme="redis", | ||
user=values["user"] or None, | ||
password=values["password"].get_secret_value() | ||
if values["password"] | ||
else None, | ||
host=values["host"], | ||
port=f"{values['port']}", | ||
path=f"/{values['db']}", | ||
) | ||
return v | ||
|
||
class Config: | ||
env_prefix = "REDIS_" | ||
REDIS_DB: Optional[str] = "0" | ||
|
||
@cached_property | ||
def dsn(self) -> str: | ||
return RedisDsn.build( | ||
scheme="redis", | ||
user=self.REDIS_USER or None, | ||
password=self.REDIS_PASSWORD.get_secret_value() | ||
if self.REDIS_PASSWORD | ||
else None, | ||
host=self.REDIS_HOST, | ||
port=f"{self.REDIS_PORT}", | ||
path=f"/{self.REDIS_DB}", | ||
) |
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,13 +1,9 @@ | ||
from pydantic import BaseSettings | ||
from .base import BaseCustomSettings | ||
|
||
|
||
class S3Config(BaseSettings): | ||
endpoint: str = "minio:9000" | ||
access_key: str = "12345678" | ||
secret_key: str = "12345678" | ||
bucket_name: str = "simcore" | ||
secure: bool = False | ||
|
||
class Config: | ||
case_sensitive = False | ||
env_prefix = "S3_" | ||
class S3Config(BaseCustomSettings): | ||
S3_ENDPOINT: str = "minio:9000" | ||
S3_ACCESS_KEY: str = "12345678" | ||
S3_SECRET_KEY: str = "12345678" | ||
S3_BUCKET_NAME: str = "simcore" | ||
S3_SECURE: bool = False |
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