Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Add customizable variable auth-source-pass-port-separator #87

Merged
merged 2 commits into from Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -57,6 +57,9 @@ host (e.g., web and mail), you can add a colon and the port number (or
service name) at the end of the filename: e.g., `host:443.gpg` or
`host:imap.gpg`.

The separator string (default: colon) between host and port number
can be customized by `auth-source-pass-port-separator` variable.

Be aware that the .gpg extension is added automatically by the `pass`
utility. You should not include that in the name when you create the
entry. For example to create a multi-line entry with `pass`:
Expand Down
16 changes: 13 additions & 3 deletions auth-source-pass.el
Expand Up @@ -47,6 +47,10 @@
"Path to the password-store folder."
:type 'directory)

(defcustom auth-source-pass-port-separator ":"
"Separator string between host and port in entry filename."
:type 'string)

(cl-defun auth-source-pass-search (&rest spec
&key backend type host user port
&allow-other-keys)
Expand Down Expand Up @@ -252,9 +256,15 @@ return nil.

HOSTNAME should not contain any username or port number."
(or
(and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user))
(and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user))
(and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil))
(and user port (auth-source-pass--find-one-by-entry-name
(format "%s@%s%s%s" user hostname auth-source-pass-port-separator port)
user))
(and user (auth-source-pass--find-one-by-entry-name
(format "%s@%s" user hostname)
user))
(and port (auth-source-pass--find-one-by-entry-name
(format "%s%s%s" hostname auth-source-pass-port-separator port)
nil))
(auth-source-pass--find-one-by-entry-name hostname user)
;; if that didn't work, remove subdomain: foo.bar.com -> bar.com
(let ((components (split-string hostname "\\.")))
Expand Down
11 changes: 11 additions & 0 deletions test/auth-source-pass-tests.el
Expand Up @@ -186,6 +186,17 @@ This function is intended to be set to `auth-source-debug`."
(should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil)
"host.com"))))

(ert-deftest auth-source-pass-find-host-with-port ()
(auth-source-pass--with-store '(("host.com:443"))
(should (equal (auth-source-pass--find-match "host.com" "someuser" "443")
"host.com:443"))))

(ert-deftest auth-source-pass-find-host-with-custom-port-separator ()
(let ((auth-source-pass-port-separator "#"))
(auth-source-pass--with-store '(("host.com#443"))
(should (equal (auth-source-pass--find-match "host.com" "someuser" "443")
"host.com#443")))))

(defmacro auth-source-pass--with-store-find-foo (store &rest body)
"Use STORE while executing BODY. \"foo\" is the matched entry."
(declare (indent 1))
Expand Down