Skip to content

Commit 2a0cdb5

Browse files
committed
minor improvements
1 parent b2c32d7 commit 2a0cdb5

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/agent/handler.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use caracat::models::Probe;
33
use ipnet::IpNet;
4-
use log::info;
4+
use log::{info, trace};
55
use rand::seq::SliceRandom;
66
use rand::thread_rng;
77
use rdkafka::consumer::{CommitMode, Consumer};
@@ -76,6 +76,9 @@ fn generate_probes(target: &Target) -> Result<Vec<Probe>> {
7676
}
7777

7878
pub async fn handle(config: &AppConfig) -> Result<()> {
79+
trace!("Agent handler");
80+
trace!("{:?}", config);
81+
7982
// Test input ID
8083
if !test_id(Some(config.agent.agent_id.clone()), None, None) {
8184
return Err(anyhow::anyhow!("Invalid agent ID"));

src/client/handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
use anyhow::Result;
2+
use log::trace;
23

34
use crate::auth::{KafkaAuth, SaslAuth};
45
use crate::client::producer::produce;
56
use crate::config::AppConfig;
67
use crate::target::decode_target;
78

89
pub async fn handle(config: &AppConfig, agents: &str, target: &str) -> Result<()> {
10+
trace!("Client handler");
11+
trace!("{:?}", config);
12+
913
// Configure Kafka authentication
1014
let auth = match config.kafka.auth_protocol.as_str() {
1115
"PLAINTEXT" => KafkaAuth::PlainText,

src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ pub struct AppConfig {
7474
pub kafka: KafkaConfig,
7575
}
7676

77-
pub fn load_config(config_path: &str) -> Config {
77+
fn load_config(config_path: &str) -> Config {
7878
Config::builder()
7979
.add_source(config::File::with_name(config_path))
8080
.add_source(config::Environment::with_prefix("SAIMIRIS"))
8181
.build()
8282
.unwrap()
8383
}
8484

85-
pub fn agent_config(config: Config) -> AppConfig {
85+
pub fn app_config(config_path: &str) -> AppConfig {
86+
let config = load_config(config_path);
8687
AppConfig {
8788
// Caracat configuration
8889
caracat: CaracatConfig {

src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use env_logger::Builder;
1313
use log::error;
1414
use std::io::Write;
1515

16-
use crate::config::{agent_config, load_config};
16+
use crate::config::app_config;
1717

1818
#[derive(Debug, Parser)]
1919
#[clap(name = "Saimiris", version)]
@@ -77,10 +77,8 @@ async fn main() -> Result<()> {
7777

7878
match cli.command {
7979
Command::Agent { config } => {
80-
let app_config = load_config(&config);
81-
let agent_config = agent_config(app_config);
82-
83-
match agent::handle(&agent_config).await {
80+
let app_config = app_config(&config);
81+
match agent::handle(&app_config).await {
8482
Ok(_) => (),
8583
Err(e) => error!("Error: {}", e),
8684
}
@@ -90,10 +88,8 @@ async fn main() -> Result<()> {
9088
agents,
9189
target,
9290
} => {
93-
let app_config = load_config(&config);
94-
let agent_config = agent_config(app_config);
95-
96-
match client::handle(&agent_config, &agents, &target).await {
91+
let app_config = app_config(&config);
92+
match client::handle(&app_config, &agents, &target).await {
9793
Ok(_) => (),
9894
Err(e) => error!("Error: {}", e),
9995
}

0 commit comments

Comments
 (0)