diff --git a/config.template.toml b/config.template.toml index 16ab7ac..860da18 100644 --- a/config.template.toml +++ b/config.template.toml @@ -8,10 +8,6 @@ maintenance = false [DATABASE] dsn = "postgres://mystbin:mystbin@database:5432/mystbin" -[REDIS] -limiter = "redis://redis:6379/0" # Optional -sessions = "redis://redis:6379/1" # Optional - [LIMITS] paste_get = { rate = 30, per = 60, priority = 1, bucket = "ip" } paste_get_day = { rate = 7200, per = 86400, priority = 2, bucket = "ip" } @@ -24,6 +20,10 @@ char_limit = 300_000 file_limit = 5 name_limit = 25 +[REDIS] # optional key +limiter = "redis://redis:6379/0" # required if key present +sessions = "redis://redis:6379/1" # required if key present + [GITHUB] # optional key token = "..." # a github token capable of creating gists, non-optional if the above key is provided timeout = 10 # how long to wait between posting gists if there's an influx of tokens posted. Non-optional diff --git a/core/server.py b/core/server.py index bd86119..bed80bc 100644 --- a/core/server.py +++ b/core/server.py @@ -47,8 +47,15 @@ def __init__(self, *, database: Database, session: aiohttp.ClientSession | None ] routes: list[Mount | Route] = [Mount("/static", app=StaticFiles(directory="web/static"), name="static")] - limit_redis = starlette_plus.Redis(url=CONFIG["REDIS"]["limiter"]) if CONFIG["REDIS"]["limiter"] else None - sess_redis = starlette_plus.Redis(url=CONFIG["REDIS"]["sessions"]) if CONFIG["REDIS"]["sessions"] else None + if redis_key := CONFIG.get("REDIS"): + limit_url = redis_key["limiter"] + session_url = redis_key["sessions"] + else: + limit_url = None + session_url = None + + limit_redis = starlette_plus.Redis(url=limit_url) + sess_redis = starlette_plus.Redis(url=session_url) global_limits = [CONFIG["LIMITS"]["global_limit"]] middleware = [ diff --git a/types_/config.py b/types_/config.py index b196186..8be4827 100644 --- a/types_/config.py +++ b/types_/config.py @@ -60,7 +60,7 @@ class Github(TypedDict): class Config(TypedDict): SERVER: Server DATABASE: Database - REDIS: Redis + REDIS: NotRequired[Redis] LIMITS: Limits PASTES: Pastes GITHUB: NotRequired[Github]