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/system-lib.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'modules/system-lib.el') diff --git a/modules/system-lib.el b/modules/system-lib.el index 96159179..80175958 100644 --- a/modules/system-lib.el +++ b/modules/system-lib.el @@ -106,5 +106,19 @@ This does so without echoing in the minibuffer." (insert (apply #'format format-string args)) (unless (bolp) (insert "\n"))))) +;; ------------------------------ Auth Source ---------------------------------- + +(declare-function auth-source-search "auth-source") + +(defun cj/auth-source-secret-value (host &optional user) + "Return the auth-source secret for HOST, or nil when none is found. +With USER, also match on the login. Resolves a function-valued secret +\(the netrc backend returns the secret as a function\) by calling it. +Callers that must have a secret layer their own error on top." + (let* ((spec (append (list :host host :require '(:secret) :max 1) + (when user (list :user user)))) + (secret (plist-get (car (apply #'auth-source-search spec)) :secret))) + (if (functionp secret) (funcall secret) secret))) + (provide 'system-lib) ;;; system-lib.el ends here -- cgit v1.2.3