Skip to content

Commit

Permalink
Merge pull request #573 from openSUSE/fix-users-import
Browse files Browse the repository at this point in the history
Merge root user settings
  • Loading branch information
imobachgs committed May 11, 2023
2 parents b2ab3f8 + e099605 commit 73287f9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
25 changes: 25 additions & 0 deletions rust/agama-lib/src/install_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ impl Settings for UserSettings {
let first_user = self.first_user.get_or_insert(Default::default());
first_user.merge(other_first_user);
}

if let Some(other_root) = &other.root {
let root = self.root.get_or_insert(Default::default());
root.merge(other_root);
}
}
}

Expand Down Expand Up @@ -256,6 +261,26 @@ pub struct SoftwareSettings {
mod tests {
use super::*;

#[test]
fn test_user_settings_merge() {
let mut user1 = UserSettings::default();
let user2 = UserSettings {
first_user: Some(FirstUserSettings {
full_name: Some("Jane Doe".to_string()),
..Default::default()
}),
root: Some(RootUserSettings {
password: Some("nots3cr3t".to_string()),
..Default::default()
}),
};
user1.merge(&user2);
let first_user = user1.first_user.unwrap();
assert_eq!(first_user.full_name, Some("Jane Doe".to_string()));
let root_user = user1.root.unwrap();
assert_eq!(root_user.password, Some("nots3cr3t".to_string()));
}

#[test]
fn test_merge() {
let mut user1 = FirstUserSettings::default();
Expand Down
11 changes: 5 additions & 6 deletions rust/agama-lib/src/store/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ impl<'a> UsersStore<'a> {
full_name: Some(first_user.full_name),
password: Some(first_user.password),
};
let ssh_public_key = self.users_client.root_ssh_key().await;
let root_user = RootUserSettings {
// todo: expose the password
password: None,
ssh_public_key: ssh_public_key.ok(),
};
let mut root_user = RootUserSettings::default();
let ssh_public_key = self.users_client.root_ssh_key().await?;
if !ssh_public_key.is_empty() {
root_user.ssh_public_key = Some(ssh_public_key)
}
Ok(UserSettings {
first_user: Some(first_user),
root: Some(root_user),
Expand Down
8 changes: 8 additions & 0 deletions rust/package/agama-cli.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu May 11 11:00:11 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Import root authentication settings when reading a Jsonnet file
(bsc#1211300, gh#openSUSE/agama#573).
- Do not export the SSH public key as an empty string when it is
not defined.

-------------------------------------------------------------------
Fri Mar 24 14:36:36 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down

0 comments on commit 73287f9

Please sign in to comment.