limit max number of users

This commit is contained in:
Davide Scaini
2026-04-10 12:35:34 +02:00
parent cbac82a2ba
commit 683b7d9c1b
4 changed files with 62 additions and 3 deletions
+17 -1
View File
@@ -18,8 +18,10 @@ console = Console()
@click.option("--port", default=4041, help="Bind port (default: 4041)")
@click.option("--strava-client-id", default=None, envvar="STRAVA_CLIENT_ID", help="Strava OAuth client ID (enables per-user Strava sync)")
@click.option("--strava-client-secret", default=None, envvar="STRAVA_CLIENT_SECRET", help="Strava OAuth client secret")
@click.option("--max-users", default=None, type=int, help="Override max users for this instance (0 = unlimited; updates the DB setting)")
def serve(data_dir: str, site_dir: Optional[str], host: str, port: int,
strava_client_id: Optional[str], strava_client_secret: Optional[str]) -> None:
strava_client_id: Optional[str], strava_client_secret: Optional[str],
max_users: Optional[int]) -> None:
"""Start the bincio multi-user application server.
Handles auth, user management, and write operations.
@@ -29,6 +31,7 @@ def serve(data_dir: str, site_dir: Optional[str], host: str, port: int,
"""
import uvicorn
import bincio.serve.server as srv
from bincio.serve.db import open_db, set_setting, get_setting
dd = Path(data_dir).expanduser().resolve()
if not (dd / "instance.db").exists():
@@ -36,6 +39,11 @@ def serve(data_dir: str, site_dir: Optional[str], host: str, port: int,
f"No instance.db found in {dd}. Run `bincio init --data-dir {dd}` first."
)
if max_users is not None:
db = open_db(dd)
set_setting(db, "max_users", str(max_users))
db.close()
srv.data_dir = dd
if site_dir:
srv.site_dir = Path(site_dir).expanduser().resolve()
@@ -44,11 +52,19 @@ def serve(data_dir: str, site_dir: Optional[str], host: str, port: int,
if strava_client_secret:
srv.strava_client_secret = strava_client_secret
db = open_db(dd)
current_limit = get_setting(db, "max_users")
db.close()
console.print(f"[bold]bincio serve[/bold]")
console.print(f" Data: [cyan]{dd}[/cyan]")
if srv.site_dir:
console.print(f" Site: [cyan]{srv.site_dir}[/cyan]")
console.print(f" URL: [cyan]http://{host}:{port}[/cyan]")
if current_limit and int(current_limit) > 0:
console.print(f" Users: [yellow]max {current_limit}[/yellow]")
else:
console.print(f" Users: [dim]unlimited[/dim]")
console.print()
uvicorn.run(srv.app, host=host, port=port, log_level="info")