Skip to content

Commit

Permalink
Fixed formatting errors, retrying clippy
Browse files Browse the repository at this point in the history
Signed-off-by: djach7 <djachimo@redhat.com>
  • Loading branch information
djach7 committed May 5, 2023
1 parent 9430491 commit 7aad656
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
38 changes: 20 additions & 18 deletions client-linuxapp/src/serviceinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use fdo_data_formats::{
};
use fdo_http_wrapper::client::{RequestResult, ServiceClient};

use sha_crypt::{Sha256Params, sha256_simple, sha256_check};
use sha_crypt::{sha256_check, sha256_simple, Sha256Params};

const MAX_SERVICE_INFO_LOOPS: u32 = 1000;

Expand Down Expand Up @@ -105,7 +105,7 @@ fn create_user_with_password(user: &str, password: &str) -> Result<()> {
str_encrypted_pw = sha256_simple(password, &default_params).expect("Hashing failed");
assert!(sha256_check(password, &str_encrypted_pw).is_ok());
}

// Creates new user if user not present
log::info!("Creating user {user} with password");
Command::new("useradd")
Expand All @@ -119,7 +119,6 @@ fn create_user_with_password(user: &str, password: &str) -> Result<()> {
Ok(())
}


fn install_ssh_key(user: &str, key: &str) -> Result<()> {
let user_info = passwd::Passwd::from_name(user);
if user_info.is_none() {
Expand Down Expand Up @@ -457,21 +456,15 @@ async fn process_serviceinfo_in(si_in: &ServiceInfo, si_out: &mut ServiceInfo) -
}
if module == FedoraIotServiceInfoModule::SSHKey.into() {
if key == "username" {
let value = value
.as_str()
.context("Error parsing username value")?;
let value = value.as_str().context("Error parsing username value")?;
sshkey_user = Some(value.to_string());
log::info!("Username is: {value}");
} else if key == "password" {
let value = value
.as_str()
.context("Error parsing password value")?;
let value = value.as_str().context("Error parsing password value")?;
sshkey_password = Some(value.to_string());
log::info!("Password is present");
} else if key == "sshkeys" {
let value = value
.as_str()
.context("Error parsing sshkey value")?;
let value = value.as_str().context("Error parsing sshkey value")?;
sshkey_keys = Some(value.to_string());
log::info!("Keys are present");
}
Expand Down Expand Up @@ -686,25 +679,34 @@ async fn process_serviceinfo_in(si_in: &ServiceInfo, si_out: &mut ServiceInfo) -
if sshkey_user.is_none() {
bail!("SSHkey module missing username");
} else if sshkey_keys.is_none() && sshkey_password.is_none() {
bail!("SSHkey module missing password and key")
bail!("SSHkey module missing password and key")
}
if sshkey_password.is_some() {
log::info!("SSHkey module was active, creating user with password");
create_user_with_password(sshkey_user.as_ref().unwrap(), sshkey_password.as_ref().unwrap()).context(format!(
create_user_with_password(
sshkey_user.as_ref().unwrap(),
sshkey_password.as_ref().unwrap(),
)
.context(format!(
"Error creating new user with password: {}",
sshkey_user.as_ref().unwrap()
))?;
sshkey_user.as_ref().unwrap()
))?;
}
if sshkey_keys.is_some() {
log::info!("SSHkey module was active, installing SSH keys");
create_user(sshkey_user.as_ref().unwrap()).context(format!(
"Error creating new user: {}",
sshkey_user.as_ref().unwrap()
))?;
let sshkey_keys_v: Vec<String> = sshkey_keys.unwrap().split(" ").map(|s| s.to_string()).collect();
let sshkey_keys_v: Vec<String> = sshkey_keys
.unwrap()
.split(' ')
.map(|s| s.to_string())
.collect();
for key in sshkey_keys_v {
let key_s: String = key;
install_ssh_key(sshkey_user.as_ref().unwrap(), key_s.as_str()).context("Error installing SSH key")?;
install_ssh_key(sshkey_user.as_ref().unwrap(), key_s.as_str())
.context("Error installing SSH key")?;
log::info!("Installed sshkey: {key_s}");
}
}
Expand Down
14 changes: 2 additions & 12 deletions integration-tests/tests/service_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ async fn test_e2e() -> Result<()> {
{
// for default serviceinfo
for diun_key_type in &diun_key_types {
match test_password_login(
diun_verification_method_generator,
diun_key_type,
)
.await
{
match test_password_login(diun_verification_method_generator, diun_key_type).await {
Ok(()) => (),
Err(e) => {
failed.push(TestCase {
Expand All @@ -89,12 +84,7 @@ async fn test_e2e() -> Result<()> {

// for per_device serviceinfo
for diun_key_type in &diun_key_types {
match test_password_login(
diun_verification_method_generator,
diun_key_type,
)
.await
{
match test_password_login(diun_verification_method_generator, diun_key_type).await {
Ok(()) => (),
Err(e) => {
failed.push(TestCase {
Expand Down
4 changes: 2 additions & 2 deletions owner-onboarding-server/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ async fn perform_service_info(
)?;
if initial_user.password.is_some() {
out_si.add(
FedoraIotServiceInfoModule::SSHKey,
"password",
FedoraIotServiceInfoModule::SSHKey,
"password",
&initial_user.password,
)?;
}
Expand Down

0 comments on commit 7aad656

Please sign in to comment.