Started working on attachment store
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use crate::daemon::SettingsKey;
|
||||
|
||||
use keyring::{Entry, Result};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use keyring::{Entry, Result};
|
||||
|
||||
use kordophone::api::{AuthenticationStore, http_client::Credentials};
|
||||
use kordophone::api::{http_client::Credentials, AuthenticationStore};
|
||||
use kordophone::model::JwtToken;
|
||||
use kordophone_db::database::{Database, DatabaseAccess};
|
||||
|
||||
@@ -25,52 +25,67 @@ impl AuthenticationStore for DatabaseAuthenticationStore {
|
||||
async fn get_credentials(&mut self) -> Option<Credentials> {
|
||||
use keyring::secret_service::SsCredential;
|
||||
|
||||
self.database.lock().await.with_settings(|settings| {
|
||||
let username: Option<String> = settings.get::<String>(SettingsKey::USERNAME)
|
||||
.unwrap_or_else(|e| {
|
||||
log::warn!("error getting username from database: {}", e);
|
||||
None
|
||||
});
|
||||
self.database
|
||||
.lock()
|
||||
.await
|
||||
.with_settings(|settings| {
|
||||
let username: Option<String> = settings
|
||||
.get::<String>(SettingsKey::USERNAME)
|
||||
.unwrap_or_else(|e| {
|
||||
log::warn!("error getting username from database: {}", e);
|
||||
None
|
||||
});
|
||||
|
||||
match username {
|
||||
Some(username) => {
|
||||
let credential = SsCredential::new_with_target(None, "net.buzzert.kordophonecd", &username).unwrap();
|
||||
match username {
|
||||
Some(username) => {
|
||||
let credential = SsCredential::new_with_target(
|
||||
None,
|
||||
"net.buzzert.kordophonecd",
|
||||
&username,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let password: Result<String> = Entry::new_with_credential(Box::new(credential))
|
||||
.get_password();
|
||||
let password: Result<String> =
|
||||
Entry::new_with_credential(Box::new(credential)).get_password();
|
||||
|
||||
log::debug!("password: {:?}", password);
|
||||
|
||||
match password {
|
||||
Ok(password) => Some(Credentials { username, password }),
|
||||
Err(e) => {
|
||||
log::error!("error getting password from keyring: {}", e);
|
||||
None
|
||||
match password {
|
||||
Ok(password) => Some(Credentials { username, password }),
|
||||
Err(e) => {
|
||||
log::error!("error getting password from keyring: {}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}).await
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_token(&mut self) -> Option<String> {
|
||||
self.database.lock().await
|
||||
.with_settings(|settings| {
|
||||
match settings.get::<String>(SettingsKey::TOKEN) {
|
||||
self.database
|
||||
.lock()
|
||||
.await
|
||||
.with_settings(
|
||||
|settings| match settings.get::<String>(SettingsKey::TOKEN) {
|
||||
Ok(token) => token,
|
||||
Err(e) => {
|
||||
log::warn!("Failed to get token from settings: {}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}).await
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn set_token(&mut self, token: String) {
|
||||
self.database.lock().await
|
||||
.with_settings(|settings| settings.put(SettingsKey::TOKEN, &token)).await.unwrap_or_else(|e| {
|
||||
self.database
|
||||
.lock()
|
||||
.await
|
||||
.with_settings(|settings| settings.put(SettingsKey::TOKEN, &token))
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
log::error!("Failed to set token: {}", e);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user