Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct bad DX/UX of configuration #46

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Loading