/ operator / src / configuration.rs
configuration.rs
 1  use std::collections::HashMap;
 2  
 3  static CONSOLE_IMAGE: &str = "quay.io/apibara/sink-console:latest";
 4  static MONGO_IMAGE: &str = "quay.io/apibara/sink-mongo:latest";
 5  static PARQUET_IMAGE: &str = "quay.io/apibara/sink-parquet:latest";
 6  static POSTGRES_IMAGE: &str = "quay.io/apibara/sink-postgres:latest";
 7  static WEBHOOK_IMAGE: &str = "quay.io/apibara/sink-webhook:latest";
 8  
 9  #[derive(Debug, Clone)]
10  pub struct Configuration {
11      /// Sink type to image.
12      pub sinks: HashMap<String, SinkConfiguration>,
13      /// Sink status port.
14      pub status_port: i32,
15      /// Limit the namespace the operator watches.
16      pub namespace: Option<String>,
17  }
18  
19  #[derive(Debug, Clone)]
20  pub struct SinkConfiguration {
21      /// The container image to use for the sink container.
22      pub image: String,
23  }
24  
25  impl Configuration {
26      pub fn with_sinks(&mut self, sinks: HashMap<String, SinkConfiguration>) -> &mut Self {
27          self.sinks = sinks;
28          self
29      }
30  }
31  
32  impl Default for Configuration {
33      fn default() -> Self {
34          let console = SinkConfiguration {
35              image: CONSOLE_IMAGE.to_string(),
36          };
37          let mongo = SinkConfiguration {
38              image: MONGO_IMAGE.to_string(),
39          };
40          let parquet = SinkConfiguration {
41              image: PARQUET_IMAGE.to_string(),
42          };
43          let postgres = SinkConfiguration {
44              image: POSTGRES_IMAGE.to_string(),
45          };
46          let webhook = SinkConfiguration {
47              image: WEBHOOK_IMAGE.to_string(),
48          };
49  
50          let sinks = HashMap::from([
51              ("console".to_string(), console),
52              ("mongo".to_string(), mongo),
53              ("parquet".to_string(), parquet),
54              ("postgres".to_string(), postgres),
55              ("webhook".to_string(), webhook),
56          ]);
57  
58          Configuration {
59              sinks,
60              status_port: 8118,
61              namespace: None,
62          }
63      }
64  }