Skip to content

Commit

Permalink
change configuration of config and types to make the parent key optio…
Browse files Browse the repository at this point in the history
…nal, not the subkeys
  • Loading branch information
AbstractUmbra committed May 22, 2024
1 parent ba8f937 commit 12c3bff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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
11 changes: 9 additions & 2 deletions core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion types_/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 12c3bff

Please sign in to comment.