omni_director/routing/
mod.rs

1//! # Request Routing System
2//!
3//! Handles routing of requests to the appropriate providers and features.
4
5pub mod router;
6pub mod resolver;
7
8pub use router::*;
9pub use resolver::*;
10
11/// Route specification for provider/feature/operation
12#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub struct Route {
14    /// Provider name
15    pub provider: String,
16    /// Feature name
17    pub feature: String,
18    /// Operation name
19    pub operation: String,
20}
21
22impl Route {
23    /// Create a new route
24    pub fn new(provider: String, feature: String, operation: String) -> Self {
25        Self {
26            provider,
27            feature,
28            operation,
29        }
30    }
31    
32    /// Parse route from path
33    /// Example: "virtualbox/vm-management/start-vm" -> Route
34    pub fn from_path(path: &str) -> Result<Self, String> {
35        let parts: Vec<&str> = path.split('/').collect();
36        
37        if parts.len() != 3 {
38            return Err(format!(
39                "Invalid route path '{}'. Expected format: provider/feature/operation",
40                path
41            ));
42        }
43        
44        Ok(Self {
45            provider: parts[0].to_string(),
46            feature: parts[1].to_string(),
47            operation: parts[2].to_string(),
48        })
49    }
50    
51    /// Convert route to path
52    pub fn to_path(&self) -> String {
53        format!("{}/{}/{}", self.provider, self.feature, self.operation)
54    }
55    
56    /// Convert route to URL path
57    pub fn to_url_path(&self) -> String {
58        format!("/providers/{}/features/{}/operations/{}", 
59                self.provider, self.feature, self.operation)
60    }
61}
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_route_from_path() {
69        let route = Route::from_path("virtualbox/vm-management/start-vm").unwrap();
70        assert_eq!(route.provider, "virtualbox");
71        assert_eq!(route.feature, "vm-management");
72        assert_eq!(route.operation, "start-vm");
73    }
74
75    #[test]
76    fn test_route_to_path() {
77        let route = Route::new(
78            "virtualbox".to_string(),
79            "vm-management".to_string(),
80            "start-vm".to_string(),
81        );
82        assert_eq!(route.to_path(), "virtualbox/vm-management/start-vm");
83    }
84
85    #[test]
86    fn test_route_to_url_path() {
87        let route = Route::new(
88            "virtualbox".to_string(),
89            "vm-management".to_string(),
90            "start-vm".to_string(),
91        );
92        assert_eq!(
93            route.to_url_path(),
94            "/providers/virtualbox/features/vm-management/operations/start-vm"
95        );
96    }
97}