1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::{fmt::Debug, sync::Arc};

use super::metrics::{MetricsCollector, NopMetricsCollector};
use crate::environment::TlsConfiguration;

#[derive(Clone)]
pub struct ClientOptions {
    pub(crate) host: String,
    pub(crate) port: u16,
    pub(crate) user: String,
    pub(crate) password: String,
    pub(crate) v_host: String,
    pub(crate) heartbeat: u32,
    pub(crate) max_frame_size: u32,
    pub(crate) tls: TlsConfiguration,
    pub(crate) collector: Arc<dyn MetricsCollector>,
}

impl Debug for ClientOptions {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ClientOptions")
            .field("host", &self.host)
            .field("port", &self.port)
            .field("user", &self.user)
            .field("password", &self.password)
            .field("v_host", &self.v_host)
            .field("heartbeat", &self.heartbeat)
            .field("max_frame_size", &self.max_frame_size)
            .finish()
    }
}
impl Default for ClientOptions {
    fn default() -> Self {
        ClientOptions {
            host: "localhost".to_owned(),
            port: 5552,
            user: "guest".to_owned(),
            password: "guest".to_owned(),
            v_host: "/".to_owned(),
            heartbeat: 60,
            max_frame_size: 1048576,
            collector: Arc::new(NopMetricsCollector {}),
            tls: TlsConfiguration {
                enabled: false,
                trust_certificates: false,
                root_certificates_path: String::from(""),
                client_certificates_path: String::from(""),
                client_keys_path: String::from(""),
            },
        }
    }
}

impl ClientOptions {
    pub fn get_tls(&self) -> TlsConfiguration {
        self.tls.clone()
    }

    pub fn enable_tls(&mut self) {
        self.tls.enable(true);
    }

    pub fn set_port(&mut self, port: u16) {
        self.port = port;
    }
}