Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into i18n_web_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Nov 26, 2024
2 parents 0d7aa42 + ccc33bb commit 70aa194
Show file tree
Hide file tree
Showing 33 changed files with 447 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-doc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && zypper ref

- name: Install Ruby development files and XML tooling
run: zypper --non-interactive install --no-recommends
run: zypper --non-interactive install --no-recommends --allow-downgrade
gcc gcc-c++ make libopenssl-devel ruby-devel augeas-devel diff
libxslt-devel libxml2-devel xmlstarlet 'rubygem(ruby-augeas)'

Expand Down
12 changes: 10 additions & 2 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,13 @@
"examples": ["jane.doe"]
},
"password": {
"title": "User password",
"title": "User password (plain text or encrypted depending on the \"passwordEncrypted\" field)",
"type": "string",
"examples": ["nots3cr3t"]
},
"passwordEncrypted": {
"title": "Flag for encrypted password (true) or plain text password (false or not defined)",
"type": "boolean"
}
},
"required": ["fullName", "userName", "password"]
Expand All @@ -404,9 +408,13 @@
"additionalProperties": false,
"properties": {
"password": {
"title": "Root password",
"title": "Root password (plain text or encrypted depending on the \"passwordEncrypted\" field)",
"type": "string"
},
"passwordEncrypted": {
"title": "Flag for encrypted password (true) or plain text password (false or not defined)",
"type": "boolean"
},
"sshPublicKey": {
"title": "SSH public key",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use tokio_stream::{StreamExt, StreamMap};
use zbus::{proxy::PropertyStream, Connection};

/// Represents the progress for an Agama service.
#[derive(Clone, Default, Debug, Serialize)]
#[derive(Clone, Default, Debug, Serialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Progress {
/// Current step
Expand Down
1 change: 1 addition & 0 deletions rust/agama-lib/src/proxies/questions/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use zbus::proxy;
#[proxy(
default_service = "org.opensuse.Agama1",
interface = "org.opensuse.Agama1.Questions",
default_path = "/org/opensuse/Agama1/Questions",
assume_defaults = true
)]
pub trait Questions {
Expand Down
1 change: 1 addition & 0 deletions rust/agama-lib/src/storage/proxies/iscsi/initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use zbus::proxy;
#[proxy(
default_service = "org.opensuse.Agama.Storage1",
default_path = "/org/opensuse/Agama/Storage1",
interface = "org.opensuse.Agama.Storage1.ISCSI.Initiator",
assume_defaults = true
)]
Expand Down
6 changes: 5 additions & 1 deletion rust/agama-lib/src/users/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct FirstUser {
pub user_name: String,
/// First user's password (in clear text)
pub password: String,
/// Whether the password is encrypted (true) or is plain text (false)
pub encrypted_password: bool,
/// Whether auto-login should enabled or not
pub autologin: bool,
}
Expand All @@ -46,7 +48,8 @@ impl FirstUser {
full_name: data.0,
user_name: data.1,
password: data.2,
autologin: data.3,
encrypted_password: data.3,
autologin: data.4,
})
}
}
Expand Down Expand Up @@ -107,6 +110,7 @@ impl<'a> UsersClient<'a> {
&first_user.full_name,
&first_user.user_name,
&first_user.password,
first_user.encrypted_password,
first_user.autologin,
std::collections::HashMap::new(),
)
Expand Down
3 changes: 3 additions & 0 deletions rust/agama-lib/src/users/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use zbus::proxy;
/// * full name
/// * user name
/// * password
/// * encrypted_password (true = encrypted, false = plain text)
/// * auto-login (enabled or not)
/// * some optional and additional data
// NOTE: Manually added to this file.
Expand All @@ -55,6 +56,7 @@ pub type FirstUser = (
String,
String,
bool,
bool,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
);

Expand All @@ -77,6 +79,7 @@ pub trait Users1 {
full_name: &str,
user_name: &str,
password: &str,
encrypted_password: bool,
auto_login: bool,
data: std::collections::HashMap<&str, &zbus::zvariant::Value<'_>>,
) -> zbus::Result<(bool, Vec<String>)>;
Expand Down
5 changes: 5 additions & 0 deletions rust/agama-lib/src/users/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct FirstUserSettings {
pub user_name: Option<String>,
/// First user's password (in clear text)
pub password: Option<String>,
/// Whether the password is encrypted or is plain text
pub encrypted_password: Option<bool>,
/// Whether auto-login should enabled or not
pub autologin: Option<bool>,
}
Expand All @@ -56,6 +58,9 @@ pub struct RootUserSettings {
/// Root's password (in clear text)
#[serde(skip_serializing)]
pub password: Option<String>,
/// Whether the password is encrypted or is plain text
#[serde(skip_serializing)]
pub encrypted_password: Option<bool>,
/// Root SSH public key
pub ssh_public_key: Option<String>,
}
13 changes: 11 additions & 2 deletions rust/agama-lib/src/users/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl UsersStore {
autologin: Some(first_user.autologin),
full_name: Some(first_user.full_name),
password: Some(first_user.password),
encrypted_password: Some(first_user.encrypted_password),
};
let mut root_user = RootUserSettings::default();
let ssh_public_key = self.users_client.root_ssh_key().await?;
Expand Down Expand Up @@ -77,16 +78,19 @@ impl UsersStore {
full_name: settings.full_name.clone().unwrap_or_default(),
autologin: settings.autologin.unwrap_or_default(),
password: settings.password.clone().unwrap_or_default(),
encrypted_password: settings.encrypted_password.clone().unwrap_or_default(),
..Default::default()
};
self.users_client.set_first_user(&first_user).await?;
Ok(())
}

async fn store_root_user(&self, settings: &RootUserSettings) -> Result<(), ServiceError> {
let encrypted_password = settings.encrypted_password.clone().unwrap_or_default();

if let Some(root_password) = &settings.password {
self.users_client
.set_root_password(root_password, false)
.set_root_password(root_password, encrypted_password)
.await?;
}

Expand Down Expand Up @@ -126,6 +130,7 @@ mod test {
"fullName": "Tux",
"userName": "tux",
"password": "fish",
"encryptedPassword": false,
"autologin": true
}"#,
);
Expand All @@ -150,11 +155,13 @@ mod test {
full_name: Some("Tux".to_owned()),
user_name: Some("tux".to_owned()),
password: Some("fish".to_owned()),
encrypted_password: Some(false),
autologin: Some(true),
};
let root_user = RootUserSettings {
// FIXME this is weird: no matter what HTTP reports, we end up with None
password: None,
encrypted_password: None,
ssh_public_key: Some("keykeykey".to_owned()),
};
let expected = UserSettings {
Expand All @@ -179,7 +186,7 @@ mod test {
when.method(PUT)
.path("/api/users/first")
.header("content-type", "application/json")
.body(r#"{"fullName":"Tux","userName":"tux","password":"fish","autologin":true}"#);
.body(r#"{"fullName":"Tux","userName":"tux","password":"fish","encryptedPassword":false,"autologin":true}"#);
then.status(200);
});
// note that we use 2 requests for root
Expand All @@ -205,10 +212,12 @@ mod test {
full_name: Some("Tux".to_owned()),
user_name: Some("tux".to_owned()),
password: Some("fish".to_owned()),
encrypted_password: Some(false),
autologin: Some(true),
};
let root_user = RootUserSettings {
password: Some("1234".to_owned()),
encrypted_password: Some(false),
ssh_public_key: Some("keykeykey".to_owned()),
};
let settings = UserSettings {
Expand Down
3 changes: 2 additions & 1 deletion rust/agama-server/src/users/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ async fn first_user_changed_stream(
full_name: user.0,
user_name: user.1,
password: user.2,
autologin: user.3,
encrypted_password: user.3,
autologin: user.4,
};
return Some(Event::FirstUserChanged(user_struct));
}
Expand Down
10 changes: 5 additions & 5 deletions rust/agama-server/src/web/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ struct ServiceStatusState<'a> {
proxy: ServiceStatusProxy<'a>,
}

#[derive(Clone, Serialize)]
struct ServiceStatus {
/// Current service status.
#[derive(Clone, Serialize, utoipa::ToSchema)]
pub struct ServiceStatus {
/// Current service status (0 = idle, 1 = busy).
current: u32,
}

Expand Down Expand Up @@ -189,7 +189,7 @@ struct ProgressState<'a> {
}

/// Information about the current progress sequence.
#[derive(Clone, Default, Serialize)]
#[derive(Clone, Default, Serialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct ProgressSequence {
/// Sequence steps if known in advance
Expand Down Expand Up @@ -319,7 +319,7 @@ struct IssuesState<'a> {
proxy: IssuesProxy<'a>,
}

#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug, Serialize, utoipa::ToSchema)]
pub struct Issue {
description: String,
details: Option<String>,
Expand Down
26 changes: 19 additions & 7 deletions rust/agama-server/src/web/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use utoipa::openapi::{Components, InfoBuilder, OpenApiBuilder, Paths};
use utoipa::openapi::{Components, Info, InfoBuilder, OpenApi, OpenApiBuilder, Paths};

mod network;
pub use network::NetworkApiDocBuilder;
Expand All @@ -36,6 +36,7 @@ mod users;
pub use users::UsersApiDocBuilder;
mod misc;
pub use misc::MiscApiDocBuilder;
pub mod common;

pub trait ApiDocBuilder {
fn title(&self) -> String {
Expand All @@ -46,16 +47,27 @@ pub trait ApiDocBuilder {

fn components(&self) -> Components;

fn build(&self) -> utoipa::openapi::OpenApi {
let info = InfoBuilder::new()
fn info(&self) -> Info {
InfoBuilder::new()
.title(self.title())
.version("0.1.0")
.build();
.build()
}

fn nested(&self) -> Option<OpenApi> {
None
}

OpenApiBuilder::new()
.info(info)
fn build(&self) -> utoipa::openapi::OpenApi {
let mut api = OpenApiBuilder::new()
.info(self.info())
.paths(self.paths())
.components(Some(self.components()))
.build()
.build();

if let Some(nested) = self.nested() {
api.merge(nested);
}
api
}
}
Loading

0 comments on commit 70aa194

Please sign in to comment.