From 64286ce759b52300d5050c7c73e9bba651b326cb Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Thu, 4 Jan 2024 22:41:33 +0100 Subject: [PATCH] Add api key to flatpak up --- cmd/config.go | 8 ++++---- ui/goldwarden.py | 12 ++++++++++++ ui/settings.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index db25b28..8867833 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -107,9 +107,9 @@ var setNotificationsURLCmd = &cobra.Command{ } var setApiClientIDCmd = &cobra.Command{ - Use: "set-api-client-id", - Short: "Set the api client id", - Long: `Set the api client id.`, + Use: "set-client-id", + Short: "Set the client id", + Long: `Set the client id.`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { return @@ -140,7 +140,7 @@ var setApiClientIDCmd = &cobra.Command{ } var setApiSecretCmd = &cobra.Command{ - Use: "set-api-client-secret", + Use: "set-client-secret", Short: "Set the api secret", Long: `Set the api secret.`, Run: func(cmd *cobra.Command, args []string) { diff --git a/ui/goldwarden.py b/ui/goldwarden.py index b78c97b..dd3b638 100644 --- a/ui/goldwarden.py +++ b/ui/goldwarden.py @@ -27,6 +27,18 @@ def set_notification_url(url): if result.returncode != 0: raise Exception("Failed to initialize repository, err", result.stderr) +def set_client_id(client_id): + restic_cmd = f"{BINARY_PATH} config set-client-id {client_id}" + result = subprocess.run(restic_cmd.split(), capture_output=True, text=True) + if result.returncode != 0: + raise Exception("Failed err", result.stderr) + +def set_client_secret(client_secret): + restic_cmd = f"{BINARY_PATH} config set-client-secret {client_secret}" + result = subprocess.run(restic_cmd.split(), capture_output=True, text=True) + if result.returncode != 0: + raise Exception("Failed err", result.stderr) + def login_with_password(email, password): restic_cmd = f"{BINARY_PATH} vault login --email {email}" result = subprocess.run(restic_cmd.split(), capture_output=True, text=True) diff --git a/ui/settings.py b/ui/settings.py index bc45e43..90c42ee 100644 --- a/ui/settings.py +++ b/ui/settings.py @@ -282,6 +282,16 @@ def show_login(): email_entry.set_text("") auth_preference_group.add(email_entry) + client_id_entry = Adw.EntryRow() + client_id_entry.set_title("Client ID (optional)") + client_id_entry.set_text("") + auth_preference_group.add(client_id_entry) + + client_secret_entry = Adw.EntryRow() + client_secret_entry.set_title("Client Secret (optional)") + client_secret_entry.set_text("") + auth_preference_group.add(client_secret_entry) + dialog.add_button("Login", Gtk.ResponseType.OK) def on_save(res): if res != Gtk.ResponseType.OK: @@ -289,6 +299,8 @@ def show_login(): goldwarden.set_api_url(api_url_entry.get_text()) goldwarden.set_identity_url(identity_url_entry.get_text()) goldwarden.set_notification_url(notification_url_entry.get_text()) + goldwarden.set_client_id(client_id_entry.get_text()) + goldwarden.set_client_secret(client_secret_entry.get_text()) def login(): res = goldwarden.login_with_password(email_entry.get_text(), "password") def handle_res():