Revoke special password implementation for SQL Org source blocks
Turns out this can be done by a simple function call, as demonstrated by https://magnus.therning.org/2024-09-01-improving-how-i-handle-secrets-in-my-work-notes.html. So we just extend `org-password-manager-get-password-by-id` accordingly and use that instead. No need to patch the default implementation of Org!
This commit is contained in:
parent
3d38510284
commit
5a25d5d069
17
init.el
17
init.el
@ -1239,22 +1239,7 @@ accordingly."
|
||||
(funcall orig-fun
|
||||
host port user
|
||||
(password-read (format "Password for %s@%s: " user database))
|
||||
database))))
|
||||
|
||||
(define-advice org-babel-execute:sql (:around
|
||||
(orig-fun body params)
|
||||
retrieve-password-by-function)
|
||||
"Allow to set :dbpassword by an ID of an Org items having the PASSWORD property."
|
||||
(let* ((dbpassword-id (cdr (assq :dbpassword-by-id params)))
|
||||
(params params))
|
||||
(when dbpassword-id
|
||||
(setq params (cons (cons :dbpassword
|
||||
(let* ((pom (or (org-id-find dbpassword-id 'marker)
|
||||
(user-error "Cannot find ID %s" dbpassword-id))))
|
||||
(or (org-entry-get pom "PASSWORD")
|
||||
(user-error "No PASSWORD property at ID %s" dbpassword-id))))
|
||||
params)))
|
||||
(funcall orig-fun body params)))))
|
||||
database))))))
|
||||
|
||||
;; Exporting
|
||||
|
||||
|
||||
@ -1164,10 +1164,14 @@ cache if that's in use."
|
||||
(when (derived-mode-p 'org-agenda-mode)
|
||||
(org-agenda-redo)))
|
||||
|
||||
(defun org-password-manager-get-password-by-id (id)
|
||||
(defun org-password-manager-get-password-by-id (id &optional return-as-value)
|
||||
"Retrieve password from Org item identified by ID.
|
||||
|
||||
The password is assumed to be stored at the PASSWORD property."
|
||||
The password is assumed to be stored at the PASSWORD property.
|
||||
When RETURN-AS-VALUE is nil, the password is copied to the
|
||||
clipboard as with `org-password-manager-get-password', which see.
|
||||
Otherwise, the password is returned as value from this function
|
||||
and can be used for further processing."
|
||||
|
||||
(require 'org-password-manager)
|
||||
(let ((pom (org-id-find id 'marker)))
|
||||
@ -1179,13 +1183,15 @@ The password is assumed to be stored at the PASSWORD property."
|
||||
(when (null pw)
|
||||
(user-error "PASSWORD property not set for “%s”" heading))
|
||||
|
||||
(if return-as-value
|
||||
pw
|
||||
(funcall interprogram-cut-function pw)
|
||||
(run-at-time org-password-manager-default-password-wait-time
|
||||
nil
|
||||
(lambda () (funcall interprogram-cut-function "")))
|
||||
(message "Password for “%s” securly copied to system clipboard; will be overwritten in %s."
|
||||
heading
|
||||
org-password-manager-default-password-wait-time))))
|
||||
org-password-manager-default-password-wait-time)))))
|
||||
|
||||
(defhydra hydra-org-jump (:color blue)
|
||||
;; Quote %, as otherwise they would be misinterpreted as format characters
|
||||
|
||||
Loading…
Reference in New Issue
Block a user