1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::Result;
use std::path::Path;
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum DependencyProtocol {
Http,
Grpc,
Kafka,
Amqp,
Sqs,
}
impl Default for DependencyProtocol {
fn default() -> DependencyProtocol {
DependencyProtocol::Http
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "filesystem", serde(deny_unknown_fields))]
pub struct Dependency {
pub name: String,
#[serde(default = "default_api_version")]
pub api: String,
pub contract: Option<String>,
#[serde(default)]
pub protocol: DependencyProtocol,
pub intent: Option<String>,
}
fn default_api_version() -> String {
"v1".into()
}
impl Dependency {
pub fn verify(&self) -> Result<()> {
let dpth = Path::new(".").join("services").join(self.name.clone());
if !dpth.is_dir() {
bail!("Service {} does not exist in services/", self.name);
}
if self.api != "" {
let vstr = self.api.chars().skip_while(|ch| *ch == 'v').collect::<String>();
let ver: usize = vstr.parse()?;
trace!(
"Parsed api version of dependency {} as {}",
self.name.clone(),
ver
);
}
Ok(())
}
}