From 7daf582df58a90d06ab4505f2864ccbf4443ea37 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 15 Jun 2020 19:56:30 +0200 Subject: [PATCH] Query password when executing SQL queries against Oracle databases I don't like to store my passwords in plain in my files. Next step should be to cache the password, but maybe this is already achieved by using a dedicated session? --- init.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/init.el b/init.el index bdfdf63..6a8f669 100644 --- a/init.el +++ b/init.el @@ -1215,6 +1215,28 @@ in the main agenda view." :config (setf (alist-get :results org-babel-default-header-args) "output code replace")) +(use-package ob-sql + :defer t + :config (progn + + (defun db/ob-sql-oracle-ask-for-password (orig-fun + host port user password database) + "Ask for PASSWORD if not given, and call ORIG-FUN with arguments afterwards." + (cond + ((not (or (and user database host port) + (and user database))) + (user-error "Insufficient login credentials given, aborting.")) + (password + (funcall orig-fun host port user password database)) + (t + (funcall orig-fun + host port user + (password-read (format "Password for %s@%s: " user database)) + database)))) + + (advice-add #'org-babel-sql-dbstring-oracle + :around #'db/ob-sql-oracle-ask-for-password))) + ;; Exporting (use-package ox-icalendar