Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhb committed Jan 22, 2024
1 parent 05eb21d commit fd2bd09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ pub fn get_current_ruleset_raw(
}
None => default_args.to_vec(),
};
let program = nft_cmd.get_program().to_str().unwrap().to_string();
let process_result = nft_cmd
.args(args)
.output()
.map_err(|e| NftablesError::NftExecution {
inner: e,
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program: program.clone(),
})?;

let stdout = read_output(&nft_cmd, process_result.stdout)?;
Expand All @@ -65,7 +66,7 @@ pub fn get_current_ruleset_raw(
let stderr = read_output(&nft_cmd, process_result.stderr)?;

return Err(NftablesError::NftFailed {
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program,
hint: "getting the current ruleset".to_string(),
stdout,
stderr,
Expand Down Expand Up @@ -97,21 +98,22 @@ pub fn apply_ruleset_raw(
}
None => default_args.to_vec(),
};
let program = nft_cmd.get_program().to_str().unwrap().to_string();
let mut process = nft_cmd
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.map_err(|e| NftablesError::NftExecution {
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program: program.clone(),
inner: e,
})?;

let mut stdin = process.stdin.take().unwrap();
stdin
.write_all(payload.as_bytes())
.map_err(|e| NftablesError::NftExecution {
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program: program.clone(),
inner: e,
})?;
drop(stdin);
Expand All @@ -124,14 +126,14 @@ pub fn apply_ruleset_raw(
let stderr = read_output(&nft_cmd, process_result.stderr)?;

Err(NftablesError::NftFailed {
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program,
hint: "applying ruleset".to_string(),
stdout,
stderr,
})
}
Err(e) => Err(NftablesError::NftExecution {
program: format!("{}", nft_cmd.get_program().to_str().unwrap()),
program: nft_cmd.get_program().to_str().unwrap().to_string(),
inner: e,
}),
}
Expand All @@ -145,6 +147,6 @@ fn get_command(program: Option<&str>) -> Command {
fn read_output(cmd: &Command, bytes: Vec<u8>) -> Result<String, NftablesError> {
String::from_utf8(bytes).map_err(|e| NftablesError::NftOutputEncoding {
inner: e,
program: format!("{}", cmd.get_program().to_str().unwrap()),
program: cmd.get_program().to_str().unwrap().to_string(),
})
}
4 changes: 2 additions & 2 deletions tests/helper_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ fn example_ruleset() -> schema::Nftables {
batch.add(schema::NfListObject::Map(schema::Map {
family: types::NfFamily::IP,
table: table_name.clone(),
name: map_name.clone(),
name: map_name,
handle: None,
map: map_type.clone(),
map: map_type,
set_type: schema::SetTypeValue::Single(schema::SetType::Ipv4Addr),
policy: None,
flags: None,
Expand Down

0 comments on commit fd2bd09

Please sign in to comment.