superviseur_server/
lib.rs1pub mod control;
2pub mod core;
3pub mod logging;
4pub mod macros;
5pub mod project;
6pub mod server;
7
8pub mod api {
9 #[path = ""]
10 pub mod superviseur {
11 #[path = "superviseur.v1alpha1.rs"]
12 pub mod v1alpha1;
13 }
14 #[path = ""]
15 pub mod objects {
16 use std::collections::HashMap;
17
18 use superviseur_types as types;
19
20 use self::v1alpha1::{Process, Service};
21
22 #[path = "objects.v1alpha1.rs"]
23 pub mod v1alpha1;
24
25 impl Into<types::service::Service> for Service {
26 fn into(self) -> types::service::Service {
27 types::service::Service {
28 id: self.id,
29 name: self.name,
30 status: self.status,
31 depends_on: self.depends_on,
32 command: self.command,
33 r#type: self.r#type,
34 port: Some(self.port as u32),
35 ..Default::default()
36 }
37 }
38 }
39
40 impl From<types::configuration::Service> for Service {
41 fn from(service: types::configuration::Service) -> Self {
42 Self {
43 id: service.id.unwrap_or_default(),
44 name: service.name,
45 depends_on: service.depends_on,
46 command: service.command,
47 r#type: service.r#type,
48 port: service.port.unwrap_or_default() as i32,
49 ..Default::default()
50 }
51 }
52 }
53
54 impl Into<types::process::Process> for Process {
55 fn into(self) -> types::process::Process {
56 let mut env: HashMap<String, String> = HashMap::new();
57 self.env.iter().for_each(|e| {
58 let mut split = e.split('=');
59 if let Some(key) = split.next() {
60 if let Some(value) = split.next() {
61 env.insert(key.to_string(), value.to_string());
62 }
63 }
64 });
65 types::process::Process {
66 name: self.name,
67 pid: Some(self.pid),
68 command: self.command,
69 up_time: self.up_time.parse().ok(),
70 state: self.state.parse().unwrap_or_default(),
71 description: Some(self.description),
72 working_dir: self.working_directory,
73 project: self.project,
74 r#type: self.r#type,
75 stdout: self.log_file,
76 stderr: self.stderr_file,
77 auto_restart: self.auto_restart,
78 env,
79 service_id: self.service_id,
80 port: Some(self.port as u32),
81 ..Default::default()
82 }
83 }
84 }
85
86 impl From<types::process::Process> for Process {
87 fn from(process: types::process::Process) -> Self {
88 let mut env = vec![];
89 process.env.iter().for_each(|(k, v)| {
90 env.push(format!("{}={}", k, v));
91 });
92 Self {
93 name: process.name,
94 pid: process.pid.unwrap_or_default(),
95 command: process.command,
96 up_time: process.up_time.map(|t| t.to_rfc3339()).unwrap_or_default(),
97 state: process.state.to_string(),
98 description: process.description.unwrap_or_default(),
99 working_directory: process.working_dir,
100 project: process.project,
101 r#type: process.r#type,
102 log_file: process.stdout,
103 stderr_file: process.stderr,
104 auto_restart: process.auto_restart,
105 env,
106 service_id: process.service_id,
107 port: process.port.unwrap_or_default() as i32,
108 ..Default::default()
109 }
110 }
111 }
112 }
113}