feat(readarr): fetch the Readarr security config and expose it on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-20 16:15:34 -06:00
1 parent 1072585903
commit 97d67a6938
6 files changed
+117 -4

No files matched your search

+9
View File
@@ -20,6 +20,8 @@ mod get_command_handler_tests;
pub enum ReadarrGetCommand { pub enum ReadarrGetCommand {
#[command(about = "Fetch the host config for your Readarr instance")] #[command(about = "Fetch the host config for your Readarr instance")]
HostConfig, HostConfig,
#[command(about = "Fetch the security config for your Readarr instance")]
SecurityConfig,
#[command(about = "Get the system status")] #[command(about = "Get the system status")]
SystemStatus, SystemStatus,
} }
@@ -58,6 +60,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandH
.await?; .await?;
serde_json::to_string_pretty(&resp)? serde_json::to_string_pretty(&resp)?
} }
ReadarrGetCommand::SecurityConfig => {
let resp = self
.network
.handle_network_event(ReadarrEvent::GetSecurityConfig.into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrGetCommand::SystemStatus => { ReadarrGetCommand::SystemStatus => {
let resp = self let resp = self
.network .network
+24 -1
View File
@@ -23,7 +23,7 @@ mod tests {
#[rstest] #[rstest]
fn test_get_commands_have_no_arg_requirements( fn test_get_commands_have_no_arg_requirements(
#[values("host-config", "system-status")] subcommand: &str, #[values("host-config", "security-config", "system-status")] subcommand: &str,
) { ) {
let result = Cli::command().try_get_matches_from(["managarr", "readarr", "get", subcommand]); let result = Cli::command().try_get_matches_from(["managarr", "readarr", "get", subcommand]);
@@ -71,6 +71,29 @@ mod tests {
assert_ok!(&result); assert_ok!(&result);
} }
#[tokio::test]
async fn test_handle_get_security_config_command() {
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(ReadarrEvent::GetSecurityConfig.into()))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let get_security_config_command = ReadarrGetCommand::SecurityConfig;
let result =
ReadarrGetCommandHandler::with(&app_arc, get_security_config_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test] #[tokio::test]
async fn test_handle_get_system_status_command() { async fn test_handle_get_system_status_command() {
let mut mock_network = MockNetworkTrait::new(); let mut mock_network = MockNetworkTrait::new();
+6 -1
View File
@@ -15,6 +15,7 @@ mod readarr_network_tests;
pub enum ReadarrEvent { pub enum ReadarrEvent {
GetDiskSpace, GetDiskSpace,
GetHostConfig, GetHostConfig,
GetSecurityConfig,
GetStatus, GetStatus,
HealthCheck, HealthCheck,
} }
@@ -22,7 +23,7 @@ pub enum ReadarrEvent {
impl NetworkResource for ReadarrEvent { impl NetworkResource for ReadarrEvent {
fn resource(&self) -> &'static str { fn resource(&self) -> &'static str {
match &self { match &self {
ReadarrEvent::GetHostConfig => "/config/host", ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
ReadarrEvent::GetDiskSpace => "/diskspace", ReadarrEvent::GetDiskSpace => "/diskspace",
ReadarrEvent::HealthCheck => "/health", ReadarrEvent::HealthCheck => "/health",
ReadarrEvent::GetStatus => "/system/status", ReadarrEvent::GetStatus => "/system/status",
@@ -50,6 +51,10 @@ impl Network<'_, '_> {
.get_readarr_host_config() .get_readarr_host_config()
.await .await
.map(ReadarrSerdeable::from), .map(ReadarrSerdeable::from),
ReadarrEvent::GetSecurityConfig => self
.get_readarr_security_config()
.await
.map(ReadarrSerdeable::from),
ReadarrEvent::GetStatus => self.get_readarr_status().await.map(ReadarrSerdeable::from), ReadarrEvent::GetStatus => self.get_readarr_status().await.map(ReadarrSerdeable::from),
ReadarrEvent::HealthCheck => self ReadarrEvent::HealthCheck => self
.get_readarr_healthcheck() .get_readarr_healthcheck()
@@ -7,6 +7,7 @@ mod tests {
#[rstest] #[rstest]
#[case(ReadarrEvent::GetHostConfig, "/config/host")] #[case(ReadarrEvent::GetHostConfig, "/config/host")]
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")] #[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
#[case(ReadarrEvent::HealthCheck, "/health")] #[case(ReadarrEvent::HealthCheck, "/health")]
#[case(ReadarrEvent::GetStatus, "/system/status")] #[case(ReadarrEvent::GetStatus, "/system/status")]
+16 -1
View File
@@ -1,4 +1,4 @@
use crate::models::servarr_models::{DiskSpace, HostConfig, SystemStatus}; use crate::models::servarr_models::{DiskSpace, HostConfig, SecurityConfig, SystemStatus};
use crate::network::readarr_network::ReadarrEvent; use crate::network::readarr_network::ReadarrEvent;
use crate::network::{Network, RequestMethod}; use crate::network::{Network, RequestMethod};
use anyhow::Result; use anyhow::Result;
@@ -41,6 +41,21 @@ impl Network<'_, '_> {
.await .await
} }
pub(in crate::network::readarr_network) async fn get_readarr_security_config(
&mut self,
) -> Result<SecurityConfig> {
info!("Fetching Readarr security config");
let event = ReadarrEvent::GetSecurityConfig;
let request_props = self
.request_props_from(event, RequestMethod::Get, None::<()>, None, None)
.await;
self
.handle_request::<(), SecurityConfig>(request_props, |_, _| ())
.await
}
pub(in crate::network::readarr_network) async fn get_readarr_status( pub(in crate::network::readarr_network) async fn get_readarr_status(
&mut self, &mut self,
) -> Result<SystemStatus> { ) -> Result<SystemStatus> {
@@ -2,7 +2,10 @@
mod tests { mod tests {
use crate::models::HorizontallyScrollableText; use crate::models::HorizontallyScrollableText;
use crate::models::readarr_models::ReadarrSerdeable; use crate::models::readarr_models::ReadarrSerdeable;
use crate::models::servarr_models::{DiskSpace, HostConfig, SystemStatus}; use crate::models::servarr_models::{
AuthenticationMethod, AuthenticationRequired, CertificateValidation, DiskSpace, HostConfig,
SecurityConfig, SystemStatus,
};
use crate::network::network_tests::test_utils::{MockServarrApi, test_network}; use crate::network::network_tests::test_utils::{MockServarrApi, test_network};
use crate::network::readarr_network::ReadarrEvent; use crate::network::readarr_network::ReadarrEvent;
use chrono::DateTime; use chrono::DateTime;
@@ -141,6 +144,63 @@ mod tests {
assert_err!(result); assert_err!(result);
} }
#[tokio::test]
async fn test_handle_get_readarr_security_config_event() {
let (mock, app, _server) = MockServarrApi::get()
.returns(json!({
"authenticationMethod": "forms",
"authenticationRequired": "enabled",
"username": "test",
"password": "test",
"apiKey": "test1234",
"certificateValidation": "enabled"
}))
.build_for(ReadarrEvent::GetSecurityConfig)
.await;
app.lock().await.server_tabs.set_index(3);
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetSecurityConfig)
.await;
mock.assert_async().await;
let ReadarrSerdeable::SecurityConfig(security_config) = result.unwrap() else {
panic!("Expected SecurityConfig")
};
assert_eq!(
security_config,
SecurityConfig {
authentication_method: AuthenticationMethod::Forms,
authentication_required: Some(AuthenticationRequired::Enabled),
username: Some("test".to_owned()),
password: Some("test".to_owned()),
api_key: "test1234".to_owned(),
certificate_validation: CertificateValidation::Enabled,
}
);
}
#[tokio::test]
async fn test_handle_get_readarr_security_config_event_failure() {
let (mock, app, _server) = MockServarrApi::get()
.returns(json!({}))
.status(500)
.build_for(ReadarrEvent::GetSecurityConfig)
.await;
app.lock().await.server_tabs.set_index(3);
let mut network = test_network(&app);
let result = network
.handle_readarr_event(ReadarrEvent::GetSecurityConfig)
.await;
mock.assert_async().await;
assert_err!(result);
}
#[tokio::test] #[tokio::test]
async fn test_handle_get_readarr_status_event() { async fn test_handle_get_readarr_status_event() {
let (mock, app, _server) = MockServarrApi::get() let (mock, app, _server) = MockServarrApi::get()