Skip to content

Commit

Permalink
implement rust part
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 14, 2025
1 parent 98e59b1 commit 479d7c8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
25 changes: 24 additions & 1 deletion rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -88,6 +89,28 @@ impl<'a> SoftwareClient<'a> {
})
}

/// Returns list of defined repositories
pub async fn repositories(&self) -> Result<Vec<Repository>, ServiceError> {
let repositories: Vec<Repository> = 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<Vec<Pattern>, ServiceError> {
let patterns: Vec<Pattern> = self
Expand Down
20 changes: 20 additions & 0 deletions rust/agama-lib/src/software/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
22 changes: 20 additions & 2 deletions rust/agama-server/src/software/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -191,7 +191,6 @@ pub async fn software_service(dbus: zbus::Connection) -> Result<Router, ServiceE
let product_issues = issues_router(&dbus, DBUS_SERVICE, DBUS_PRODUCT_PATH).await?;

let product = ProductClient::new(dbus.clone()).await?;
let repositories = RepositoriesClient::new(dbus.clone()).await?;
let software = SoftwareClient::new(dbus).await?;
let state = SoftwareState { product, software };
let router = Router::new()
Expand Down Expand Up @@ -231,6 +230,25 @@ async fn products(State(state): State<SoftwareState<'_>>) -> Result<Json<Vec<Pro
Ok(Json(products))
}

/// Returns the list of defined repositories.
///
/// * `state`: service state.
#[utoipa::path(
get,
path = "/repositories",
context_path = "/api/software",
responses(
(status = 200, description = "List of known repositories", body = Vec<Repository>),
(status = 400, description = "The D-Bus service could not perform the action")
)
)]
async fn repositories(
State(state): State<SoftwareState<'_>>,
) -> Result<Json<Vec<Repository>>, Error> {
let repositories = state.software.repositories().await?;
Ok(Json(repositories))
}

/// returns registration info
///
/// * `state`: service state.
Expand Down
5 changes: 5 additions & 0 deletions rust/agama-server/src/web/docs/software.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ impl ApiDocBuilder for SoftwareApiDocBuilder {

fn paths(&self) -> Paths {
PathsBuilder::new()
.path_from::<crate::software::web::__path_deregister>()
.path_from::<crate::software::web::__path_get_config>()
.path_from::<crate::software::web::__path_get_registration>()
.path_from::<crate::software::web::__path_patterns>()
.path_from::<crate::software::web::__path_probe>()
.path_from::<crate::software::web::__path_products>()
.path_from::<crate::software::web::__path_proposal>()
.path_from::<crate::software::web::__path_repositories>()
.path_from::<crate::software::web::__path_register>()
.path_from::<crate::software::web::__path_set_config>()
.path_from::<crate::software::web::__path_set_resolvables>()
.build()
Expand All @@ -55,6 +59,7 @@ impl ApiDocBuilder for SoftwareApiDocBuilder {
.schema_from::<agama_lib::software::model::ResolvableType>()
.schema_from::<agama_lib::software::SelectedBy>()
.schema_from::<agama_lib::software::model::SoftwareConfig>()
.schema_from::<agama_lib::software::model::Repository>()
.schema_from::<crate::software::web::SoftwareProposal>()
.schema_from::<crate::web::common::Issue>()
.build()
Expand Down

0 comments on commit 479d7c8

Please sign in to comment.