[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sql and auth-source

From: Filipp Gunbin
Subject: Re: sql and auth-source
Date: Thu, 26 Nov 2020 22:49:05 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin)

On 26/11/2020 12:46 +0000, Robert via Users list for the GNU Emacs text editor 

> 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.
> Help please.
> --
> Robert

Generally, (setq sql-password-wallet '("~/my/sql-wallet.gpg")) should be

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)
   (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...
                         (concat host "-" database)))))
         (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)))))))
    :file file :host t :port t :user t)))

(setq sql-connection-alist
      (fg-dotemacs-get-sql-connections (car sql-password-wallet)))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]