diff --git a/Cargo.lock b/Cargo.lock index 6bdf6aa..befd43f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1106,7 +1106,6 @@ dependencies = [ "clap", "colored", "futures", - "seahorse", "serde", "serde_json", "simple-home-dir", @@ -1489,12 +1488,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "seahorse" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3367111e93171f2f51f16fb46201bf6687f9da95eb1d409b6067cbc77af9c9c" - [[package]] name = "security-framework" version = "2.9.2" diff --git a/Cargo.toml b/Cargo.toml index f738fe6..a2f32fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -seahorse = "2.1" simple-home-dir = "0.2.0" serde_json = "1.0.107" serde = {version= "1.0.188", features = ["derive"] } diff --git a/src/analyze/mod.rs b/src/analyze/mod.rs index 7eaee18..761a9e8 100644 --- a/src/analyze/mod.rs +++ b/src/analyze/mod.rs @@ -29,13 +29,11 @@ pub async fn run_analysis(args: &Args) { match filtered_analyzer { Some(x) => { let thread_tx = tx.clone(); - // Init analyzer - x.run().await; let response = x.run().await; match response { - Some(respResults) => { - thread_tx.send(respResults).unwrap(); + Some(resp_results) => { + thread_tx.send(resp_results).unwrap(); } None => { thread_tx.send(vec![AnalysisResults::new()]).unwrap(); @@ -52,10 +50,6 @@ pub async fn run_analysis(args: &Args) { for current_analyzer in analyzers { let thread_tx = tx.clone(); tasks.push(tokio::spawn(async move { - - // Init analyzer - current_analyzer.init().await; - let response = current_analyzer.run().await; match response { Some(resp_results) => { diff --git a/src/analyzer/s3_analyzer.rs b/src/analyzer/s3_analyzer.rs index 8c73b70..85cfb18 100644 --- a/src/analyzer/s3_analyzer.rs +++ b/src/analyzer/s3_analyzer.rs @@ -1,13 +1,13 @@ use crate::analyzer::analyzer_trait; use crate::analyzer::types::AnalysisResults; -use crate::utils; + use async_trait::async_trait; use colored::Colorize; use std::sync::Arc; use aws_sdk_s3; -const role_name: &str = "DetectPublicS3BucketsRole"; -const policy_name: &str = "DetectPublicS3BucketsPolicy"; -const policy_document: &str = r#"{ +const ROLE_NAME: &str = "DetectPublicS3BucketsRole"; +const POLICY_NAME: &str = "DetectPublicS3BucketsPolicy"; +const POLICY_DOCUMENT: &str = r#"{ "Version": "2012-10-17", "Statement": [ { @@ -21,7 +21,7 @@ const policy_document: &str = r#"{ ] } "#; -const assume_role_policy_document: &str = r#"{ +const ASSUME_ROLE_POLICY_DOCUMENT: &str = r#"{ "Version": "2012-10-17", "Statement": [ { @@ -56,27 +56,27 @@ impl analyzer_trait::Analyzer for S3Analyzer { // let c4 = Arc::clone(&self.config); // let mut shouldCreate: bool = false; // // Role ------------------------------------------------------------------------------------ - // match utils::iam::check_role_exists(c2, role_name).await { - // Ok(x) => println!("Role {} exists", role_name), + // match utils::iam::check_role_exists(c2, ROLE_NAME).await { + // Ok(x) => println!("Role {} exists", ROLE_NAME), // _ => { // shouldCreate = true; - // println!("Role {} does not exist", role_name) + // println!("Role {} does not exist", ROLE_NAME) // } // } // if shouldCreate { - // let response = utils::iam::create_role(c3, role_name, assume_role_policy_document).await?; + // let response = utils::iam::create_role(c3, ROLE_NAME, ASSUME_ROLE_POLICY_DOCUMENT).await?; // println!( // "Created role {} with ARN {}", - // response.role_name.unwrap(), + // response.ROLE_NAME.unwrap(), // response.arn.unwrap() // ); // } // // Policy ---------------------------------------------------------------------------------- - // let policy = utils::iam::create_policy(c4, policy_name, policy_document).await; + // let policy = utils::iam::create_policy(c4, POLICY_NAME, POLICY_DOCUMENT).await; // match policy { // Ok(p) => println!("Created {:?}", p), // Err(e) => { - // println!("Error creating policy {} {}", policy_name, e); + // println!("Error creating policy {} {}", POLICY_NAME, e); // }, // } // ----------------------------------------------------------------------------------------- diff --git a/src/analyzer/types.rs b/src/analyzer/types.rs index 34e1417..1f94140 100644 --- a/src/analyzer/types.rs +++ b/src/analyzer/types.rs @@ -7,6 +7,6 @@ pub struct AnalysisResults { impl AnalysisResults { pub fn new() -> AnalysisResults{ - return Self{ message: "".to_string()} + Self{ message: "".to_string()} } } \ No newline at end of file diff --git a/src/configure/mod.rs b/src/configure/mod.rs deleted file mode 100644 index 6d9d8d7..0000000 --- a/src/configure/mod.rs +++ /dev/null @@ -1,52 +0,0 @@ - -use seahorse::{Command, Context, Flag, FlagType, error::FlagError}; -use crate::config; -use crate::config::Conf; - -static CLOUD_TYPES: &[&str] = &["aws"]; -pub fn add_commands() -> Command { - Command::new("config") - .description("Configure isotope") - .alias("c") - .usage("isotope config") - .command(Command::new("set") - .usage("config set") - .description("isotope config set --cloud aws") - .flag( - Flag::new("cloud", FlagType::String) - .alias("cl"), - ) - .action(run_configure)) - .command(Command::new("get") - .description("isotope config get") - .usage("config get") - .action(show_configure)) -} -fn show_configure(_context: &Context) { - let c = config::get_or_create_config(); - match c { - Ok(x) => println!("{:?}",x), - Err(e) => println!("Error detected {:?}",e.to_string()) - } -} -fn run_configure(context: &Context) { - let mut conf: Conf = config::Conf{ cloud:String::new()}; - let c = config::get_or_create_config(); - match c { - Ok(x) => conf = x, - Err(e) => println!("Error detected {:?}",e.to_string()) - } - match context.string_flag("cloud") { - Ok(cl) => if CLOUD_TYPES.contains(&cl.as_str()) { - conf.cloud = cl.clone(); - } - Err(e) => match e { - FlagError::Undefined => println!("--cloud flag required"), - FlagError::ArgumentError => panic!("argument error..."), - FlagError::NotFound => panic!("flag not found..."), - FlagError::ValueTypeError => panic!("value type mismatch..."), - FlagError::TypeError => println!("Wrong flag type selected"), - }, - } - config::save_config(conf).unwrap(); -} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 87d19d8..a97a131 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,8 @@ use clap::{Parser}; mod analyze; -mod configure; mod config; mod analyzer; mod outputs; -mod utils; // const const CARGO_PKG_NAME: &str = "isotope"; diff --git a/src/utils/iam.rs b/src/utils/iam.rs index a3b14cb..35c3d61 100644 --- a/src/utils/iam.rs +++ b/src/utils/iam.rs @@ -1,10 +1,10 @@ use std::error::Error; use std::sync::Arc; -use aws_sdk_iam::operation::create_role::{CreateRoleError, CreateRoleOutput}; +use aws_sdk_iam::operation::create_role::{CreateRoleError}; use aws_sdk_iam::types::{Policy, Role}; -use aws_sdk_sts; + use aws_sdk_iam::error::SdkError; -use aws_sdk_iam::operation::create_policy::{CreatePolicyError, CreatePolicyOutput}; +use aws_sdk_iam::operation::create_policy::{CreatePolicyError}; use aws_smithy_runtime_api::client::orchestrator::HttpResponse; pub async fn check_role_exists( config: Arc, @@ -14,7 +14,7 @@ pub async fn check_role_exists( let iam = aws_sdk_iam::Client::new(&config); // Create a request to get information about the role. - let get_role_request = iam.get_role().role_name(role_name).send().await?; + let _get_role_request = iam.get_role().role_name(role_name).send().await?; // Attempt to get information about the role. Ok(()) } @@ -42,18 +42,18 @@ pub async fn create_role( // Configure the AWS region and create an IAM client. let iam = aws_sdk_iam::Client::new(&config); - let strippedPolicy = &assume_role_policy_document.to_string(); + let stripped_policy = &assume_role_policy_document.to_string(); let response = iam .create_role() .role_name(role_name) - .assume_role_policy_document(strippedPolicy) + .assume_role_policy_document(stripped_policy) .send() .await; match response { Ok(x) => Ok(x.role.unwrap()), Err(e) => { println!("create_role {:?}", e); - return Err(e); + Err(e) } } } diff --git a/src/utils/sts.rs b/src/utils/sts.rs index 37bd7e2..10ba86c 100644 --- a/src/utils/sts.rs +++ b/src/utils/sts.rs @@ -1,7 +1,7 @@ -use aws_sdk_sts::error::SdkError; -use aws_sdk_sts::operation::assume_role::{AssumeRoleError, AssumeRoleOutput}; -use aws_smithy_runtime_api::client::orchestrator::HttpResponse; -use std::error::Error; + + + + use std::sync::Arc; pub async fn get_account_id(config: Arc) -> Option {