Skip to content

Commit

Permalink
Clippy (#510)
Browse files Browse the repository at this point in the history
* settings

* silly jack

* silly jack

* first run

* we did it

* nit

* un nit
  • Loading branch information
Cictrone authored Jan 27, 2024
1 parent bfd1eb9 commit bc0a869
Show file tree
Hide file tree
Showing 51 changed files with 291 additions and 292 deletions.
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
// RUST
"rust-analyzer.check.command": "clippy",
"rust-analyzer.checkOnSave.overrideCommand": [
"cargo",
"clippy",
"--fix",
"--workspace",
"--message-format=json",
"--all-targets",
"--allow-dirty"
],
// Formatting
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
Expand Down
5 changes: 3 additions & 2 deletions .devcontainer/library-scripts/rust-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if ! type rustup > /dev/null 2>&1; then
mkdir -p "${CARGO_HOME}" "${RUSTUP_HOME}"
chown ${USERNAME} "${CARGO_HOME}" "${RUSTUP_HOME}"
su ${USERNAME} -c "curl --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y --no-modify-path --profile minimal 2>&1"
else
else
echo "Rust already installed. Skipping."
fi

Expand All @@ -95,6 +95,7 @@ su ${USERNAME} -c "$(cat << EOF
rustup component add rls rust-analysis rust-src clippy 2>&1
rustup toolchain install nightly-2023-09-04
rustup component add rustfmt --toolchain nightly-2023-09-04
rustup component add clippy --toolchain nightly-2023-09-04
EOF
)"

Expand All @@ -109,4 +110,4 @@ EOF
)"


echo "Done!"
echo "Done!"
14 changes: 12 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@
"rust-analyzer.cargo.extraArgs": [
"--profile",
"rust-analyzer"
]
}
],
"rust-analyzer.check.command": "clippy",
"rust-analyzer.checkOnSave.overrideCommand": [
"cargo",
"clippy",
"--fix",
"--workspace",
"--message-format=json",
"--all-targets",
"--allow-dirty"
],
}
6 changes: 3 additions & 3 deletions implants/golem/src/inter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
use std::fmt;
use std::fmt::Display;

use anyhow;
use serde_json;


use starlark::errors::EvalMessage;
use starlark::errors::EvalSeverity;
use starlark::read_line::ReadLine;
Expand Down Expand Up @@ -110,7 +110,7 @@ fn interactive(ctx: &Context) -> anyhow::Result<()> {
}

pub fn interactive_main() -> anyhow::Result<()> {
let ctx = Context::new(ContextMode::Run, true, &vec![], true)?;
let ctx = Context::new(ContextMode::Run, true, &[], true)?;

interactive(&ctx)?;
Ok(())
Expand Down
11 changes: 4 additions & 7 deletions implants/golem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn run_tomes(tomes: Vec<ParsedTome>) -> Result<Vec<String>> {
};
let mut out = handle.output.collect();
let errors = handle.output.collect_errors();
if errors.len() > 0 {
if !errors.is_empty() {
return Err(anyhow!("tome execution failed: {:?}", errors));
}
println!("OUTPUT: {:?}", out);
Expand Down Expand Up @@ -108,7 +108,7 @@ fn main() -> anyhow::Result<()> {
}
};

if result.len() > 0 {
if !result.is_empty() {
println!("{:?}", result);
}
process::exit(error_code);
Expand All @@ -117,10 +117,7 @@ fn main() -> anyhow::Result<()> {
} else {
let mut parsed_tomes: Vec<ParsedTome> = Vec::new();
for embedded_file_path in eldritch::assets::Asset::iter() {
let filename = match embedded_file_path.split(r#"/"#).last() {
Some(local_filename) => local_filename,
None => "",
};
let filename = embedded_file_path.split('/').last().unwrap_or("");
println!("{}", embedded_file_path);
if filename == "main.eldritch" {
let tome_path = embedded_file_path.to_string().clone();
Expand Down Expand Up @@ -161,7 +158,7 @@ fn main() -> anyhow::Result<()> {
}
};

if result.len() > 0 {
if !result.is_empty() {
println!("{:?}", result);
}
process::exit(error_code);
Expand Down
4 changes: 1 addition & 3 deletions implants/golem/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ fn test_golem_main_syntax_fail() -> anyhow::Result<()> {
cmd.arg(format!("{GOLEM_CLI_TEST_DIR}syntax_fail.tome"));
cmd.assert()
.failure()
.stderr(predicate::str::contains(format!(
r#"Parse error: unexpected string literal "win" here"#
)));
.stderr(predicate::str::contains(r#"Parse error: unexpected string literal "win" here"#.to_string()));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion implants/imix/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Agent {
}
};

let interval = self.info.interval.clone();
let interval = self.info.interval;
let delay = match interval.checked_sub(start.elapsed().as_secs()) {
Some(secs) => Duration::from_secs(secs),
None => Duration::from_secs(0),
Expand Down
17 changes: 7 additions & 10 deletions implants/imix/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! callback_uri {
* Compile-time constant for the agent callback URI, derived from the IMIX_CALLBACK_URI environment variable during compilation.
* Defaults to "http://127.0.0.1:80/grpc" if this is unset.
*/
pub const CALLBACK_URI: &'static str = callback_uri!();
pub const CALLBACK_URI: &str = callback_uri!();

macro_rules! callback_interval {
() => {
Expand All @@ -32,7 +32,7 @@ macro_rules! callback_interval {
/* Compile-time constant for the agent retry interval, derived from the IMIX_RETRY_INTERVAL environment variable during compilation.
* Defaults to 5 if unset.
*/
pub const CALLBACK_INTERVAL: &'static str = callback_interval!();
pub const CALLBACK_INTERVAL: &str = callback_interval!();

macro_rules! retry_interval {
() => {
Expand All @@ -45,7 +45,7 @@ macro_rules! retry_interval {
/* Compile-time constant for the agent callback interval, derived from the IMIX_CALLBACK_INTERVAL environment variable during compilation.
* Defaults to 5 if unset.
*/
pub const RETRY_INTERVAL: &'static str = retry_interval!();
pub const RETRY_INTERVAL: &str = retry_interval!();

/*
* Config holds values necessary to configure an Agent.
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Default for Config {
#[cfg(debug_assertions)]
log::error!("failed to parse callback interval constant, defaulting to 5 seconds: {_err}");

5 as u64
5_u64
}
},
host: Some(host),
Expand All @@ -100,7 +100,7 @@ impl Default for Config {
"failed to parse retry interval constant, defaulting to 5 seconds: {_err}"
);

5 as u64
5_u64
}
},
}
Expand Down Expand Up @@ -155,10 +155,7 @@ fn get_host_id(file_path: String) -> String {
// Read Existing Host ID
let path = Path::new(file_path.as_str());
if path.exists() {
match fs::read_to_string(path) {
Ok(host_id) => return host_id.trim().to_string(),
Err(_) => {}
}
if let Ok(host_id) = fs::read_to_string(path) { return host_id.trim().to_string() }
}

// Generate New
Expand All @@ -179,7 +176,7 @@ fn get_host_id(file_path: String) -> String {
}
};

return host_id;
host_id
}

/*
Expand Down
7 changes: 2 additions & 5 deletions implants/imix/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ pub async fn install() {

// Iterate through all embedded files
for embedded_file_path in eldritch::assets::Asset::iter() {
let filename = match embedded_file_path.split(r#"/"#).last() {
Some(local_filename) => local_filename,
None => "",
};
let filename = embedded_file_path.split('/').last().unwrap_or("");

#[cfg(debug_assertions)]
log::debug!("checking asset {embedded_file_path}");
Expand Down Expand Up @@ -75,7 +72,7 @@ fn load_embedded_eldritch(path: String) -> Result<String> {
#[cfg(debug_assertions)]
log::error!("no asset file at {}", path);

return Err(anyhow!("no asset file at {}", path));
Err(anyhow!("no asset file at {}", path))
}
}
}
12 changes: 4 additions & 8 deletions implants/imix/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ async fn main() {
#[cfg(debug_assertions)]
init_logging();

match Command::new("imix")
if let Some(("install", _)) = Command::new("imix")
.subcommand(Command::new("install").about("Install imix"))
.get_matches()
.subcommand()
{
Some(("install", _)) => {
imix::install().await;
return;
}
_ => {}
.subcommand() {
imix::install().await;
return;
}

loop {
Expand Down
13 changes: 5 additions & 8 deletions implants/imix/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ impl TaskHandle {
let exec_started_at = self.output.get_exec_started_at();
let exec_finished_at = self.output.get_exec_finished_at();
let text = self.output.collect();
let err = match self.output.collect_errors().pop() {
Some(err) => Some(TaskError {
let err = self.output.collect_errors().pop().map(|err| TaskError {
msg: err.to_string(),
}),
None => None,
};
});

#[cfg(debug_assertions)]
log::info!(
Expand All @@ -57,7 +54,7 @@ impl TaskHandle {
}
);

if text.len() > 0
if !text.is_empty()
|| err.is_some()
|| exec_started_at.is_some()
|| exec_finished_at.is_some()
Expand All @@ -71,8 +68,8 @@ impl TaskHandle {
id: self.id,
output: text.join(""),
error: err,
exec_started_at: exec_started_at,
exec_finished_at: exec_finished_at,
exec_started_at,
exec_finished_at,
}),
})
.await?;
Expand Down
2 changes: 1 addition & 1 deletion implants/imix/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ macro_rules! crate_version {
};
}

pub const VERSION: &'static str = crate_version!();
pub const VERSION: &str = crate_version!();
1 change: 1 addition & 0 deletions implants/lib/eldritch/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl<'v> UnpackValue<'v> for AssetsLibrary {
// This is where all of the "assets.X" impl methods are bound
#[starlark_module]
#[rustfmt::skip]
#[allow(clippy::needless_lifetimes, clippy::type_complexity, clippy::too_many_arguments)]
fn methods(builder: &mut MethodsBuilder) {
fn copy(this: AssetsLibrary, src: String, dest: String) -> anyhow::Result<NoneType> {
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); }
Expand Down
2 changes: 1 addition & 1 deletion implants/lib/eldritch/src/assets/copy_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod tests {
// Run our code
#[cfg(any(target_os = "linux", target_os = "macos"))]
copy("exec_script/hello_world.sh".to_string(), path_dst)?;
#[cfg(any(target_os = "windows"))]
#[cfg(target_os = "windows")]
copy("exec_script/hello_world.bat".to_string(), path_dst)?;

// Read
Expand Down
1 change: 1 addition & 0 deletions implants/lib/eldritch/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<'v> UnpackValue<'v> for CryptoLibrary {
// This is where all of the "crypto.X" impl methods are bound
#[starlark_module]
#[rustfmt::skip]
#[allow(clippy::needless_lifetimes, clippy::type_complexity, clippy::too_many_arguments)]
fn methods(builder: &mut MethodsBuilder) {
fn aes_encrypt_file<'v>(this: CryptoLibrary, src: String, dst: String, key: String) -> anyhow::Result<NoneType> {
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); }
Expand Down
32 changes: 28 additions & 4 deletions implants/lib/eldritch/src/crypto/aes_decrypt_file_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ pub fn decrypt_file(src: String, dst: String, key: String) -> Result<()> {
}
}
if !invalid {
out_file.write(&block[..(16 - last_byte) as usize])?;
match out_file.write(&block[..(16 - last_byte) as usize]) {
Ok(_) => {}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("failed to decrypt file: {_err}");
}
};
continue;
}
}
}
out_file.write(&block)?;
match out_file.write(&block) {
Ok(_) => {}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("failed to decrypt file: {_err}");
}
};
block = GenericArray::from([0u8; 16]);
}
drop(src_file);
Expand Down Expand Up @@ -80,7 +92,13 @@ mod tests {
let test_dec_path = tmp_dir.path().join("test.txt.dec");
{
let mut tmp_file = File::create(test_path.clone())?;
tmp_file.write(&lorem_encrypted)?;
match tmp_file.write(&lorem_encrypted) {
Ok(_) => {}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("failed to decrypt file: {_err}");
}
};
}
decrypt_file(
test_path.to_str().unwrap().to_owned(),
Expand Down Expand Up @@ -137,7 +155,13 @@ mod tests {
let test_path = tmp_dir.path().join("test.txt");
{
let mut tmp_file = File::create(test_path.clone())?;
tmp_file.write(&[0u8; 15])?;
match tmp_file.write(&[0u8; 15]) {
Ok(_) => {}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("failed to decrypt file: {_err}");
}
};
}
assert!(decrypt_file(
test_path.to_str().unwrap().to_owned(),
Expand Down
8 changes: 7 additions & 1 deletion implants/lib/eldritch/src/crypto/aes_encrypt_file_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub fn encrypt_file(src: String, dst: String, key: String) -> Result<()> {
block = GenericArray::from_iter(short_buffer);
}
cipher.encrypt_block(&mut block);
out_file.write(&block)?;
match out_file.write(&block) {
Ok(_) => {}
Err(_err) => {
#[cfg(debug_assertions)]
log::error!("failed to encrypt file: {_err}");
}
};
block = GenericArray::from([0u8; 16]);
}
drop(src_file);
Expand Down
Loading

0 comments on commit bc0a869

Please sign in to comment.