Skip to content

Commit

Permalink
storage: extend HTTP API to allow getting the solved config
Browse files Browse the repository at this point in the history
- /api/storage/solved_config
  • Loading branch information
joseivanlopez committed Oct 24, 2024
1 parent 2c0205f commit 585cf88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ impl<'a> StorageClient<'a> {
Ok(settings)
}

/// Get the storage solved config according to the JSON schema
pub async fn get_solved_config(&self) -> Result<StorageSettings, ServiceError> {
let serialized_settings = self.storage_proxy.get_solved_config().await?;
let settings = serde_json::from_str(serialized_settings.as_str()).unwrap();
Ok(settings)
}

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 @@ -44,6 +44,9 @@ trait Storage1 {
/// Get the current storage config according to the JSON schema
fn get_config(&self) -> zbus::Result<String>;

/// Get the current storage solved config according to the JSON schema
fn get_solved_config(&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 @@ -113,6 +113,7 @@ pub async fn storage_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
let state = StorageState { client };
let router = Router::new()
.route("/config", put(set_config).get(get_config))
.route("/solved_config", get(get_solved_config))
.route("/probe", post(probe))
.route("/devices/dirty", get(devices_dirty))
.route("/devices/system", get(system_devices))
Expand Down Expand Up @@ -155,6 +156,31 @@ async fn get_config(State(state): State<StorageState<'_>>) -> Result<Json<Storag
Ok(Json(settings))
}

/// Returns the solved storage configuration.
///
/// * `state` : service state.
#[utoipa::path(
get,
path = "/solved_config",
context_path = "/api/storage",
operation_id = "get_storage_solved_config",
responses(
(status = 200, description = "storage solved configuration", body = StorageSettings),
(status = 400, description = "The D-Bus service could not perform the action")
)
)]
async fn get_solved_config(
State(state): State<StorageState<'_>>,
) -> Result<Json<StorageSettings>, Error> {
// StorageSettings is just a wrapper over serde_json::value::RawValue
let settings = state
.client
.get_solved_config()
.await
.map_err(Error::Service)?;
Ok(Json(settings))
}

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

0 comments on commit 585cf88

Please sign in to comment.