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
+2 -2
View File
@@ -26,7 +26,7 @@ mod tests {
.with_body("{}")
.create_async()
.await;
let host = server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned();
let host = Some(server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned());
let port = Some(
server.host_with_port().split(':').collect::<Vec<&str>>()[1]
.parse()
@@ -38,8 +38,8 @@ mod tests {
host,
api_token: String::new(),
port,
use_ssl: false,
ssl_cert_path: None,
..RadarrConfig::default()
};
app.config.radarr = radarr_config;
let app_arc = Arc::new(Mutex::new(app));
+16 -7
View File
@@ -2261,15 +2261,24 @@ impl<'a, 'b> Network<'a, 'b> {
let RadarrConfig {
host,
port,
uri,
api_token,
use_ssl,
..
ssl_cert_path,
} = &app.config.radarr;
let protocol = if *use_ssl { "https" } else { "http" };
let uri = format!(
"{protocol}://{host}:{}/api/v3{resource}",
port.unwrap_or(7878)
);
let uri = if let Some(radarr_uri) = uri {
format!("{radarr_uri}/api/v3{resource}")
} else {
let protocol = if ssl_cert_path.is_some() {
"https"
} else {
"http"
};
let host = host.as_ref().unwrap();
format!(
"{protocol}://{host}:{}/api/v3{resource}",
port.unwrap_or(7878)
)
};
RequestProps {
uri,
+31 -12
View File
@@ -794,7 +794,7 @@ mod test {
.match_header("X-Api-Key", "test1234");
async_server = async_server.expect_at_most(0).create_async().await;
let host = server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned();
let host = Some(server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned());
let port = Some(
server.host_with_port().split(':').collect::<Vec<&str>>()[1]
.parse()
@@ -805,8 +805,7 @@ mod test {
host,
port,
api_token: "test1234".to_owned(),
use_ssl: false,
ssl_cert_path: None,
..RadarrConfig::default()
};
app.config.radarr = radarr_config;
let app_arc = Arc::new(Mutex::new(app));
@@ -4876,11 +4875,10 @@ mod test {
assert!(request_props.api_token.is_empty());
app_arc.lock().await.config.radarr = RadarrConfig {
host: "192.168.0.123".to_owned(),
host: Some("192.168.0.123".to_owned()),
port: Some(8080),
api_token: "testToken1234".to_owned(),
use_ssl: false,
ssl_cert_path: None,
..RadarrConfig::default()
};
}
@@ -4889,11 +4887,33 @@ mod test {
let api_token = "testToken1234".to_owned();
let app_arc = Arc::new(Mutex::new(App::default()));
app_arc.lock().await.config.radarr = RadarrConfig {
host: "192.168.0.123".to_owned(),
host: Some("192.168.0.123".to_owned()),
port: Some(8080),
api_token: api_token.clone(),
use_ssl: true,
ssl_cert_path: None,
ssl_cert_path: Some("/test/cert.crt".to_owned()),
..RadarrConfig::default()
};
let network = Network::new(&app_arc, CancellationToken::new(), Client::new());
let request_props = network
.radarr_request_props_from("/test", RequestMethod::Get, None::<()>)
.await;
assert_str_eq!(request_props.uri, "https://192.168.0.123:8080/api/v3/test");
assert_eq!(request_props.method, RequestMethod::Get);
assert_eq!(request_props.body, None);
assert_str_eq!(request_props.api_token, api_token);
}
#[tokio::test]
async fn test_radarr_request_props_from_custom_radarr_config_using_uri_instead_of_host_and_port()
{
let api_token = "testToken1234".to_owned();
let app_arc = Arc::new(Mutex::new(App::default()));
app_arc.lock().await.config.radarr = RadarrConfig {
uri: Some("https://192.168.0.123:8080".to_owned()),
api_token: api_token.clone(),
..RadarrConfig::default()
};
let network = Network::new(&app_arc, CancellationToken::new(), Client::new());
@@ -4986,7 +5006,7 @@ mod test {
async_server = async_server.create_async().await;
let host = server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned();
let host = Some(server.host_with_port().split(':').collect::<Vec<&str>>()[0].to_owned());
let port = Some(
server.host_with_port().split(':').collect::<Vec<&str>>()[1]
.parse()
@@ -4997,8 +5017,7 @@ mod test {
host,
port,
api_token: "test1234".to_owned(),
use_ssl: false,
ssl_cert_path: None,
..RadarrConfig::default()
};
app.config.radarr = radarr_config;
let app_arc = Arc::new(Mutex::new(app));