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
1 changed files with 94 additions and 6 deletions

View File

@ -125,6 +125,35 @@ The exit status of the command is stored in
" ")
'bitwarden--shell-status))
(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
option)
(bitwarden--run-cli "config"
"server"
(concat "--" option)
(bitwarden--quote-string value)))
((and value
(null option))
(bitwarden--run-cli "config"
"server"
(bitwarden--quote-string value)))
((and option
(null value))
(bitwarden--run-cli "config"
"server"
(concat "--" option)))
(t
(bitwarden--run-cli "config" "server")))))
(if (eq 0 bitwarden--shell-status)
(string-trim output-str "https?://")
"")))
(defun bitwarden-dummy ()
"Dummy function."
(interactive)
@ -160,14 +189,66 @@ This macro is largely copied from Tecosaurs screenshot.el"
(bitwarden--define-infix
"-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?://")
""))
(bitwarden--dwim-config-url)
(let ((server (read-string "Server URL: ")))
(bitwarden--run-cli "config" "server" server)
(bitwarden--dwim-config-url :value server)
server))
(bitwarden--define-infix
"-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)
server))
(bitwarden--define-infix
"-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)))
(bitwarden--define-infix
"-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)
identity-url))
(bitwarden--define-infix
"-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)
icons-url))
(bitwarden--define-infix
"-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)
notifications-url))
(bitwarden--define-infix
"-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)
events-url))
(bitwarden--define-infix
"-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)
key-connector-url))
;; Login
(bitwarden--define-infix
@ -302,7 +383,14 @@ This function is meant to be called by a transient.")
;;; Transient Prefixes
(transient-define-prefix bitwarden-config ()
["Options"
(bitwarden--set-config-server)]
(bitwarden--set-config-server)
(bitwarden--set-config-api)
(bitwarden--set-config-web-vault)
(bitwarden--set-config-identify)
(bitwarden--set-config-icons)
(bitwarden--set-config-notifications)
(bitwarden--set-config-events)
(bitwarden--set-config-key-connector)]
["Actions"
("q" "Quit" bitwarden--action-config-quit)]
(interactive)