[fractal/not-so-secret: 11/13] passwd: improve token storage error handling




commit 1f6ea3bac6bbc52620c05284bf8a2e433fe2b69a
Author: Alexandre Franke <afranke gnome org>
Date:   Mon Jan 4 09:20:24 2021 +0100

    passwd: improve token storage error handling

 fractal-gtk/src/appop/login.rs | 9 ++++++---
 fractal-gtk/src/passwd.rs      | 8 ++++----
 2 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index d1bf5cc4..8f86a709 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -14,6 +14,7 @@ use crate::cache;
 use crate::client::get_matrix_client;
 
 use crate::passwd::PasswordStorage;
+use secret_service::SsError;
 
 use crate::actions::AppState;
 
@@ -28,9 +29,11 @@ impl AppOp {
         server_url: Url,
         identity_url: Box<ServerName>,
     ) {
-        if self.store_token(uid.clone(), access_token.clone()).is_err() {
-            error!("Can't store the token using libsecret");
-        }
+        match self.store_token(uid.clone(), access_token.clone()) {
+            Err(SsError::Locked) => error!("Can’t store the token, keyring is locked."),
+            Err(SsError::Dbus(_)) => error!("Can’t store the token, no Secret Service available."),
+            _ => (),
+        };
 
         let matrix_client =
             get_matrix_client(server_url).expect("Failed to login with the Matrix client");
diff --git a/fractal-gtk/src/passwd.rs b/fractal-gtk/src/passwd.rs
index caadcf00..995aa3e0 100644
--- a/fractal-gtk/src/passwd.rs
+++ b/fractal-gtk/src/passwd.rs
@@ -29,7 +29,7 @@ impl From<IdError> for Error {
 }
 
 pub trait PasswordStorage {
-    fn delete_pass(&self, key: &str) -> Result<(), Error> {
+    fn delete_pass(&self, key: &str) -> Result<(), secret_service::SsError> {
         ss_storage::delete_pass(key)
     }
 
@@ -47,7 +47,7 @@ pub trait PasswordStorage {
         ss_storage::get_pass()
     }
 
-    fn store_token(&self, uid: UserId, token: AccessToken) -> Result<(), Error> {
+    fn store_token(&self, uid: UserId, token: AccessToken) -> Result<(), secret_service::SsError> {
         ss_storage::store_token(uid, token)
     }
 
@@ -67,7 +67,7 @@ mod ss_storage {
 
     use crate::globals;
 
-    pub fn delete_pass(key: &str) -> Result<(), Error> {
+    pub fn delete_pass(key: &str) -> Result<(), secret_service::SsError> {
         let ss = SecretService::new(EncryptionType::Dh)?;
         let collection = get_default_collection_unlocked(&ss)?;
 
@@ -84,7 +84,7 @@ mod ss_storage {
         Ok(())
     }
 
-    pub fn store_token(uid: UserId, token: AccessToken) -> Result<(), Error> {
+    pub fn store_token(uid: UserId, token: AccessToken) -> Result<(), SsError> {
         let ss = SecretService::new(EncryptionType::Dh)?;
         let collection = get_default_collection_unlocked(&ss)?;
         let key = "fractal-token";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]