Skip to main content

idem_handler_config/
execution_flow_config.rs

1use std::collections::HashMap;
2use serde::{Deserialize, Serialize};
3
4#[derive(Deserialize, Serialize, Debug)]
5pub struct ExecutionFlowConfig {
6    pub handlers: Vec<String>,
7    pub chains: HashMap<String, Vec<String>>,
8
9    /// Path keys can be based on different data types. i.e. URL paths, IP, mac addr, RPC paths, etc.
10    /// They hold what handlers should be executed in the 'PrefixConfig' associated.
11    pub paths: HashMap<String, PrefixConfig>,
12}
13
14#[derive(Deserialize, Serialize, Debug)]
15pub struct PrefixConfig {
16    pub method: String,
17    pub exec: Vec<String>
18}
19
20
21#[cfg(test)]
22mod test {
23    use crate::execution_flow_config::ExecutionFlowConfig;
24
25    #[test]
26    fn test_read_execution_path_config() {
27        let test_config_string = r#"
28        {
29            "handlers": [
30                "ProxyHandler",
31                "TraceabilityHandler",
32                "HeaderHandler",
33                "JwtValidationHandler",
34                "MyCustomHandler",
35                "HealthCheckHandler"
36            ],
37            "chains": {
38                "default": [
39                    "TraceabilityHandler",
40                    "JwtValidationHandler",
41                    "HeaderHandler"
42                ]
43            },
44            "paths": {
45                "/some/resource/path": {
46                    "method": "GET",
47                    "exec": [
48                        "default",
49                        "MyCustomHandler",
50                        "ProxyHandler"
51                    ]
52                },
53                "/health": {
54                    "method": "GET",
55                    "exec": [
56                        "default",
57                        "HealthCheckHandler"
58                    ]
59                }
60            }
61        }"#;
62        let my_config = serde_json::from_str::<ExecutionFlowConfig>(test_config_string).unwrap();
63        assert_eq!(my_config.handlers.len(), 6);
64        assert_eq!(my_config.chains.len(), 1);
65        assert_eq!(my_config.paths.len(), 2);
66    }
67}