aboutsummaryrefslogtreecommitdiff
path: root/jb/settings.py
blob: 7747afc442498d2a99479b19f0df9824f25f9c44 (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
79
80
81
82
83
84
85
86
import os
from functools import lru_cache
from pathlib import Path

from generalresearch.models.custom_types import InfluxDsn
from pydantic import Field, HttpUrl, PostgresDsn, RedisDsn, SecretStr
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: RedisDsn | None = Field(default=None)
    redis_timeout: float = Field(default=0.10)

    amt_jb_db: PostgresDsn = Field()

    amt_endpoint: HttpUrl | None = Field(default=None)
    amt_access_id: str | None = Field(default=None)
    amt_secret_key: str | None = Field(default=None)

    aws_owner_id: str = Field()
    aws_subscription_arn: 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"
    base_url: HttpUrl = Field(default=HttpUrl("https://jamesbillings67.com/"))

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

    product_id: UUIDStr = Field()

    influx_db: InfluxDsn | None = Field(default=None)

    sns_path: str = Field()

    session_token_ttl_seconds: int = Field(default=30 * 24 * 60 * 60, gt=0)
    session_jwt_secret: SecretStr = Field(min_length=32)

    magic_token_salt: SecretStr = Field(min_length=32)

    gr_api_host: HttpUrl = Field(default=HttpUrl("https://generalresearch.com/api/v2/"))
    gr_api_token: SecretStr = Field(min_length=1)

    mautic_api_key: SecretStr = Field(min_length=32)


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"
    base_url: HttpUrl = Field(default=HttpUrl("http://127.0.0.1:8081/"))


@lru_cache
def get_settings():
    return Settings()


@lru_cache
def get_test_settings():
    return TestSettings()