From f6e5885b47e3ab244b293f4e478af7e520180710 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 22 May 2026 19:32:32 -0500 Subject: refactor(auth): consolidate the auth-source secret lookup into one helper The auth-source-search + funcall-the-secret block was copied four times: calendar-sync--calendar-url, cj/auth-source-secret (ai-config), cj/--auth-source-password (transcription), and cj/slack--get-credential. Each searched authinfo, pulled :secret, and called it when the netrc backend returned a function. I pulled that into cj/auth-source-secret-value in system-lib (a leaf, so calendar-sync doesn't have to depend on ai-config and drag in the gptel stack). It takes an optional user and returns the secret or nil. The four callers now delegate to it: ai-config layers its required-secret error on top, and the others keep their nil-on-miss behavior. With the direct auth-source-search calls gone, I dropped the now-unused (require 'auth-source) from transcription, slack, and calendar-sync. The helper's autoload covers it. The transcription tests that exercise the delegated path stay green, and the primitive and the error wrapper get their own tests. --- modules/calendar-sync.el | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'modules/calendar-sync.el') diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el index 9379b427..4ccb0917 100644 --- a/modules/calendar-sync.el +++ b/modules/calendar-sync.el @@ -71,7 +71,7 @@ (require 'cl-lib) (require 'subr-x) -(require 'auth-source) +(require 'system-lib) ;; provides cj/auth-source-secret-value (leaf; no ai-config dep) (require 'cj-org-text-lib) (defun calendar-sync--log-silently (format-string &rest args) @@ -1509,13 +1509,8 @@ An explicit :url wins. Otherwise :secret-host names an auth-source host whose stored secret is the URL (kept in auth-source because the .ics URL is itself a token)." (or (plist-get calendar :url) - (let ((host (plist-get calendar :secret-host))) - (when host - (let ((secret (plist-get (car (auth-source-search :host host :max 1)) - :secret))) - ;; auth-source's netrc backend returns the secret as a function - (cond ((functionp secret) (funcall secret)) - (secret secret))))))) + (when-let* ((host (plist-get calendar :secret-host))) + (cj/auth-source-secret-value host)))) (defun calendar-sync--sync-calendar-ics (calendar) "Sync a single CALENDAR from its .ics feed asynchronously. -- cgit v1.2.3