From 97d655e9bb9022237d5ff1bc9c23d48063b92bd8 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Tue, 7 May 2024 15:43:48 +0100 Subject: [PATCH] Added code review suggestions --- rust/agama-lib/src/lib.rs | 5 ----- rust/agama-lib/src/network/client.rs | 6 +----- rust/agama-lib/src/store.rs | 8 +++++--- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/rust/agama-lib/src/lib.rs b/rust/agama-lib/src/lib.rs index 0309cd9e70..a104dce55f 100644 --- a/rust/agama-lib/src/lib.rs +++ b/rust/agama-lib/src/lib.rs @@ -41,9 +41,7 @@ mod store; pub use store::Store; pub mod questions; use crate::error::ServiceError; -use reqwest::cookie::Jar; use reqwest::{header, Client}; -use std::sync::Arc; const ADDRESS: &str = "unix:path=/run/agama/bus"; @@ -52,7 +50,6 @@ pub async fn connection() -> Result { } pub fn http_client(token: String) -> Result { - let cookie_store = Arc::new(Jar::default()); let mut headers = header::HeaderMap::new(); let value = header::HeaderValue::from_str(format!("Bearer {}", token).as_str()) .map_err(|e| ServiceError::NetworkClientError(e.to_string()))?; @@ -60,8 +57,6 @@ pub fn http_client(token: String) -> Result { headers.insert(header::AUTHORIZATION, value); let client = Client::builder() - .cookie_store(true) - .cookie_provider(cookie_store.clone()) .default_headers(headers) .build() .map_err(|e| ServiceError::NetworkClientError(e.to_string()))?; diff --git a/rust/agama-lib/src/network/client.rs b/rust/agama-lib/src/network/client.rs index 113ac20110..20f4f7930b 100644 --- a/rust/agama-lib/src/network/client.rs +++ b/rust/agama-lib/src/network/client.rs @@ -1,12 +1,8 @@ use super::settings::{BondSettings, MatchSettings, NetworkConnection, WirelessSettings}; use super::types::{Device, DeviceState, DeviceType, SSID}; use crate::error::ServiceError; -use reqwest::cookie::CookieStore; -use reqwest::{header, ClientBuilder}; -use reqwest::{Client, Error, Response}; +use reqwest::{Client, Response}; use serde_json; -use std::collections::HashMap; -use tokio_stream::StreamExt; const API_URL: &str = "http://localhost:3000/api/network"; diff --git a/rust/agama-lib/src/store.rs b/rust/agama-lib/src/store.rs index 26ad36325d..9ff30b8ea6 100644 --- a/rust/agama-lib/src/store.rs +++ b/rust/agama-lib/src/store.rs @@ -7,7 +7,6 @@ use crate::{ localization::LocalizationStore, network::NetworkStore, product::ProductStore, software::SoftwareStore, storage::StorageStore, users::UsersStore, }; -use reqwest::Client; use zbus::Connection; /// Struct that loads/stores the settings from/to the D-Bus services. @@ -26,11 +25,14 @@ pub struct Store<'a> { } impl<'a> Store<'a> { - pub async fn new(connection: Connection, client: Client) -> Result, ServiceError> { + pub async fn new( + connection: Connection, + http_client: reqwest::Client, + ) -> Result, ServiceError> { Ok(Self { localization: LocalizationStore::new(connection.clone()).await?, users: UsersStore::new(connection.clone()).await?, - network: NetworkStore::new(client).await?, + network: NetworkStore::new(http_client).await?, product: ProductStore::new(connection.clone()).await?, software: SoftwareStore::new(connection.clone()).await?, storage: StorageStore::new(connection).await?,