-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Problem **Patterns** part of the migration of the CLI from D-Bus API to HTTP API: - https://trello.com/c/hvPtBtMD/3719-5-replace-d-bus-with-http-based-clients ## Solution - Added `SoftwareHTTPClient` - Kept (D-Bus) `SoftwareClient` because it serves as the backend for the above ## Testing - Tested manually, via [`/testing_using_container.sh`](https://github.com/openSUSE/agama/blob/c65497c94ff1a1aa05d0f67a100e980c89e6ebfb/testing_using_container.sh) - Added tests that mock the HTTP API ## Screenshots No
- Loading branch information
Showing
10 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
//! Implements support for handling the software settings | ||
|
||
mod client; | ||
mod http_client; | ||
pub mod model; | ||
pub mod proxies; | ||
mod settings; | ||
mod store; | ||
|
||
pub use client::{Pattern, SelectedBy, SoftwareClient, UnknownSelectedBy}; | ||
pub use http_client::SoftwareHTTPClient; | ||
pub use settings::SoftwareSettings; | ||
pub use store::SoftwareStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::software::model::SoftwareConfig; | ||
use crate::{base_http_client::BaseHTTPClient, error::ServiceError}; | ||
use std::collections::HashMap; | ||
|
||
pub struct SoftwareHTTPClient { | ||
client: BaseHTTPClient, | ||
} | ||
|
||
impl SoftwareHTTPClient { | ||
pub fn new() -> Result<Self, ServiceError> { | ||
Ok(Self { | ||
client: BaseHTTPClient::new()?, | ||
}) | ||
} | ||
|
||
pub fn new_with_base(base: BaseHTTPClient) -> Self { | ||
Self { client: base } | ||
} | ||
|
||
pub async fn get_config(&self) -> Result<SoftwareConfig, ServiceError> { | ||
self.client.get("/software/config").await | ||
} | ||
|
||
pub async fn set_config(&self, config: &SoftwareConfig) -> Result<(), ServiceError> { | ||
// FIXME: test how errors come out: | ||
// unknown pattern name, | ||
// D-Bus client returns | ||
// Err(ServiceError::UnknownPatterns(wrong_patterns)) | ||
// CLI prints: | ||
// Anyhow(Backend call failed with status 400 and text '{"error":"Agama service error: Failed to find these patterns: [\"no_such_pattern\"]"}') | ||
self.client.put_void("/software/config", config).await | ||
} | ||
|
||
/// Returns the ids of patterns selected by user | ||
pub async fn user_selected_patterns(&self) -> Result<Vec<String>, ServiceError> { | ||
// TODO: this way we unnecessarily ask D-Bus (via web.rs) also for the product and then ignore it | ||
let config = self.get_config().await?; | ||
|
||
let Some(patterns_map) = config.patterns else { | ||
return Ok(vec![]); | ||
}; | ||
|
||
let patterns: Vec<String> = patterns_map | ||
.into_iter() | ||
.filter_map(|(name, is_selected)| if is_selected { Some(name) } else { None }) | ||
.collect(); | ||
|
||
Ok(patterns) | ||
} | ||
|
||
/// Selects patterns by user | ||
pub async fn select_patterns( | ||
&self, | ||
patterns: HashMap<String, bool>, | ||
) -> Result<(), ServiceError> { | ||
let config = SoftwareConfig { | ||
product: None, | ||
// TODO: SoftwareStore only passes true bools, false branch is untested | ||
patterns: Some(patterns), | ||
}; | ||
self.set_config(&config).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
/// Software service configuration (product, patterns, etc.). | ||
#[derive(Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct SoftwareConfig { | ||
/// A map where the keys are the pattern names and the values whether to install them or not. | ||
pub patterns: Option<HashMap<String, bool>>, | ||
/// Name of the product to install. | ||
pub product: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
------------------------------------------------------------------- | ||
Mon Aug 26 11:19:27 UTC 2024 - Martin Vidner <[email protected]> | ||
|
||
- For CLI, use HTTP clients instead of D-Bus clients, | ||
for Software (gh#openSUSE/agama#1548) | ||
- added SoftwareHTTPClient | ||
|
||
------------------------------------------------------------------- | ||
Thu Aug 15 08:33:02 UTC 2024 - Josef Reidinger <[email protected]> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters