mirror of
https://github.com/pcvolkmer/mv64e-rest-to-kafka-gateway
synced 2025-09-13 09:12:51 +00:00
feat: add optional ssl key password
This commit is contained in:
12
src/cli.rs
12
src/cli.rs
@@ -36,20 +36,26 @@ pub struct Cli {
|
||||
pub listen: String,
|
||||
#[arg(
|
||||
long,
|
||||
env = "APP_SSL_CA_FILE",
|
||||
env = "APP_KAFKA_SSL_CA_FILE",
|
||||
help = "CA file for SSL connection to Kafka"
|
||||
)]
|
||||
pub ssl_ca_file: Option<String>,
|
||||
#[arg(
|
||||
long,
|
||||
env = "APP_SSL_CERT_FILE",
|
||||
env = "APP_KAFKA_SSL_CERT_FILE",
|
||||
help = "Certificate file for SSL connection to Kafka"
|
||||
)]
|
||||
pub ssl_cert_file: Option<String>,
|
||||
#[arg(
|
||||
long,
|
||||
env = "APP_SSL_KEY_FILE",
|
||||
env = "APP_KAFKA_SSL_KEY_FILE",
|
||||
help = "Key file for SSL connection to Kafka"
|
||||
)]
|
||||
pub ssl_key_file: Option<String>,
|
||||
#[arg(
|
||||
long,
|
||||
env = "APP_KAFKA_SSL_KEY_PASSWORD",
|
||||
help = "The SSL key password"
|
||||
)]
|
||||
pub ssl_key_password: Option<String>,
|
||||
}
|
||||
|
27
src/main.rs
27
src/main.rs
@@ -73,12 +73,16 @@ async fn main() -> Result<(), ()> {
|
||||
.init();
|
||||
}
|
||||
|
||||
let mut client_config = ClientConfig::new();
|
||||
|
||||
client_config
|
||||
.set("bootstrap.servers", &CONFIG.bootstrap_server)
|
||||
.set("message.timeout.ms", "5000")
|
||||
.set("security.protocol", "ssl");
|
||||
|
||||
let producer = if CONFIG.ssl_cert_file.is_some() || CONFIG.ssl_key_file.is_some() {
|
||||
// Use SSL
|
||||
ClientConfig::new()
|
||||
.set("bootstrap.servers", &CONFIG.bootstrap_server)
|
||||
.set("message.timeout.ms", "5000")
|
||||
.set("security.protocol", "ssl")
|
||||
client_config
|
||||
.set(
|
||||
"ssl.ca.location",
|
||||
CONFIG.ssl_ca_file.clone().unwrap_or_default(),
|
||||
@@ -90,16 +94,14 @@ async fn main() -> Result<(), ()> {
|
||||
.set(
|
||||
"ssl.key.location",
|
||||
CONFIG.ssl_key_file.clone().unwrap_or_default(),
|
||||
)
|
||||
.create::<FutureProducer>()
|
||||
.map_err(|_| ())?
|
||||
);
|
||||
if let Some(ssl_key_password) = &CONFIG.ssl_key_password {
|
||||
client_config.set("ssl.key.password", ssl_key_password);
|
||||
}
|
||||
client_config.create::<FutureProducer>().map_err(|_| ())?
|
||||
} else {
|
||||
// Plain
|
||||
ClientConfig::new()
|
||||
.set("bootstrap.servers", &CONFIG.bootstrap_server)
|
||||
.set("message.timeout.ms", "5000")
|
||||
.create::<FutureProducer>()
|
||||
.map_err(|_| ())?
|
||||
client_config.create::<FutureProducer>().map_err(|_| ())?
|
||||
};
|
||||
|
||||
let sender = Arc::new(DefaultMtbFileSender::new(&CONFIG.topic, producer));
|
||||
@@ -128,6 +130,7 @@ static CONFIG: LazyLock<Cli> = LazyLock::new(|| Cli {
|
||||
ssl_ca_file: None,
|
||||
ssl_cert_file: None,
|
||||
ssl_key_file: None,
|
||||
ssl_key_password: None,
|
||||
});
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user