kuma_client/
config.rs

1use crate::deserialize::DeserializeVecLenient;
2use serde::{Deserialize, Serialize};
3use serde_alias::serde_alias;
4use serde_inline_default::serde_inline_default;
5use serde_with::{formats::CommaSeparator, serde_as, PickFirst, StringWithSeparator};
6use url::Url;
7
8/// TLS Configuration for the [Client](crate::Client).
9#[serde_alias(ScreamingSnakeCase)]
10#[serde_inline_default]
11#[serde_as]
12#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
13pub struct TlsConfig {
14    /// Whether to verify the TLS certificate or not.
15    ///
16    /// Defaults to `true`.
17    ///
18    /// # Warning
19    ///
20    /// You should think very carefully before using this method. If
21    /// invalid certificates are trusted, *any* certificate for *any* site
22    /// will be trusted for use. This includes expired certificates. This
23    /// introduces significant vulnerabilities, and should only be used
24    /// as a last resort.
25    #[serde_inline_default(true)]
26    pub verify: bool,
27
28    /// The path to a custom tls certificate in PEM format.
29    ///
30    /// This can be used to connect to a server that has a self-signed
31    /// certificate for example.
32    #[serde(default)]
33    pub cert: Option<String>,
34}
35
36/// Configuration for the [Client](crate::Client).
37#[serde_alias(ScreamingSnakeCase)]
38#[serde_inline_default]
39#[serde_as]
40#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
41pub struct Config {
42    /// The URL for connecting to Uptime Kuma.
43    pub url: Url,
44
45    /// The username for logging into Uptime Kuma (required unless auth is disabled).                      .
46    pub username: Option<String>,
47
48    /// The password for logging into Uptime Kuma (required unless auth is disabled).
49    pub password: Option<String>,
50
51    /// The MFA token for logging into Uptime Kuma (required if MFA is enabled).
52    pub mfa_token: Option<String>,
53
54    /// The MFA secret. Used to generate a tokens for logging into Uptime Kuma (alternative to a single_use mfa_token).
55    pub mfa_secret: Option<String>,
56
57    /// JWT Auth token received after a succesfull login, can be used to as an alternative to username/password.
58    pub auth_token: Option<String>,
59
60    /// List of HTTP headers to send when connecting to Uptime Kuma.
61    #[serde_as(
62        as = "PickFirst<(DeserializeVecLenient<String>, StringWithSeparator::<CommaSeparator, String>)>"
63    )]
64    #[serde(default)]
65    pub headers: Vec<String>,
66
67    /// The timeout for the initial connection to Uptime Kuma.
68    #[serde_inline_default(30.0)]
69    pub connect_timeout: f64,
70
71    /// The timeout for executing calls to the Uptime Kuma server.
72    #[serde_inline_default(30.0)]
73    pub call_timeout: f64,
74
75    /// TLS Configuration for the [Client](crate::Client).
76    pub tls: TlsConfig,
77}
78
79impl Default for Config {
80    fn default() -> Self {
81        Self {
82            url: Url::parse("http://localhost:3001").unwrap(),
83            username: None,
84            password: None,
85            mfa_token: None,
86            mfa_secret: None,
87            auth_token: None,
88            headers: Vec::new(),
89            connect_timeout: 30.0,
90            call_timeout: 30.0,
91            tls: TlsConfig::default(),
92        }
93    }
94}