Skip to content
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

Merge root user settings #573

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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