aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-02-18 20:45:47 -0500
committerJesse Luehrs <doy@tozt.net>2023-02-18 20:45:47 -0500
commit5208e99627d596b86e63a15c42b2c9fb473d766c (patch)
tree6915dc8db19b88c4bc99710084e6b484e679623b
parent9d9d5dac7a2e342a35482756ef7c92d045f8f835 (diff)
downloadrbw-5208e99627d596b86e63a15c42b2c9fb473d766c.tar.gz
rbw-5208e99627d596b86e63a15c42b2c9fb473d766c.zip
more refactoring
-rw-r--r--src/actions.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/actions.rs b/src/actions.rs
index ca5e448..dc78f7e 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -1,20 +1,10 @@
use crate::prelude::*;
-fn api_client() -> Result<(crate::api::Client, crate::config::Config)> {
- let config = crate::config::Config::load()?;
- let client = crate::api::Client::new(
- &config.base_url(),
- &config.identity_url(),
- config.client_cert_path(),
- );
- Ok((client, config))
-}
-
pub async fn register(
email: &str,
apikey: crate::locked::ApiKey,
) -> Result<()> {
- let (client, config) = api_client()?;
+ let (client, config) = api_client_async().await?;
client
.register(email, &crate::config::device_id(&config).await?, &apikey)
@@ -29,7 +19,7 @@ pub async fn login(
two_factor_token: Option<&str>,
two_factor_provider: Option<crate::api::TwoFactorProviderType>,
) -> Result<(String, String, u32, String)> {
- let (client, config) = api_client()?;
+ let (client, config) = api_client_async().await?;
let iterations = client.prelogin(email).await?;
let identity =
crate::identity::Identity::new(email, &password, iterations)?;
@@ -126,7 +116,7 @@ async fn sync_once(
std::collections::HashMap<String, String>,
Vec<crate::db::Entry>,
)> {
- let (client, _) = api_client()?;
+ let (client, _) = api_client_async().await?;
client.sync(access_token).await
}
@@ -303,3 +293,24 @@ async fn exchange_refresh_token_async(refresh_token: &str) -> Result<String> {
let (client, _) = api_client()?;
client.exchange_refresh_token_async(refresh_token).await
}
+
+fn api_client() -> Result<(crate::api::Client, crate::config::Config)> {
+ let config = crate::config::Config::load()?;
+ let client = crate::api::Client::new(
+ &config.base_url(),
+ &config.identity_url(),
+ config.client_cert_path(),
+ );
+ Ok((client, config))
+}
+
+async fn api_client_async(
+) -> Result<(crate::api::Client, crate::config::Config)> {
+ let config = crate::config::Config::load_async().await?;
+ let client = crate::api::Client::new(
+ &config.base_url(),
+ &config.identity_url(),
+ config.client_cert_path(),
+ );
+ Ok((client, config))
+}