Add remaining server settings, simplify config infix declaration

Add support for custom URLs available through `bw config server`

Simplify reading and setting an option through a DWIM function.
This commit is contained in:
Lucien Cartier-Tilet 2022-03-16 20:20:26 +01:00
parent 3e2d16ad64
commit f1a5d7f125
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -125,6 +125,35 @@ The exit status of the command is stored in
" ")
(cl-defun bitwarden--dwim-config-url (&key option (value nil))
"Get the servers url for OPTION or set it to VALUE.
If OPTION is nil, then return the base URL for the server. OPTION
values can be one of the accepted options by the command `bw
config server' minus the two preceding dashes (for instance
\"api\" instead of \"--api\")."
(let ((output-str (cond
((and value
(bitwarden--run-cli "config"
(concat "--" option)
(bitwarden--quote-string value)))
((and value
(null option))
(bitwarden--run-cli "config"
(bitwarden--quote-string value)))
((and option
(null value))
(bitwarden--run-cli "config"
(concat "--" option)))
(bitwarden--run-cli "config" "server")))))
(if (eq 0 bitwarden--shell-status)
(string-trim output-str "https?://")
(defun bitwarden-dummy ()
"Dummy function."
@ -160,14 +189,66 @@ This macro is largely copied from Tecosaurs screenshot.el"
"-s" "config-server" "On-premises hosted installation URL"
'string "0.1.0"
(let ((output-str (bitwarden--run-cli "config" "server")))
(if (eq 0 bitwarden--shell-status)
(string-trim output-str "https?://")
(let ((server (read-string "Server URL: ")))
(bitwarden--run-cli "config" "server" server)
(bitwarden--dwim-config-url :value server)
"-a" "config-api" "Custom API URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "api")
(let ((api-url (read-string "Server API URL: ")))
(bitwarden--dwim-config-url :option "api" :value server)
"-w" "config-web-vault" "Custom web vault URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "web-vault")
(let ((webvault-url (read-string "Server web-vault URL: ")))
(bitwarden--dwim-config-url :option "web-vault" :value webvault-url)))
"-I" "config-identify" "Custom identity URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "identity")
(let ((identity-url (read-string "Server identity URL: ")))
(bitwarden--dwim-config-url :option "identity" :value identity-url)
"-i" "config-icons" "Custom icons service URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "icons")
(let ((icons-url (read-string "Icons service URL: ")))
(bitwarden--dwim-config-url :option "icons" :value icons-url)
"-n" "config-notifications" "Custom notifications URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "notifications")
(let ((notifications-url (read-string "Notifications URL: ")))
(bitwarden--dwim-config-url :option "notifications" :value notifications-url)
"-e" "config-events" "Custom events URL."
'string "0.1.0"
(bitwarden--dwim-config-url :option "events")
(let ((events-url (read-string "Events URL: ")))
(bitwarden--dwim-config-url :option "events" :value events-url)
"-k" "config-key-connector" "Custom URLfor your Key Connector server."
'string "0.1.0"
(bitwarden--dwim-config-url :option "key-connector")
(let ((key-connector-url (read-string "Key Connector URL: ")))
(bitwarden--dwim-config-url :option "key-connector" :value key-connector-url)
;; Login
@ -302,7 +383,14 @@ This function is meant to be called by a transient.")
;;; Transient Prefixes
(transient-define-prefix bitwarden-config ()
("q" "Quit" bitwarden--action-config-quit)]