From aa70c3db6ef342006039748d51cb2788ab3b39fe Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Sun, 19 May 2024 12:59:42 -0700 Subject: [PATCH] Get rabbitmq password from file instead of static string --- ofborg/src/config.rs | 12 +++++++----- ofborg/src/easylapin.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ofborg/src/config.rs b/ofborg/src/config.rs index dba6806..71e24bf 100644 --- a/ofborg/src/config.rs +++ b/ofborg/src/config.rs @@ -35,7 +35,7 @@ pub struct RabbitMqConfig { pub host: String, pub virtualhost: Option, pub username: String, - pub password: String, + pub password_file: PathBuf, } #[derive(Serialize, Deserialize, Debug)] @@ -155,15 +155,17 @@ impl Config { } impl RabbitMqConfig { - pub fn as_uri(&self) -> String { - format!( + pub fn as_uri(&self) -> Result { + let password = std::fs::read_to_string(&self.password_file)?; + let uri = format!( "{}://{}:{}@{}/{}", if self.ssl { "amqps" } else { "amqp" }, self.username, - self.password, + password, self.host, self.virtualhost.clone().unwrap_or_else(|| "/".to_owned()), - ) + ); + Ok(uri) } } diff --git a/ofborg/src/easylapin.rs b/ofborg/src/easylapin.rs index 95e1446..0c8df4f 100644 --- a/ofborg/src/easylapin.rs +++ b/ofborg/src/easylapin.rs @@ -31,7 +31,7 @@ pub fn from_config(cfg: &RabbitMqConfig) -> Result { client_properties: props, ..Default::default() }; - task::block_on(Connection::connect(&cfg.as_uri(), opts)) + task::block_on(Connection::connect(&cfg.as_uri()?, opts)) } impl ChannelExt for Channel {