aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/modules/todo.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
committerDanilo M. <danix@danix.xyz>2026-11-30 11:18:32 +0100
commit202995fc8afab753a9e5c441932779c9a5249c96 (patch)
treefe051c09097e965c7e49f1ccebce3c270d34b415 /deckit/modules/todo.py
parent41c503645122f3d2d79ea4a428d6eb72c399c5b5 (diff)
downloaddeck-it-202995fc8afab753a9e5c441932779c9a5249c96.tar.gz
deck-it-202995fc8afab753a9e5c441932779c9a5249c96.zip
feat(todo): read the Vikunja token from pass
[todo] pass names the pass entry holding the API token; it is read once and kept in memory, and read again after Vikunja answers 401. No token file on disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'deckit/modules/todo.py')
-rw-r--r--deckit/modules/todo.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/deckit/modules/todo.py b/deckit/modules/todo.py
index 8abbd23..8ce673d 100644
--- a/deckit/modules/todo.py
+++ b/deckit/modules/todo.py
@@ -18,23 +18,21 @@
Open tasks due today or overdue, or whose reminder has passed; one with a
reminder still ahead is hidden, which is how a snooze works. The token is a
-Vikunja API token (read and update tasks) in ~/.config/deck-it/vikunja-token.
+Vikunja API token (read and update tasks) in pass, entry [todo] pass, read
+once and kept in memory until Vikunja refuses it.
"""
import http.client
import json
-import os
import subprocess
import threading
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime, timedelta, timezone
-from pathlib import Path
from ..module import Module, ModuleError
-TOKEN = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "deck-it" / "vikunja-token"
POLL = 60
SNOOZE = timedelta(minutes=30)
FILTER = "done = false && (due_date < now/d+1d || reminders < now)"
@@ -57,6 +55,17 @@ def _http(method, url, token, data=None):
return json.loads(raw) if raw else {}
+def _pass(entry):
+ """The first line of a pass entry. gpg may ask for the PIN the first time."""
+ try:
+ out = subprocess.run(["pass", "show", entry], capture_output=True, text=True, timeout=120)
+ except subprocess.TimeoutExpired:
+ raise OSError("pass timed out") from None
+ if out.returncode:
+ raise OSError(f"pass show {entry} failed")
+ return out.stdout.partition("\n")[0].strip()
+
+
def _popen(cmd):
subprocess.Popen(cmd, start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@@ -87,10 +96,13 @@ def pick(tasks, now):
class Todo:
def __init__(self, cfg: dict):
- self.url = cfg.get("todo", {}).get("url", "").rstrip("/")
+ tcfg = cfg.get("todo", {})
+ self.url = tcfg.get("url", "").rstrip("/")
+ self.entry = tcfg.get("pass", "")
self.http = cfg.get("http", _http)
self.popen = cfg.get("popen", _popen)
- self.token_path = Path(cfg.get("token", TOKEN))
+ self.pass_ = cfg.get("pass", _pass)
+ self.token = None
self.now = cfg.get("now", lambda: datetime.now(timezone.utc))
self.front = None
self.st = {"tasks": [], "error": None}
@@ -98,8 +110,16 @@ class Todo:
self.actions = {"open": self._open, "done": self._done, "snooze": self._snooze} if self.url else {}
def _call(self, method, path, data=None):
- token = self.token_path.read_text().strip()
- return self.http(method, self.url + path, token, data)
+ if not self.entry:
+ raise OSError("no [todo] pass entry for the token")
+ if self.token is None:
+ self.token = self.pass_(self.entry)
+ try:
+ return self.http(method, self.url + path, self.token, data)
+ except OSError as e:
+ if str(e) == "HTTP 401":
+ self.token = None # revoked or replaced: read pass again next time
+ raise
def refresh(self):
try: