aboutsummaryrefslogtreecommitdiff
path: root/jb/settings.py
blob: d529591d12a58226123eb824edeb3f77572dcff4 (plain)
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
71
72
73
74
75
76
77
78
import os
from functools import lru_cache
from pathlib import Path
from typing import Optional

from generalresearchutils.models.custom_types import InfluxDsn
from pydantic import Field, PostgresDsn, HttpUrl, RedisDsn
from pydantic_settings import BaseSettings, SettingsConfigDict

from jb.models.custom_types import UUIDStr

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

BASE_HTML_PATH = Path(BASE_DIR) / "templates" / "base.html"
BASE_HTML = BASE_HTML_PATH.read_text()


class AmtJbBaseSettings(BaseSettings):
    debug: bool = Field(default=True)

    redis: Optional[RedisDsn] = Field(default=None)
    redis_timeout: float = Field(default=0.10)

    amt_jb_db: PostgresDsn = Field()

    amt_endpoint: Optional[HttpUrl] = Field(default=None)
    amt_access_id: Optional[str] = Field(default=None)
    amt_secret_key: Optional[str] = Field(default=None)

    aws_owner_id: str = Field()
    aws_subscription_arn: str = Field()

    amt_bonus_cashout_method: str = Field()
    amt_assignment_cashout_method: str = Field()


class Settings(AmtJbBaseSettings):
    model_config = SettingsConfigDict(
        env_prefix="",
        case_sensitive=False,
        env_file=os.path.join(BASE_DIR, ".env"),
        extra="allow",
        cli_parse_args=False,
    )
    debug: bool = False
    app_name: str = "AMT JB API"

    fsb_host: HttpUrl = Field(default=HttpUrl("https://fsb.generalresearch.com/"))
    # Needed for admin function on fsb w/o authentication
    fsb_host_private_route: Optional[str] = Field(default=None)

    product_id: UUIDStr = Field()

    influx_db: Optional[InfluxDsn] = Field(default=None)

    sns_path: str = Field()


class TestSettings(Settings):
    model_config = SettingsConfigDict(
        env_prefix="",
        case_sensitive=False,
        env_file=os.path.join(BASE_DIR, ".env.test"),
        extra="allow",
        cli_parse_args=False,
    )
    debug: bool = True
    app_name: str = "AMT JB API Test"


@lru_cache
def get_settings():
    return Settings()


@lru_cache
def get_test_settings():
    return TestSettings()