Skip to content

Commit

Permalink
feat(storage): add HTTP endpoint to get the config model
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 19, 2024
1 parent afe0190 commit 636332c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use super::proxies::{DevicesProxy, ProposalCalculatorProxy, ProposalProxy, Stora
use super::StorageSettings;
use crate::dbus::get_property;
use crate::error::ServiceError;
use serde_json::value::RawValue;
use std::collections::HashMap;
use zbus::fdo::ObjectManagerProxy;
use zbus::names::{InterfaceName, OwnedInterfaceName};
Expand Down Expand Up @@ -160,6 +161,13 @@ impl<'a> StorageClient<'a> {
Ok(settings)
}

/// Get the storage config model according to the JSON schema
pub async fn get_config_model(&self) -> Result<Box<RawValue>, ServiceError> {
let serialized_config_model = self.storage_proxy.get_config_model().await?;
let config_model = serde_json::from_str(serialized_config_model.as_str()).unwrap();
Ok(config_model)
}

pub async fn calculate(&self, settings: ProposalSettingsPatch) -> Result<u32, ServiceError> {
Ok(self.calculator_proxy.calculate(settings.into()).await?)
}
Expand Down
3 changes: 3 additions & 0 deletions rust/agama-lib/src/storage/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ trait Storage1 {
/// Get the current storage solved config according to the JSON schema
fn get_solved_config(&self) -> zbus::Result<String>;

/// Get the storage config model according to the JSON schema
fn get_config_model(&self) -> zbus::Result<String>;

/// DeprecatedSystem property
#[dbus_proxy(property)]
fn deprecated_system(&self) -> zbus::Result<bool>;
Expand Down
26 changes: 26 additions & 0 deletions rust/agama-server/src/storage/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use axum::{
Json, Router,
};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use tokio_stream::{Stream, StreamExt};
use zfcp::{zfcp_service, zfcp_stream};

Expand Down Expand Up @@ -114,6 +115,7 @@ pub async fn storage_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
let router = Router::new()
.route("/config", put(set_config).get(get_config))
.route("/solved_config", get(get_solved_config))
.route("/config_model", get(get_config_model))
.route("/probe", post(probe))
.route("/devices/dirty", get(devices_dirty))
.route("/devices/system", get(system_devices))
Expand Down Expand Up @@ -181,6 +183,30 @@ async fn get_solved_config(
Ok(Json(settings))
}

/// Returns the storage config model.
///
/// * `state` : service state.
#[utoipa::path(
get,
path = "/config_model",
context_path = "/api/storage",
operation_id = "get_storage_config_model",
responses(
(status = 200, description = "storage config model", body = Box<RawValue>),
(status = 400, description = "The D-Bus service could not perform the action")
)
)]
async fn get_config_model(
State(state): State<StorageState<'_>>,
) -> Result<Json<Box<RawValue>>, Error> {
let config_model = state
.client
.get_config_model()
.await
.map_err(Error::Service)?;
Ok(Json(config_model))
}

/// Sets the storage configuration.
///
/// * `state`: service state.
Expand Down

0 comments on commit 636332c

Please sign in to comment.