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