Skip to content

Commit 531c66b

Browse files
committed
Add config to api
1 parent 1f85b82 commit 531c66b

File tree

10 files changed

+108
-105
lines changed

10 files changed

+108
-105
lines changed

rust/agama-lib/src/install_settings.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::{
3333
network::NetworkSettings, product::ProductSettings, scripts::ScriptsConfig,
3434
software::SoftwareSettings, storage::settings::dasd::DASDConfig, users::UserSettings,
3535
};
36-
use agama_utils::api;
3736
use fluent_uri::Uri;
3837
use serde::{Deserialize, Serialize};
3938
use serde_json::value::RawValue;
@@ -86,8 +85,6 @@ pub struct InstallSettings {
8685
#[serde(skip_serializing_if = "Option::is_none")]
8786
pub network: Option<NetworkSettings>,
8887
#[serde(skip_serializing_if = "Option::is_none")]
89-
pub localization: Option<api::l10n::Config>,
90-
#[serde(skip_serializing_if = "Option::is_none")]
9188
pub scripts: Option<ScriptsConfig>,
9289
#[serde(skip_serializing_if = "Option::is_none")]
9390
pub zfcp: Option<ZFCPConfig>,

rust/agama-manager/src/message.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
// To contact SUSE LLC about this file by physical or electronic mail, you may
1919
// find current contact information at www.suse.com.
2020

21-
use agama_lib::install_settings::InstallSettings;
2221
use agama_utils::actor::Message;
23-
use agama_utils::api::{Action, Proposal, Scope, Status, SystemInfo};
22+
use agama_utils::api::{Action, Config, Proposal, Scope, Status, SystemInfo};
2423
use agama_utils::issue::Issue;
2524
use std::collections::HashMap;
2625

@@ -46,25 +45,25 @@ impl Message for GetSystem {
4645
pub struct GetExtendedConfig;
4746

4847
impl Message for GetExtendedConfig {
49-
type Reply = InstallSettings;
48+
type Reply = Config;
5049
}
5150

5251
/// Gets the current config set by the user.
5352
#[derive(Debug)]
5453
pub struct GetConfig;
5554

5655
impl Message for GetConfig {
57-
type Reply = InstallSettings;
56+
type Reply = Config;
5857
}
5958

6059
/// Replaces the config.
6160
#[derive(Debug)]
6261
pub struct SetConfig {
63-
pub config: InstallSettings,
62+
pub config: Config,
6463
}
6564

6665
impl SetConfig {
67-
pub fn new(config: InstallSettings) -> Self {
66+
pub fn new(config: Config) -> Self {
6867
Self { config }
6968
}
7069
}
@@ -76,11 +75,11 @@ impl Message for SetConfig {
7675
/// Updates the config.
7776
#[derive(Debug)]
7877
pub struct UpdateConfig {
79-
pub config: InstallSettings,
78+
pub config: Config,
8079
}
8180

8281
impl UpdateConfig {
83-
pub fn new(config: InstallSettings) -> Self {
82+
pub fn new(config: Config) -> Self {
8483
Self { config }
8584
}
8685
}

rust/agama-manager/src/service.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
use crate::l10n;
2222
use crate::message;
23-
use agama_lib::install_settings::InstallSettings;
2423
use agama_utils::actor::{self, Actor, Handler, MessageHandler};
24+
use agama_utils::api::event;
2525
use agama_utils::api::status::State;
26-
use agama_utils::api::{event, Action, Event, Proposal, Scope, Status, SystemInfo};
26+
use agama_utils::api::{Action, Config, Event, Proposal, Scope, Status, SystemInfo};
2727
use agama_utils::issue;
2828
use agama_utils::progress;
2929
use async_trait::async_trait;
@@ -52,7 +52,7 @@ pub struct Service {
5252
issues: Handler<issue::Service>,
5353
progress: Handler<progress::Service>,
5454
state: State,
55-
config: InstallSettings,
55+
config: Config,
5656
events: event::Sender,
5757
}
5858

@@ -69,7 +69,7 @@ impl Service {
6969
progress,
7070
events,
7171
state: State::Configuring,
72-
config: InstallSettings::default(),
72+
config: Config::default(),
7373
}
7474
}
7575

@@ -125,13 +125,10 @@ impl MessageHandler<message::GetExtendedConfig> for Service {
125125
/// Gets the current configuration.
126126
///
127127
/// It includes user and default values.
128-
async fn handle(
129-
&mut self,
130-
_message: message::GetExtendedConfig,
131-
) -> Result<InstallSettings, Error> {
132-
let l10n_config = self.l10n.call(l10n::message::GetConfig).await?;
133-
Ok(InstallSettings {
134-
localization: Some(l10n_config),
128+
async fn handle(&mut self, _message: message::GetExtendedConfig) -> Result<Config, Error> {
129+
let l10n = self.l10n.call(l10n::message::GetConfig).await?;
130+
Ok(Config {
131+
l10n: Some(l10n),
135132
..Default::default()
136133
})
137134
}
@@ -142,7 +139,7 @@ impl MessageHandler<message::GetConfig> for Service {
142139
/// Gets the current configuration set by the user.
143140
///
144141
/// It includes only the values that were set by the user.
145-
async fn handle(&mut self, _message: message::GetConfig) -> Result<InstallSettings, Error> {
142+
async fn handle(&mut self, _message: message::GetConfig) -> Result<Config, Error> {
146143
Ok(self.config.clone())
147144
}
148145
}
@@ -157,9 +154,9 @@ impl MessageHandler<message::SetConfig> for Service {
157154
/// FIXME: We should replace not given sections with the default ones.
158155
/// After all, now we have config/user/:scope URLs.
159156
async fn handle(&mut self, message: message::SetConfig) -> Result<(), Error> {
160-
if let Some(l10n_config) = &message.config.localization {
157+
if let Some(l10n) = &message.config.l10n {
161158
self.l10n
162-
.call(l10n::message::SetConfig::new(l10n_config.clone()))
159+
.call(l10n::message::SetConfig::new(l10n.clone()))
163160
.await?;
164161
}
165162
self.config = message.config;

rust/agama-manager/src/start.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ pub async fn start(
6363

6464
#[cfg(test)]
6565
mod test {
66+
use crate as manager;
6667
use crate::message;
6768
use crate::service::Service;
68-
use crate::{self as manager};
69-
use agama_lib::install_settings::InstallSettings;
7069
use agama_utils::actor::Handler;
71-
use agama_utils::api;
72-
use agama_utils::api::Event;
70+
use agama_utils::api::l10n;
71+
use agama_utils::api::{Config, Event};
7372
use tokio::sync::broadcast;
7473

7574
async fn start_service() -> Handler<Service> {
@@ -89,13 +88,12 @@ mod test {
8988
async fn test_update_config() -> Result<(), Box<dyn std::error::Error>> {
9089
let handler = start_service().await;
9190

92-
let input_config = InstallSettings {
93-
localization: Some(api::l10n::Config {
91+
let input_config = Config {
92+
l10n: Some(l10n::Config {
9493
locale: Some("es_ES.UTF-8".to_string()),
9594
keymap: Some("es".to_string()),
9695
timezone: Some("Atlantic/Canary".to_string()),
9796
}),
98-
..Default::default()
9997
};
10098

10199
handler
@@ -104,10 +102,7 @@ mod test {
104102

105103
let config = handler.call(message::GetConfig).await?;
106104

107-
assert_eq!(
108-
input_config.localization.unwrap(),
109-
config.localization.unwrap()
110-
);
105+
assert_eq!(input_config.l10n.unwrap(), config.l10n.unwrap());
111106

112107
Ok(())
113108
}
@@ -119,18 +114,17 @@ mod test {
119114

120115
// Ensure the keymap is different to the system one.
121116
let config = handler.call(message::GetExtendedConfig).await?;
122-
let keymap = if config.localization.unwrap().keymap.unwrap() == "es" {
117+
let keymap = if config.l10n.unwrap().keymap.unwrap() == "es" {
123118
"en"
124119
} else {
125120
"es"
126121
};
127122

128-
let input_config = InstallSettings {
129-
localization: Some(api::l10n::Config {
123+
let input_config = Config {
124+
l10n: Some(l10n::Config {
130125
keymap: Some(keymap.to_string()),
131126
..Default::default()
132127
}),
133-
..Default::default()
134128
};
135129

136130
handler
@@ -139,13 +133,10 @@ mod test {
139133

140134
let config = handler.call(message::GetConfig).await?;
141135

142-
assert_eq!(
143-
input_config.localization.unwrap(),
144-
config.localization.unwrap()
145-
);
136+
assert_eq!(input_config.l10n.unwrap(), config.l10n.unwrap());
146137

147138
let extended_config = handler.call(message::GetExtendedConfig).await?;
148-
let l10n_config = extended_config.localization.unwrap();
139+
let l10n_config = extended_config.l10n.unwrap();
149140

150141
assert!(l10n_config.locale.is_some());
151142
assert!(l10n_config.keymap.is_some());

rust/agama-server/src/server/types.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
//! This module defines some ancillary types for the HTTP API.
2222
23-
use agama_lib::install_settings::InstallSettings;
2423
use agama_utils::api::Scope;
2524
use agama_utils::issue;
2625
use serde::{Deserialize, Serialize};
@@ -61,10 +60,3 @@ impl From<HashMap<Scope, Vec<issue::Issue>>> for IssuesMap {
6160
}
6261
}
6362
}
64-
65-
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
66-
/// Patch for the config.
67-
pub struct ConfigPatch {
68-
/// Update for the current config.
69-
pub update: Option<InstallSettings>,
70-
}

rust/agama-server/src/server/web.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
//! This module implements Agama's HTTP API.
2222
23-
use crate::server::types::{ConfigPatch, IssuesMap};
23+
use crate::server::types::IssuesMap;
2424
use agama_lib::error::ServiceError;
25-
use agama_lib::install_settings::InstallSettings;
25+
use agama_manager as manager;
2626
use agama_manager::message;
27-
use agama_manager::{self as manager};
2827
use agama_utils::actor::Handler;
29-
use agama_utils::api::{event, Action, Status, SystemInfo};
28+
use agama_utils::api::config;
29+
use agama_utils::api::event;
30+
use agama_utils::api::{Action, Config, Status, SystemInfo};
3031
use anyhow;
3132
use axum::extract::State;
3233
use axum::response::{IntoResponse, Response};
@@ -129,9 +130,7 @@ async fn get_system(State(state): State<ServerState>) -> ServerResult<Json<Syste
129130
(status = 400, description = "Not possible to retrieve the configuration.")
130131
)
131132
)]
132-
async fn get_extended_config(
133-
State(state): State<ServerState>,
134-
) -> ServerResult<Json<InstallSettings>> {
133+
async fn get_extended_config(State(state): State<ServerState>) -> ServerResult<Json<Config>> {
135134
let config = state.manager.call(message::GetExtendedConfig).await?;
136135
Ok(Json(config))
137136
}
@@ -146,7 +145,7 @@ async fn get_extended_config(
146145
(status = 400, description = "Not possible to retrieve the configuration.")
147146
)
148147
)]
149-
async fn get_config(State(state): State<ServerState>) -> ServerResult<Json<InstallSettings>> {
148+
async fn get_config(State(state): State<ServerState>) -> ServerResult<Json<Config>> {
150149
let config = state.manager.call(message::GetConfig).await?;
151150
Ok(Json(config))
152151
}
@@ -163,12 +162,12 @@ async fn get_config(State(state): State<ServerState>) -> ServerResult<Json<Insta
163162
(status = 400, description = "Not possible to replace the configuration.")
164163
),
165164
params(
166-
("config" = InstallSettings, description = "Configuration to apply.")
165+
("config" = Config, description = "Configuration to apply.")
167166
)
168167
)]
169168
async fn put_config(
170169
State(state): State<ServerState>,
171-
Json(config): Json<InstallSettings>,
170+
Json(config): Json<Config>,
172171
) -> ServerResult<()> {
173172
state.manager.call(message::SetConfig::new(config)).await?;
174173
Ok(())
@@ -186,12 +185,12 @@ async fn put_config(
186185
(status = 400, description = "Not possible to patch the configuration.")
187186
),
188187
params(
189-
("config" = InstallSettings, description = "Changes in the configuration.")
188+
("config" = Config, description = "Changes in the configuration.")
190189
)
191190
)]
192191
async fn patch_config(
193192
State(state): State<ServerState>,
194-
Json(patch): Json<ConfigPatch>,
193+
Json(patch): Json<config::Patch>,
195194
) -> ServerResult<()> {
196195
if let Some(config) = patch.update {
197196
state

rust/agama-server/src/web/docs/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl ApiDocBuilder for ConfigApiDocBuilder {
157157
.schema_from::<agama_lib::users::RootUserSettings>()
158158
.schema_from::<agama_lib::users::UserPassword>()
159159
.schema_from::<agama_lib::users::UserSettings>()
160-
.schema_from::<crate::server::types::ConfigPatch>()
161160
.schema_from::<crate::server::types::IssuesMap>()
162161
.schema_from::<crate::software::web::SoftwareProposal>()
163162
.schema_from::<agama_utils::api::Status>()
@@ -166,6 +165,8 @@ impl ApiDocBuilder for ConfigApiDocBuilder {
166165
.schema_from::<agama_utils::api::Scope>()
167166
.schema_from::<agama_utils::api::Action>()
168167
.schema_from::<agama_utils::api::SystemInfo>()
168+
.schema_from::<agama_utils::api::Config>()
169+
.schema_from::<agama_utils::api::config::Patch>()
169170
.schema_from::<agama_utils::api::l10n::SystemInfo>()
170171
.schema_from::<agama_utils::api::l10n::SystemConfig>()
171172
.schema_from::<agama_utils::api::l10n::LocaleEntry>()

0 commit comments

Comments
 (0)