Skip to content

Commit

Permalink
Added code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 7, 2024
1 parent af48057 commit 97d655e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
5 changes: 0 additions & 5 deletions rust/agama-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -52,16 +50,13 @@ pub async fn connection() -> Result<zbus::Connection, ServiceError> {
}

pub fn http_client(token: String) -> Result<reqwest::Client, ServiceError> {
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()))?;

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()))?;
Expand Down
6 changes: 1 addition & 5 deletions rust/agama-lib/src/network/client.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
8 changes: 5 additions & 3 deletions rust/agama-lib/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -26,11 +25,14 @@ pub struct Store<'a> {
}

impl<'a> Store<'a> {
pub async fn new(connection: Connection, client: Client) -> Result<Store<'a>, ServiceError> {
pub async fn new(
connection: Connection,
http_client: reqwest::Client,
) -> Result<Store<'a>, 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?,
Expand Down

0 comments on commit 97d655e

Please sign in to comment.