slim_controller/
config.rs1use std::sync::Arc;
5
6use serde::Deserialize;
7
8use slim_config::component::configuration::{Configuration, ConfigurationError};
9use slim_config::component::id::ID;
10use slim_config::grpc::client::ClientConfig;
11use slim_config::grpc::server::ServerConfig;
12use slim_datapath::message_processing::MessageProcessor;
13
14use crate::service::ControlPlane;
15
16#[derive(Debug, Clone, Deserialize, Default)]
18pub struct Config {
19 #[serde(default)]
21 pub servers: Vec<ServerConfig>,
22
23 #[serde(default)]
25 pub clients: Vec<ClientConfig>,
26}
27
28impl Config {
29 pub fn new() -> Self {
31 Self::default()
32 }
33
34 pub fn with_servers(self, servers: Vec<ServerConfig>) -> Self {
36 Self { servers, ..self }
37 }
38
39 pub fn with_clients(self, clients: Vec<ClientConfig>) -> Self {
41 Self { clients, ..self }
42 }
43
44 pub fn servers(&self) -> &[ServerConfig] {
46 &self.servers
47 }
48 pub fn clients(&self) -> &[ClientConfig] {
50 &self.clients
51 }
52
53 pub fn into_service(
55 &self,
56 id: ID,
57 rx_drain: drain::Watch,
58 message_processor: Arc<MessageProcessor>,
59 ) -> ControlPlane {
60 ControlPlane::new(
61 id,
62 self.servers.clone(),
63 self.clients.clone(),
64 rx_drain,
65 message_processor,
66 )
67 }
68}
69
70impl Configuration for Config {
71 fn validate(&self) -> Result<(), ConfigurationError> {
72 for server in self.servers.iter() {
74 server.validate()?;
75 }
76
77 for client in &self.clients {
78 client.validate()?;
79 }
80
81 Ok(())
82 }
83}