Add default-server ntfy auth (fix 403 on protected topics)
build-and-push / docker (push) Has been cancelled

The "send test" action, admin alerts and feeds without their own
credentials now use configurable default-server token / basic auth,
so publishing works against ntfy servers with access control enabled.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dimon
2026-06-02 21:47:12 +08:00
parent bf52bc3079
commit e696537fe1
7 changed files with 50 additions and 3 deletions
+12 -3
View File
@@ -95,6 +95,12 @@ async def dispatch(feed: Feed, settings: Settings, msg: Message) -> DispatchResu
server = feed.ntfy_server.strip() or settings.default_ntfy_server
full_title = f"{msg.source}: {msg.title}" if msg.source else msg.title
# Per-feed auth wins; otherwise fall back to the default-server credentials.
has_feed_auth = bool(feed.ntfy_token.strip() or feed.ntfy_username.strip())
token = feed.ntfy_token if has_feed_auth else settings.default_ntfy_token
username = feed.ntfy_username if has_feed_auth else settings.default_ntfy_username
password = feed.ntfy_password if has_feed_auth else settings.default_ntfy_password
# --- ntfy (default channel; requires a topic) ---
if feed.ntfy_topic.strip():
try:
@@ -107,9 +113,9 @@ async def dispatch(feed: Feed, settings: Settings, msg: Message) -> DispatchResu
tags=feed.tags,
priority=feed.priority,
attach=msg.image if feed.attach_image else "",
token=feed.ntfy_token,
username=feed.ntfy_username,
password=feed.ntfy_password,
token=token,
username=username,
password=password,
)
result.channels.append("ntfy")
except Exception as exc: # noqa: BLE001
@@ -146,6 +152,9 @@ async def send_admin_alert(settings: Settings, text: str) -> None:
message=text,
tags="warning",
priority=4,
token=settings.default_ntfy_token,
username=settings.default_ntfy_username,
password=settings.default_ntfy_password,
)
except Exception as exc: # noqa: BLE001
log.warning("admin alert failed: %s", exc)