Fix inherited transients in actions, quote passwords by default

This commit is contained in:
Lucien Cartier-Tilet 2022-03-02 20:03:01 +01:00
parent a949544779
commit dd1a740350
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 19 additions and 28 deletions

View File

@ -244,18 +244,19 @@ By order of preference, retrieve the password from the user if
designated by the variable `bitwarden--login-passwordenv', by the designated by the variable `bitwarden--login-passwordenv', by the
file designated by the variable `bitwarden--login-passwordfile', file designated by the variable `bitwarden--login-passwordfile',
or from the authinfo source." or from the authinfo source."
(cond (bitwarden--quote-string
(bitwarden--login-password (cond
(read-passwd "Bitwarden Password: ")) (bitwarden--login-password
((not (bitwarden--empty-or-nil bitwarden--login-passwordenv)) (read-passwd "Bitwarden Password: "))
`("--passwordenv" ,bitwarden--login-passwordenv)) ((not (bitwarden--empty-or-nil bitwarden--login-passwordenv))
((not (bitwarden--empty-or-nil bitwarden--login-passwordfile)) `("--passwordenv" ,bitwarden--login-passwordenv))
`("--passwordfile" ,bitwarden--login-passwordfile)) ((not (bitwarden--empty-or-nil bitwarden--login-passwordfile))
(t (funcall `("--passwordfile" ,bitwarden--login-passwordfile))
(plist-get (t (funcall
(car (auth-source-search :max 1 (plist-get
:host bitwarden--config-server)) (car (auth-source-search :max 1
:secret))))) :host bitwarden--config-server))
:secret))))))
;;; Transient Actions ;;; Transient Actions
@ -276,13 +277,13 @@ This function is meant to be called by a transient.")
(bitwarden--def-action (bitwarden--def-action
"set-server" "set-server"
"Set the Bitwarden server." "Set the Bitwarden server."
'bitwarden--login-server 'bitwarden-config
(bitwarden--run-cli "config" "server" bitwarden--config-server)) (bitwarden--run-cli "config" "server" bitwarden--config-server))
(bitwarden--def-action (bitwarden--def-action
"get-server" "get-server"
"Get the URL of the on-premises hosted installation." "Get the URL of the on-premises hosted installation."
'bitwarden--config-server 'bitwarden-config
(bitwarden--run-cli "config" "server")) (bitwarden--run-cli "config" "server"))
;; Login ;; Login
@ -290,27 +291,17 @@ This function is meant to be called by a transient.")
(bitwarden--def-action (bitwarden--def-action
"login" "login"
"Log in Bitwarden." "Log in Bitwarden."
'bitwarden--login 'bitwarden-login
(if bitwarden--login-sso (if bitwarden--login-sso
(bitwarden--run-cli "login" "--raw" "--sso") (bitwarden--run-cli "login" "--raw" "--sso")
(bitwarden--run-cli "login" "--raw" (bitwarden--run-cli "login" "--raw"
(format "\"%s\"" (bitwarden--get-username)) (format "'%s'" (bitwarden--get-username))
(cond (bitwarden--get-password))))
((not (bitwarden--empty-or-nil bitwarden--login-password))
(bitwarden--quote-string bitwarden--login-password))
((not (bitwarden--empty-or-nil bitwarden--login-passwordenv))
`("--passwordenv" ,(bitwarden--quote-string bitwarden--login-passwordenv)))
((not (bitwarden--empty-or-nil bitwarden--login-passwordfile))
`("--paswordfile" ,(bitwarden--quote-string bitwarden--login-passwordfile)))
(t
(funcall (plist-get (car (auth-source-search :max 1
:host bitwarden--config-server))
:secret)))))))
(bitwarden--def-action (bitwarden--def-action
"logout" "logout"
"Log out of Bitwarden." "Log out of Bitwarden."
'bitwarden--login 'bitwarden-login
(shell-command (concat bitwarden-cli-executable " logout")))) (shell-command (concat bitwarden-cli-executable " logout"))))