-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
agama config load
/store
for "software" uses the HTTP API
#1548
Changes from all commits
68f7af5
e21574d
f8b5a68
d3f2e0b
dff2aaa
3c30c5d
9c6ec6b
54d48ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; |
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, it can be improved by decoding body of error response and creating error from it, if it is also service error. I plan to do it, but other higher priorities come in the way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what I thought too, but
|
||
// 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 | ||
} | ||
} |
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>, | ||
} |
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]> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use here
new_with_base
likeOk(Self.new_with_base(BaseHTTPClient::new()?))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point... IMHO my way is still not enough duplication to need the indirection :)