From: Filipp Gunbin <fgunbin@fastmail.fm>
To: Robert via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org>
Cc: Robert <rchar@protonmail.com>
Subject: Re: sql and auth-source
Date: Thu, 26 Nov 2020 22:49:05 +0300 [thread overview]
Message-ID: <m2360v6gr2.fsf@fastmail.fm> (raw)
In-Reply-To: <JABOufArUVKaDi8BP-DLqze9A6hDs4evNVMTm8jb1O1DspOXNIm8ENdCvhVe7FuS-B4oT9VHLSBMfK-jrRA9wPVCPBAprXxm7XVmVkc1Dc8=@protonmail.com> (Robert via Users list for the's message of "Thu, 26 Nov 2020 12:46:09 +0000")
On 26/11/2020 12:46 +0000, Robert via Users list for the GNU Emacs text editor wrote:
> Hello,
>
> how to configure the sql mode to work with a wallet file?
> A code example would be very helpful.
>
> I found function sql-auth-source-search-wallet, but i don't know how to use it.
> https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/sql.el#n736
> Help please.
>
> --
> Robert
Generally, (setq sql-password-wallet '("~/my/sql-wallet.gpg")) should be
enough.
But, from what I recently found while investigating how it (not) works
for Postgres, I can tell the following:
The value of sql-password-search-wallet-function is used for searching,
it's usually the function sql-auth-source-search-wallet.
You can test whether it works (like, is able to decrypt gpg and parse) by
something like the following:
(sql-auth-source-search-wallet sql-password-wallet 'postgres "my_user" "localhost" "my_db" 5432)
BUT, sql-connect and friends will actually call the function in
sql-password-search-wallet-function only if sql-postgres-login-params
contains password login parameter, and it doesn't (this can be checked
with (sql-get-product-feature 'postgres :sqli-login)). This is because
the login function, sql-comint-postgres, does not make use of it.
So, for Postgres, this looks like it's yet to be implemented.
Nevertheless, I was able to at least make use of sql-wallet file to
auto-set sql-connection-alist with this code:
(defun fg-dotemacs-get-sql-connections (file)
(mapcar
(lambda (alist)
(let* ((machine (cdr (assoc "machine" alist)))
(machine-list (split-string machine "/"))
(host (nth 0 machine-list))
(database (nth 1 machine-list))
(name (cond ((string= host "localhost")
(concat "local-" database))
((string-match-p "\\.prod$" host)
(concat "prod-" database))
;; more rules...
(t
(concat host "-" database)))))
`(,name
(sql-product (quote ,(intern (cdr (assoc "product" alist)))))
(sql-user ,(cdr (assoc "user" alist)))
(sql-database ,database)
(sql-server ,host)
(sql-port ,(string-to-number (cdr (assoc "port" alist)))))))
(auth-source-netrc-parse
:file file :host t :port t :user t)))
(setq sql-connection-alist
(fg-dotemacs-get-sql-connections (car sql-password-wallet)))
Filipp
next prev parent reply other threads:[~2020-11-26 19:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 12:46 sql and auth-source Robert via Users list for the GNU Emacs text editor
2020-11-26 19:49 ` Filipp Gunbin [this message]
2020-11-27 1:58 ` Jean Louis
2020-11-27 6:52 ` Robert
2020-11-27 7:10 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2360v6gr2.fsf@fastmail.fm \
--to=fgunbin@fastmail.fm \
--cc=help-gnu-emacs@gnu.org \
--cc=rchar@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.