Removed the need for use_ssl to indicate SSL usage; instead just use the ssl_cert_path

Added the ability to specify either host/port, or uri for configuring Radarr
This commit is contained in:
2024-11-05 18:16:01 -07:00
parent 650c9783a6
commit 9936ce1ab5
7 changed files with 114 additions and 73 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
#[cfg(test)]
mod tests {
use anyhow::anyhow;
use pretty_assertions::{assert_eq, assert_str_eq};
use pretty_assertions::assert_eq;
use tokio::sync::mpsc;
use crate::app::context_clues::{build_context_clue_string, SERVARR_CONTEXT_CLUES};
@@ -221,10 +221,10 @@ mod tests {
fn test_radarr_config_default() {
let radarr_config = RadarrConfig::default();
assert_str_eq!(radarr_config.host, "localhost");
assert_eq!(radarr_config.host, Some("localhost".to_string()));
assert_eq!(radarr_config.port, Some(7878));
assert_eq!(radarr_config.uri, None);
assert!(radarr_config.api_token.is_empty());
assert!(!radarr_config.use_ssl);
assert_eq!(radarr_config.ssl_cert_path, None);
}
}
+31 -5
View File
@@ -1,4 +1,7 @@
use std::process;
use anyhow::anyhow;
use colored::Colorize;
use log::{debug, error};
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::Sender;
@@ -166,29 +169,52 @@ pub struct Data<'a> {
pub radarr_data: RadarrData<'a>,
}
pub trait ServarrConfig {
fn validate(&self);
}
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct AppConfig {
pub radarr: RadarrConfig,
}
impl ServarrConfig for AppConfig {
fn validate(&self) {
self.radarr.validate();
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct RadarrConfig {
pub host: String,
pub host: Option<String>,
pub port: Option<u16>,
pub uri: Option<String>,
pub api_token: String,
#[serde(default)]
pub use_ssl: bool,
pub ssl_cert_path: Option<String>,
}
impl ServarrConfig for RadarrConfig {
fn validate(&self) {
if self.host.is_none() && self.uri.is_none() {
log_and_print_error("'host' or 'uri' is required for Radarr configuration".to_owned());
process::exit(1);
}
}
}
impl Default for RadarrConfig {
fn default() -> Self {
RadarrConfig {
host: "localhost".to_string(),
host: Some("localhost".to_string()),
port: Some(7878),
uri: None,
api_token: "".to_string(),
use_ssl: false,
ssl_cert_path: None,
}
}
}
pub fn log_and_print_error(error: String) {
error!("{}", error);
eprintln!("error: {}", error.red());
}