foxhole/app/config.py

78 lines
1.9 KiB
Python
Raw Permalink Normal View History

from pathlib import Path
import tomli
import pydantic
2023-07-30 14:50:08 +02:00
import os
DEBUG = True
2023-04-07 08:25:08 +02:00
MAIN_VERSION = "0.1.1"
2023-03-18 06:08:17 +01:00
class Config(pydantic.BaseModel):
domain: str
username: str
2023-04-03 09:40:25 +02:00
# admin_password: bytes # TODO admin password
name: str
summary: str
https: bool
icon_url: str
image_url: str | None = None
secret: str
debug: bool = False
trusted_hosts: list[str] = ["127.0.0.1"]
manually_approves_followers: bool = False
also_known_as: str | None = None
hides_followers: bool = False
hides_following: bool = False
inbox_retention_days: int = 15
2023-04-02 09:14:37 +02:00
post_token: str | None = None
2023-07-30 14:50:08 +02:00
sqlalchemy_database: str | None = None
ROOT_DIR = Path().parent.resolve()
_CONFIG_FILE = os.getenv("FOXHOLE_CONFIG_FILE", "config.toml")
def load_config() -> Config:
try:
return Config.parse_obj(
tomli.loads((ROOT_DIR / "data" / _CONFIG_FILE).read_text())
)
except FileNotFoundError:
raise ValueError(
f"{_CONFIG_FILE} is missing"
)
2023-03-18 06:08:17 +01:00
def get_version_commit() -> str:
import subprocess
try:
return (
'+' +
subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"])
.split()[0]
.decode()
)
except Exception:
return "+dev"
CONFIG = load_config()
DOMAIN = CONFIG.domain
2023-07-30 14:50:08 +02:00
DB_PATH = CONFIG.sqlalchemy_database or ROOT_DIR / "data" / "database.db"
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}"
_SCHEME = "https" if CONFIG.https else "http"
ID = f"{_SCHEME}://{DOMAIN}"
BASE_URL = ID
USERNAME = CONFIG.username
2024-02-26 14:12:20 +01:00
KEY_PATH = (ROOT_DIR / os.getenv("FOXHOLE_KEY_PATH", "data/key.pem"))
2023-03-17 09:49:09 +01:00
2023-03-18 06:08:17 +01:00
VERSION = "Foxhole-"+ MAIN_VERSION + get_version_commit()
USER_AGENT = "Fediverse Application/" + VERSION
2023-03-17 09:49:09 +01:00
AP_CONTENT_TYPE = "application/activity+json"
2023-03-17 18:46:31 +01:00
MANUALLY_APPROVES_FOLLOWERS = CONFIG.manually_approves_followers
2023-04-02 09:14:37 +02:00
POST_TOKEN = CONFIG.post_token