77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
from pathlib import Path
|
|
|
|
import tomli
|
|
import pydantic
|
|
import os
|
|
|
|
DEBUG = True
|
|
MAIN_VERSION = "0.1.1"
|
|
|
|
|
|
class Config(pydantic.BaseModel):
|
|
domain: str
|
|
username: str
|
|
# 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
|
|
post_token: str | None = None
|
|
|
|
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"
|
|
)
|
|
|
|
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
|
|
|
|
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
|
|
KEY_PATH = (ROOT_DIR / os.getenv("FOXHOLE_KEY_PATH", "data/key.pem"))
|
|
|
|
VERSION = "Foxhole-"+ MAIN_VERSION + get_version_commit()
|
|
USER_AGENT = "Fediverse Application/" + VERSION
|
|
AP_CONTENT_TYPE = "application/activity+json"
|
|
|
|
MANUALLY_APPROVES_FOLLOWERS = CONFIG.manually_approves_followers
|
|
POST_TOKEN = CONFIG.post_token
|