From 479d7c8b473621654f58a39ca64a59344f5fbb90 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 14 Jan 2025 10:40:02 +0100 Subject: [PATCH] implement rust part --- rust/agama-lib/src/software/client.rs | 25 +++++++++++++++++++++- rust/agama-lib/src/software/model.rs | 20 +++++++++++++++++ rust/agama-server/src/software/web.rs | 22 +++++++++++++++++-- rust/agama-server/src/web/docs/software.rs | 5 +++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/rust/agama-lib/src/software/client.rs b/rust/agama-lib/src/software/client.rs index 26b63e48e3..f868235a93 100644 --- a/rust/agama-lib/src/software/client.rs +++ b/rust/agama-lib/src/software/client.rs @@ -19,7 +19,7 @@ // find current contact information at www.suse.com. use super::{ - model::ResolvableType, + model::{Repository, ResolvableType}, proxies::{ProposalProxy, Software1Proxy}, }; use crate::error::ServiceError; @@ -28,6 +28,7 @@ use serde_repr::Serialize_repr; use std::collections::HashMap; use zbus::Connection; +// TODO: move it to model? /// Represents a software product #[derive(Debug, Serialize, utoipa::ToSchema)] pub struct Pattern { @@ -88,6 +89,28 @@ impl<'a> SoftwareClient<'a> { }) } + /// Returns list of defined repositories + pub async fn repositories(&self) -> Result, ServiceError> { + let repositories: Vec = self + .software_proxy + .list_repositories() + .await? + .into_iter() + .map( + |(id, alias, name, url, product_dir, enabled, loaded)| Repository { + id, + alias, + name, + url, + product_dir, + enabled, + loaded, + }, + ) + .collect(); + Ok(repositories) + } + /// Returns the available patterns pub async fn patterns(&self, filtered: bool) -> Result, ServiceError> { let patterns: Vec = self diff --git a/rust/agama-lib/src/software/model.rs b/rust/agama-lib/src/software/model.rs index 8556dae11d..eef0c3198c 100644 --- a/rust/agama-lib/src/software/model.rs +++ b/rust/agama-lib/src/software/model.rs @@ -98,3 +98,23 @@ pub struct ResolvableParams { /// Whether the resolvables are optional or not. pub optional: bool, } + +/// Resolvable list specification. +#[derive(Deserialize, Serialize, utoipa::ToSchema)] +#[serde(rename_all = "camelCase")] +pub struct Repository { + /// repository identifier + pub id: i32, + /// repository alias. Has to be unique + pub alias: String, + /// repository name + pub name: String, + /// Repository url + pub url: String, + /// product directory. Do we need it? + pub product_dir: String, + /// Whether the repository is enabled + pub enabled: bool, + /// Whether the repository is loaded + pub loaded: bool, +} diff --git a/rust/agama-server/src/software/web.rs b/rust/agama-server/src/software/web.rs index 3dea1b1f31..7dc2f82847 100644 --- a/rust/agama-server/src/software/web.rs +++ b/rust/agama-server/src/software/web.rs @@ -38,7 +38,7 @@ use agama_lib::{ product::{proxies::RegistrationProxy, Product, ProductClient}, software::{ model::{ - RegistrationError, RegistrationInfo, RegistrationParams, ResolvableParams, + RegistrationError, RegistrationInfo, RegistrationParams, Repository, ResolvableParams, SoftwareConfig, }, proxies::{Software1Proxy, SoftwareProductProxy}, @@ -191,7 +191,6 @@ pub async fn software_service(dbus: zbus::Connection) -> Result>) -> Result), + (status = 400, description = "The D-Bus service could not perform the action") + ) +)] +async fn repositories( + State(state): State>, +) -> Result>, Error> { + let repositories = state.software.repositories().await?; + Ok(Json(repositories)) +} + /// returns registration info /// /// * `state`: service state. diff --git a/rust/agama-server/src/web/docs/software.rs b/rust/agama-server/src/web/docs/software.rs index 457cac6c0c..c75f334a42 100644 --- a/rust/agama-server/src/web/docs/software.rs +++ b/rust/agama-server/src/web/docs/software.rs @@ -34,11 +34,15 @@ impl ApiDocBuilder for SoftwareApiDocBuilder { fn paths(&self) -> Paths { PathsBuilder::new() + .path_from::() .path_from::() + .path_from::() .path_from::() .path_from::() .path_from::() .path_from::() + .path_from::() + .path_from::() .path_from::() .path_from::() .build() @@ -55,6 +59,7 @@ impl ApiDocBuilder for SoftwareApiDocBuilder { .schema_from::() .schema_from::() .schema_from::() + .schema_from::() .schema_from::() .schema_from::() .build()