feat(readarr): fetch the Readarr security config and expose it on the CLI
This commit is contained in:
6 files changed
+117
-4
No files matched your search
@@ -20,6 +20,8 @@ mod get_command_handler_tests;
|
||||
pub enum ReadarrGetCommand {
|
||||
#[command(about = "Fetch the host config for your Readarr instance")]
|
||||
HostConfig,
|
||||
#[command(about = "Fetch the security config for your Readarr instance")]
|
||||
SecurityConfig,
|
||||
#[command(about = "Get the system status")]
|
||||
SystemStatus,
|
||||
}
|
||||
@@ -58,6 +60,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandH
|
||||
.await?;
|
||||
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 => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -23,7 +23,7 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
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]);
|
||||
|
||||
@@ -71,6 +71,29 @@ mod tests {
|
||||
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]
|
||||
async fn test_handle_get_system_status_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
|
||||
@@ -15,6 +15,7 @@ mod readarr_network_tests;
|
||||
pub enum ReadarrEvent {
|
||||
GetDiskSpace,
|
||||
GetHostConfig,
|
||||
GetSecurityConfig,
|
||||
GetStatus,
|
||||
HealthCheck,
|
||||
}
|
||||
@@ -22,7 +23,7 @@ pub enum ReadarrEvent {
|
||||
impl NetworkResource for ReadarrEvent {
|
||||
fn resource(&self) -> &'static str {
|
||||
match &self {
|
||||
ReadarrEvent::GetHostConfig => "/config/host",
|
||||
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
||||
ReadarrEvent::GetDiskSpace => "/diskspace",
|
||||
ReadarrEvent::HealthCheck => "/health",
|
||||
ReadarrEvent::GetStatus => "/system/status",
|
||||
@@ -50,6 +51,10 @@ impl Network<'_, '_> {
|
||||
.get_readarr_host_config()
|
||||
.await
|
||||
.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::HealthCheck => self
|
||||
.get_readarr_healthcheck()
|
||||
|
||||
@@ -7,6 +7,7 @@ mod tests {
|
||||
|
||||
#[rstest]
|
||||
#[case(ReadarrEvent::GetHostConfig, "/config/host")]
|
||||
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
|
||||
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
|
||||
#[case(ReadarrEvent::HealthCheck, "/health")]
|
||||
#[case(ReadarrEvent::GetStatus, "/system/status")]
|
||||
|
||||
@@ -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::{Network, RequestMethod};
|
||||
use anyhow::Result;
|
||||
@@ -41,6 +41,21 @@ impl Network<'_, '_> {
|
||||
.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(
|
||||
&mut self,
|
||||
) -> Result<SystemStatus> {
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
mod tests {
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
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::readarr_network::ReadarrEvent;
|
||||
use chrono::DateTime;
|
||||
@@ -141,6 +144,63 @@ mod tests {
|
||||
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]
|
||||
async fn test_handle_get_readarr_status_event() {
|
||||
let (mock, app, _server) = MockServarrApi::get()
|
||||
|
||||
Reference in new issue
Block a user