From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filipp Gunbin Newsgroups: gmane.emacs.help Subject: Re: sql and auth-source Date: Thu, 26 Nov 2020 22:49:05 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14292"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) Cc: Robert To: Robert via Users list for the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 26 20:49:42 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiNGw-0003cL-8v for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 26 Nov 2020 20:49:42 +0100 Original-Received: from localhost ([::1]:43932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kiNGv-0001b6-B1 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 26 Nov 2020 14:49:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiNGS-0001ag-7r for help-gnu-emacs@gnu.org; Thu, 26 Nov 2020 14:49:12 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:49921) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiNGQ-0004Lo-AO for help-gnu-emacs@gnu.org; Thu, 26 Nov 2020 14:49:11 -0500 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6BA6B5C017F; Thu, 26 Nov 2020 14:49:08 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 26 Nov 2020 14:49:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=fm1; bh=0sGj9XAWmAhYFB2iO6XJTiKxq/ dJmzl0yUbpxEG9dPk=; b=daA/Tx3LDV5JYJyDPBR+HVMH/gBDCZYf75JG2Tw6RW Po9cCkIANMJupSIWm17QiJE8XxEb4EonBIZ3tcBWg9i2+hn1x7i4qj/huci+Mh08 OGm1Ayj/0Jv1vWsgkC1g5jZiuve0r2iIAEZqr+EbdYKjdv30ImuDPJ7Du9L4Kai+ MbBuexXWJC1TF93BdHAEfP3G33khg3wNrEr0u9PoWf7GonAALjhJZ6FjRqokKR23 QdryNt+RmSrjIgeuzInFYfu3q1T85hDn+Qv3xez9y0+pgEugUxRa2m1BzHSZRm9G MfQi6QYi8RHgmZIQrqCjWYmyPTVEfQ1taXd0IHLiOKxw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=0sGj9X AWmAhYFB2iO6XJTiKxq/dJmzl0yUbpxEG9dPk=; b=rtfX9GJkIgavWqPf98ooop fif/78Ns3z5ub+oWmvw3A0QHPK/4HtEk52BHCfTrBCuTzr6khhpOwwVetJaSfC6i o6YC4qPa6bqmlSOfP/uOY5qguRmWpiIXmvKyV5SObwtEN+DSlRg1k8gkLp9n5+yk 3VxhWBfr9PtRqtVyu58Z7fjAWY0zXy1jO8zG1j/kyUrMaDEKrDtHtsg0ILsVW/1b zb36U0bYAyXMzWLPdorBR0r5u5OD0Ut4rXqrPiJbybBl9AFMLeyq6BH6ehwMUjvi XPkfeplkY81JkKCyTERhu91fBys/NaRV66M9/63q9y0LhfMRkE0oYCm4wYkZEzrg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudehvddgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffujghffgffkfggtgesthdtredttdertdenucfhrhhomhephfhilhhi phhpucfiuhhnsghinhcuoehfghhunhgsihhnsehfrghsthhmrghilhdrfhhmqeenucggtf frrghtthgvrhhnpedtffehgfffjedtvddvheeuteehieehgedugefhgfeutefgvdefuedu hfefudevieenucffohhmrghinhepghhnuhdrohhrghenucfkphepkeegrddvtdegrddule efrddutdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepfhhguhhnsghinhesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: from fgunbin.local (unknown [84.204.193.106]) by mail.messagingengine.com (Postfix) with ESMTPA id 6833F3280064; Thu, 26 Nov 2020 14:49:07 -0500 (EST) In-Reply-To: (Robert via Users list for the's message of "Thu, 26 Nov 2020 12:46:09 +0000") Mail-Followup-To: Robert via Users list for the GNU Emacs text editor , Robert Received-SPF: pass client-ip=66.111.4.25; envelope-from=fgunbin@fastmail.fm; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:125583 Archived-At: 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