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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use serde_derive::*;
use super::Command;
#[derive(Clone, Debug, Eq, Deserialize, Hash, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientRecord {
#[serde(rename = "id")]
pub id: String,
pub name: String,
#[serde(default, rename = "type")]
pub typ: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub commands: Vec<CommandRecord>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub fxa_device_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub protocols: Vec<String>,
#[serde(
default,
rename = "formfactor",
skip_serializing_if = "Option::is_none"
)]
pub form_factor: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub os: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub app_package: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub application: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub device: Option<String>,
#[serde(default)]
pub ttl: u32,
}
#[derive(Clone, Debug, Eq, Deserialize, Hash, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CommandRecord {
#[serde(rename = "command")]
pub name: String,
#[serde(default)]
pub args: Vec<String>,
#[serde(default, rename = "flowID", skip_serializing_if = "Option::is_none")]
pub flow_id: Option<String>,
}
impl CommandRecord {
pub fn as_command(&self) -> Option<Command> {
match self.name.as_str() {
"wipeEngine" => self.args.get(0).map(|e| Command::Wipe(e.into())),
"wipeAll" => Some(Command::WipeAll),
"resetEngine" => self.args.get(0).map(|e| Command::Reset(e.into())),
"resetAll" => Some(Command::ResetAll),
_ => None,
}
}
}
impl From<Command> for CommandRecord {
fn from(command: Command) -> CommandRecord {
match command {
Command::Wipe(engine) => CommandRecord {
name: "wipeEngine".into(),
args: vec![engine],
flow_id: None,
},
Command::WipeAll => CommandRecord {
name: "wipeAll".into(),
args: Vec::new(),
flow_id: None,
},
Command::Reset(engine) => CommandRecord {
name: "resetEngine".into(),
args: vec![engine],
flow_id: None,
},
Command::ResetAll => CommandRecord {
name: "resetAll".into(),
args: Vec::new(),
flow_id: None,
},
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use sync15_traits::Payload;
#[test]
fn test_ttl() {
let record = ClientRecord {
id: "id".into(),
name: "my device".into(),
typ: Some("type".into()),
commands: Vec::new(),
fxa_device_id: Some("12345".into()),
version: None,
protocols: vec!["1.5".into()],
form_factor: None,
os: None,
app_package: None,
application: None,
device: None,
ttl: 123,
};
let p = Payload::from_record(record).unwrap();
let bso = crate::CleartextBso::from_payload(p, "clients");
assert_eq!(bso.ttl, Some(123));
}
}