Skip to content

Commit

Permalink
Move RootConfig, RootPatchSettings to a model module
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Jul 23, 2024
1 parent 6ea3d8b commit c49b025
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
1 change: 1 addition & 0 deletions rust/agama-lib/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod client;
mod http_client;
pub mod proxies;
pub mod model;
mod settings;
mod store;

Expand Down
14 changes: 1 addition & 13 deletions rust/agama-lib/src/users/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
use anyhow::anyhow; // WIP

use serde::Deserialize;
//use reqwest::StatusCode;
use super::client::FirstUser;
use crate::{base_http_client::BaseHTTPClient, error::ServiceError};
use crate::users::model::RootConfig;

pub struct UsersHttpClient {
client: BaseHTTPClient,
}

// copying agama_server::users::web::RootConfig
// but not all derives
// #[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
#[derive(Clone, Debug, Default, Deserialize)]
pub struct RootConfig {
/// returns if password for root is set or not
password: bool,
/// empty string mean no sshkey is specified
sshkey: String,
}

impl UsersHttpClient {
pub async fn new() -> Result<Self, ServiceError> {
Ok(Self {
Expand Down Expand Up @@ -91,7 +80,6 @@ impl UsersHttpClient {
Ok(root_config.sshkey)
}


/// SetRootSSHKey method
pub async fn set_root_sshkey(&self, value: &str) -> Result<u32, ServiceError> {
//Ok(self.users_proxy.set_root_sshkey(value).await?)
Expand Down
26 changes: 5 additions & 21 deletions rust/agama-server/src/users/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ use crate::{
};
use agama_lib::{
error::ServiceError,
users::{proxies::Users1Proxy, FirstUser, UsersClient},
users::{
model::{RootConfig, RootPatchSettings},
proxies::Users1Proxy,
FirstUser, UsersClient
},
};
use axum::{
extract::State,
Expand All @@ -23,7 +27,6 @@ use axum::{
Json, Router,
};
//use reqwest;
use serde::{Deserialize, Serialize};
use tokio_stream::{Stream, StreamExt};

#[derive(Clone)]
Expand Down Expand Up @@ -191,17 +194,6 @@ async fn get_user_config(State(state): State<UsersState<'_>>) -> Result<Json<Fir
Ok(Json(state.users.first_user().await?))
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct RootPatchSettings {
/// empty string here means remove ssh key for root
pub sshkey: Option<String>,
/// empty string here means remove password for root
pub password: Option<String>,
/// specify if patched password is provided in encrypted form
pub password_encrypted: Option<bool>,
}

#[utoipa::path(patch, path = "/users/root", responses(
(status = 200, description = "Root configuration is modified", body = RootPatchSettings),
(status = 400, description = "The D-Bus service could not perform the action"),
Expand All @@ -226,14 +218,6 @@ async fn patch_root(
Ok(())
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)]
pub struct RootConfig {
/// returns if password for root is set or not
password: bool,
/// empty string mean no sshkey is specified
sshkey: String,
}

#[utoipa::path(get, path = "/users/root", responses(
(status = 200, description = "Configuration for the root user", body = RootConfig),
(status = 400, description = "The D-Bus service could not perform the action"),
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-server/src/web/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ use utoipa::OpenApi;
schemas(crate::storage::web::iscsi::InitiatorParams),
schemas(crate::storage::web::iscsi::LoginParams),
schemas(crate::storage::web::iscsi::NodeParams),
schemas(crate::users::web::RootConfig),
schemas(crate::users::web::RootPatchSettings),
schemas(agama_lib::users::model::RootConfig),
schemas(agama_lib::users::model::RootPatchSettings),
schemas(super::http::PingResponse)
)
)]
Expand Down

0 comments on commit c49b025

Please sign in to comment.