add RedisConfig.password_file

This commit is contained in:
Astro 2023-10-12 22:09:43 +02:00
parent 38f5b2cb13
commit a8461c7217
3 changed files with 9 additions and 1 deletions

View file

@ -21,4 +21,5 @@ db: "host=localhost user=relay password=xyz dbname=buzzrelay"
# Optional Redis
redis:
connection: "redis://127.0.0.1:6378/"
password_file: "redis_password.txt"
in_topic: "relay-in"

View file

@ -4,6 +4,7 @@ use sigh::{PrivateKey, PublicKey, Key};
#[derive(Clone, Deserialize)]
pub struct RedisConfig {
pub connection: String,
pub password_file: String,
pub in_topic: String,
}

View file

@ -12,6 +12,7 @@ use serde_json::json;
use std::{net::SocketAddr, sync::Arc, time::Duration, collections::HashMap};
use std::{panic, process};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use reqwest::Url;
mod error;
mod config;
@ -334,7 +335,12 @@ async fn main() {
let database = db::Database::connect(&config.db).await;
let mut redis = None;
if let Some(redis_config) = config.redis.clone() {
let client = redis::Client::open(redis_config.connection)
let mut redis_url = Url::parse(&redis_config.connection)
.expect("redis.connection");
let redis_password = std::fs::read_to_string(redis_config.password_file)
.expect("redis.password_file");
redis_url.set_password(Some(&redis_password)).unwrap();
let client = redis::Client::open(redis_url)
.expect("redis::Client");
let manager = redis::aio::ConnectionManager::new(client)
.await