diff --git a/rust/agama-lib/src/users/client.rs b/rust/agama-lib/src/users/client.rs index 923a61627c..2c24e1e602 100644 --- a/rust/agama-lib/src/users/client.rs +++ b/rust/agama-lib/src/users/client.rs @@ -7,7 +7,7 @@ use serde::{Serialize,Deserialize}; use zbus::Connection; /// Represents the settings for the first user -#[derive(Serialize, Deserialize, Debug, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, Default)] pub struct FirstUser { /// First user's full name pub full_name: String, diff --git a/rust/agama-server/src/users/web.rs b/rust/agama-server/src/users/web.rs index cef65ef2a6..bc693d9795 100644 --- a/rust/agama-server/src/users/web.rs +++ b/rust/agama-server/src/users/web.rs @@ -6,7 +6,7 @@ use axum::{ extract::State, - routing::put, + routing::{get, put}, Json, Router, }; use serde::{Deserialize, Serialize}; @@ -113,9 +113,10 @@ pub async fn users_service(dbus: zbus::Connection) -> Result Result<(), Error> { state.users.set_root_sshkey(key.as_str()).await?; Ok(()) -} \ No newline at end of file +} + +#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)] +pub struct RootInfo { + password: bool, + sshkey: Option, +} + +#[derive(Clone, Debug, Default, Serialize, Deserialize, utoipa::ToSchema)] +pub struct UsersInfo { + user: Option, + root: RootInfo, +} + +async fn get_info(State(state): State>) + -> Result, Error> { + let mut result = UsersInfo::default(); + let first_user = state.users.first_user().await?; + if first_user.user_name.is_empty() { + result.user = None; + } else { + result.user = Some(first_user); + } + result.root.password = state.users.is_root_password().await?; + let ssh_key = state.users.root_ssh_key().await?; + if ssh_key.is_empty() { + result.root.sshkey = None; + } else { + result.root.sshkey = Some(ssh_key); + } + Ok(Json(result)) +}