Kuma: sign in with a session token, wait for Kuma to be ready #54

Merged
jared merged 1 commits from kuma-token into main 2026-11-19 21:01:57 -05:00
Owner

Why

The Kuma account has two-factor login, so the password login from #53 would always end in tokenRequired. Prod config.json now holds a Kuma session token instead: uptime_kuma = {url, token, maintenance_id: 7}.

Changes (kuma.py)

  • Sign in with loginByToken. A refusal is reported as "token rejected (Kuma password changed?)". username and password remain as a fallback for an account without two-factor login; with 2FA that path now says to use the token.
  • Wait for Kuma's first info event before emitting anything. Kuma registers its handlers only after sending info, so an earlier emit is silently dropped and times out now and then. If info doesn't arrive within the timeout, the error is "Kuma not ready".
  • configured() needs url, maintenance_id, and a token (or username and password).
  • README: the config row for the new key.

pauseMaintenance and resumeMaintenance with an int id, returning {ok, msg}, are confirmed correct on Kuma 2.5.5.

Tested

  • From prod (as www-data, with the branch's kuma.py) against Kuma 2.5.5: signed in by token and paused window 7, which was already paused, so nothing changed. Window 7 is still inactive.
  • 603 tests pass (new: token sign-in, rejected token, nothing sent before info, password fallback, 2FA message). flake8 and bandit are clean.

🤖 Generated with Claude Code

## Why The Kuma account has two-factor login, so the password login from #53 would always end in `tokenRequired`. Prod `config.json` now holds a Kuma session token instead: `uptime_kuma = {url, token, maintenance_id: 7}`. ## Changes (`kuma.py`) - **Sign in with `loginByToken`.** A refusal is reported as "token rejected (Kuma password changed?)". `username` and `password` remain as a fallback for an account without two-factor login; with 2FA that path now says to use the token. - **Wait for Kuma's first `info` event before emitting anything.** Kuma registers its handlers only after sending `info`, so an earlier emit is silently dropped and times out now and then. If `info` doesn't arrive within the timeout, the error is "Kuma not ready". - **`configured()`** needs `url`, `maintenance_id`, and a token (or username and password). - **README**: the config row for the new key. `pauseMaintenance` and `resumeMaintenance` with an int id, returning `{ok, msg}`, are confirmed correct on Kuma 2.5.5. ## Tested - From prod (as www-data, with the branch's `kuma.py`) against Kuma 2.5.5: signed in by token and paused window 7, which was already paused, so nothing changed. Window 7 is still inactive. - 603 tests pass (new: token sign-in, rejected token, nothing sent before `info`, password fallback, 2FA message). flake8 and bandit are clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-19 20:59:47 -05:00
Kuma: sign in with a session token, wait for Kuma to be ready
Lint / JS (eslint) (push) Successful in 10s
Lint / Python (flake8) (push) Successful in 58s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m1s
Lint / Python (flake8) (pull_request) Successful in 57s
Lint / JS (eslint) (pull_request) Successful in 8s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Test / Python Tests (pytest) (push) Successful in 1m34s
Test / Python Tests (pytest) (pull_request) Successful in 1m45s
Security / Python Security (bandit) (pull_request) Successful in 59s
1444562a5d
The Kuma account has two-factor login, so a password login always ends
in tokenRequired. Prod config now holds a Kuma session token instead
(uptime_kuma = {url, token, maintenance_id}).

- Sign in with loginByToken; a refusal says the token was rejected
  (Kuma password changed?). username/password stay as a fallback for an
  account without two-factor login.
- Wait for Kuma's first 'info' event before emitting: Kuma registers
  its handlers only after sending it, so an earlier emit is dropped and
  times out now and then.
- configured() needs url, maintenance_id and a token (or username and
  password).

Tested from prod against Kuma 2.5.5: signed in and paused window 7,
which was already paused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-19 21:01:55 -05:00
jared merged commit 54c5fb52c4 into main 2026-11-19 21:01:57 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#54