Skip to content

Commit

Permalink
feat: second analyzer active
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <[email protected]>
  • Loading branch information
AlexsJones committed Oct 28, 2023
1 parent 2b7c7f2 commit a715387
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use std::sync::Arc;
pub mod analyzer_trait;
mod s3_analyzer;
pub(crate) mod types;
mod sts_analyzer;

pub fn generate_analyzers<'a>(config: aws_config::SdkConfig) -> Vec<Box<dyn Analyzer + 'a>> {
let analyzers: Vec<Box<dyn Analyzer>> = vec![Box::new(s3_analyzer::S3Analyzer {
config: Arc::new(config),
})];
analyzers
vec![Box::new(s3_analyzer::S3Analyzer {
config: Arc::new(config.clone()),
}),Box::new(sts_analyzer::STSAnalyzer{
config: Arc::new(config.clone()),
})]
}
5 changes: 0 additions & 5 deletions src/analyzer/s3_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::collections::{BTreeMap, HashMap};
use crate::analyzer::analyzer_trait;
use crate::analyzer::types::AnalysisResults;
use unescape::unescape;
use async_trait::async_trait;
use aws_sdk_s3;
use colored::Colorize;
Expand Down Expand Up @@ -114,9 +112,6 @@ impl analyzer_trait::Analyzer for S3Analyzer {
},
Err(e) => ()
}



}
Err(err) => ()
}
Expand Down
47 changes: 47 additions & 0 deletions src/analyzer/sts_analyzer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::analyzer::analyzer_trait;
use crate::analyzer::types::AnalysisResults;
use crate::utils;
use async_trait::async_trait;
use aws_sdk_iam;
use colored::Colorize;
use std::sync::Arc;
pub struct STSAnalyzer {
pub config: Arc<aws_config::SdkConfig>,
}
#[async_trait]
impl analyzer_trait::Analyzer for STSAnalyzer {
async fn run(&self) -> Option<Vec<AnalysisResults>> {
println!(
"{} {} {}",
"Running".green(),
"STS".blue(),
"analyzer".green()
);

let mut results = vec![AnalysisResults {
message: "".to_string(),
}];
let iam = aws_sdk_iam::Client::new(&self.config.clone());
let list_users_response = iam.list_users().send().await;
let users = list_users_response.unwrap().users.unwrap_or_default();
for user in users {
let username = user.user_name.as_deref().unwrap_or_default();

// Use IAM to get user's MFA status
let mfa_devices_response = iam.list_mfa_devices().user_name(username).send().await;
let mfa_devices = mfa_devices_response.unwrap().mfa_devices.unwrap_or_default();

if mfa_devices.is_empty() {
results.push(AnalysisResults{
message: format!("MFA is not enabled for user {}", username)
});
}
}

Some(results)
}

fn get_name(&self) -> &str {
"sts"
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod analyzer;
mod config;
mod outputs;

mod utils;

// const
const CARGO_PKG_NAME: &str = "isotope";
const CARGO_PKG_DESCRIPTION: &str = "Isotope allows for the debugging of AWS services with AI";
Expand Down
2 changes: 1 addition & 1 deletion src/outputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Processor {
}
fn print_text(&self) {
for elem in self.analysis_results.iter().filter(|&x| !x.message.is_empty()) {
println!("{:?}", elem.message);
println!("{}", elem.message);
}
}

Expand Down

0 comments on commit a715387

Please sign in to comment.