Add keep_open_until to /allowed for hold-door; fix 9 bugs

/allowed returns keep_open_until from the newest approved hold in
doorlog; /longpoll skips hold events to avoid spurious open pulses.

Fixes: assert->raise for SECRET check, text() on 403, remove dead
/logs code, flatten auth decorator, by_slackid None fallback, load
kube config once, guard missing slack command, backoff on PyMongoError,
mongo->mongosh.
This commit is contained in:
Mykhailo Yermolenko
2026-06-17 16:42:54 +03:00
parent 1e93eabf0e
commit e6fc5cb85f
5 changed files with 75 additions and 80 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import os
from datetime import datetime, timezone
from typing import Tuple
@@ -70,6 +71,7 @@ async def slack_log_fwd(app):
except PyMongoError as e:
print(e)
await asyncio.sleep(5)
# -> approved, user, err
def slack_authz(authGroup: str, slackId: str, channel_id: str) -> Tuple[bool, str, str]:
@@ -96,6 +98,10 @@ async def slack_open(request):
return "Invalid token (are you Slack?)", 401
command = request.form.get("command")
if not command:
print("WARN: /slack-open route accessed without command")
return text("Missing command", status=400)
door = command.removeprefix("/open-").replace("-", "")
authGroup = fauthGroup(door)
@@ -110,7 +116,7 @@ async def slack_open(request):
request.form.get("channel_id"),
)
userExtra = f"{request.form.get("user_id")} (slack u/n: {request.form.get("user_name")})" # slackName can be changed by user
userExtra = f"{request.form.get('user_id')} (slack u/n: {request.form.get('user_name')})" # slackName can be changed by user
doors = [door]
if door == "alldoors":