-
Notifications
You must be signed in to change notification settings - Fork 68
feat(rust): improve user/root exported information #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8353c83
1f3e48e
478247e
ab4b55d
6e66213
b3b71d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,8 @@ | |
| // find current contact information at www.suse.com. | ||
|
|
||
| use super::{ | ||
| http_client::UsersHTTPClientError, FirstUser, FirstUserSettings, RootUserSettings, | ||
| UserSettings, UsersHTTPClient, | ||
| http_client::UsersHTTPClientError, settings::UserPassword, FirstUser, FirstUserSettings, | ||
| RootUserSettings, UserSettings, UsersHTTPClient, | ||
| }; | ||
| use crate::http::BaseHTTPClient; | ||
|
|
||
|
|
@@ -50,23 +50,44 @@ impl UsersStore { | |
|
|
||
| pub async fn load(&self) -> UsersStoreResult<UserSettings> { | ||
| let first_user = self.users_client.first_user().await?; | ||
| let first_user = FirstUserSettings { | ||
| user_name: Some(first_user.user_name), | ||
| full_name: Some(first_user.full_name), | ||
| password: Some(first_user.password), | ||
| hashed_password: Some(first_user.hashed_password), | ||
| let first_user = if first_user.user_name.is_empty() { | ||
| None | ||
| } else { | ||
| let user_password = if first_user.password.is_empty() { | ||
| None | ||
| } else { | ||
| Some(UserPassword { | ||
| password: first_user.password, | ||
| hashed_password: first_user.hashed_password, | ||
| }) | ||
| }; | ||
|
|
||
| Some(FirstUserSettings { | ||
| user_name: Some(first_user.user_name), | ||
| full_name: Some(first_user.full_name), | ||
| password: user_password, | ||
| }) | ||
| }; | ||
|
|
||
| let root_user = self.users_client.root_user().await?; | ||
| let root_user = RootUserSettings { | ||
| password: root_user.password, | ||
| hashed_password: root_user.hashed_password, | ||
| ssh_public_key: root_user.ssh_public_key, | ||
| let root_password = root_user | ||
| .password | ||
| .filter(|password| !password.is_empty()) | ||
| .map(|password| UserPassword { | ||
| password, | ||
| hashed_password: root_user.hashed_password.unwrap_or_default(), | ||
| }); | ||
| let ssh_public_key = root_user.ssh_public_key.filter(|key| !key.is_empty()); | ||
| let root = if root_password.is_some() || ssh_public_key.is_some() { | ||
| Some(RootUserSettings { | ||
| password: root_password, | ||
| ssh_public_key, | ||
| }) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| Ok(UserSettings { | ||
| first_user: Some(first_user), | ||
| root: Some(root_user), | ||
| }) | ||
| Ok(UserSettings { first_user, root }) | ||
| } | ||
|
|
||
| pub async fn store(&self, settings: &UserSettings) -> UsersStoreResult<()> { | ||
|
|
@@ -85,18 +106,24 @@ impl UsersStore { | |
| let first_user = FirstUser { | ||
| user_name: settings.user_name.clone().unwrap_or_default(), | ||
| full_name: settings.full_name.clone().unwrap_or_default(), | ||
| password: settings.password.clone().unwrap_or_default(), | ||
| hashed_password: settings.hashed_password.unwrap_or_default(), | ||
| password: settings | ||
| .password | ||
| .as_ref() | ||
| .map(|p| p.password.clone()) | ||
| .unwrap_or_default(), | ||
| hashed_password: settings | ||
| .password | ||
| .as_ref() | ||
| .map(|p| p.hashed_password) | ||
| .unwrap_or_default(), | ||
|
||
| }; | ||
| Ok(self.users_client.set_first_user(&first_user).await?) | ||
| } | ||
|
|
||
| async fn store_root_user(&self, settings: &RootUserSettings) -> UsersStoreResult<()> { | ||
| let hashed_password = settings.hashed_password.unwrap_or_default(); | ||
|
|
||
| if let Some(root_password) = &settings.password { | ||
| if let Some(password) = &settings.password { | ||
| self.users_client | ||
| .set_root_password(root_password, hashed_password) | ||
| .set_root_password(&password.password, password.hashed_password) | ||
| .await?; | ||
| } | ||
|
|
||
|
|
@@ -160,13 +187,17 @@ mod test { | |
| let first_user = FirstUserSettings { | ||
| full_name: Some("Tux".to_owned()), | ||
| user_name: Some("tux".to_owned()), | ||
| password: Some("fish".to_owned()), | ||
| hashed_password: Some(false), | ||
| password: Some(UserPassword { | ||
| password: "fish".to_owned(), | ||
| hashed_password: false, | ||
| }), | ||
| }; | ||
| let root_user = RootUserSettings { | ||
| // FIXME this is weird: no matter what HTTP reports, we end up with None | ||
| password: Some("nots3cr3t".to_owned()), | ||
| hashed_password: Some(false), | ||
| password: Some(UserPassword { | ||
| password: "nots3cr3t".to_owned(), | ||
| hashed_password: false, | ||
| }), | ||
| ssh_public_key: Some("keykeykey".to_owned()), | ||
| }; | ||
| let expected = UserSettings { | ||
|
|
@@ -216,12 +247,16 @@ mod test { | |
| let first_user = FirstUserSettings { | ||
| full_name: Some("Tux".to_owned()), | ||
| user_name: Some("tux".to_owned()), | ||
| password: Some("fish".to_owned()), | ||
| hashed_password: Some(false), | ||
| password: Some(UserPassword { | ||
| password: "fish".to_owned(), | ||
| hashed_password: false, | ||
| }), | ||
| }; | ||
| let root_user = RootUserSettings { | ||
| password: Some("1234".to_owned()), | ||
| hashed_password: Some(false), | ||
| password: Some(UserPassword { | ||
| password: "1234".to_owned(), | ||
| hashed_password: false, | ||
| }), | ||
| ssh_public_key: Some("keykeykey".to_owned()), | ||
| }; | ||
| let settings = UserSettings { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| ------------------------------------------------------------------- | ||
| Tue Jun 10 13:33:09 UTC 2025 - Imobach Gonzalez Sosa <[email protected]> | ||
|
|
||
| - Expose the user and the root password when exporting the configuration | ||
| (bsc#1235602). | ||
| - Do not export the "user" section unless a first user is defined. | ||
| - Do not export the "root" section unless an authentication mechanism | ||
| is defined. | ||
|
|
||
| ------------------------------------------------------------------- | ||
| Fri Jun 6 13:22:58 UTC 2025 - Knut Anderssen <[email protected]> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means we still export even empty full_name. Is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the full_name is not mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in exported profile will be
full_name: ""which looks wrong to me.