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
use super::super::tmch::{
TrexActivateRequest, TrexActivateResponse, TrexInfo, TrexRenewRequest, TrexRenewResponse,
TrexTLD,
};
use super::super::{Error, Response};
use super::router::HandleReqReturn;
use super::tmch_proto;
use std::convert::TryInto;
impl From<tmch_proto::trex::TrexInfo> for TrexInfo {
fn from(from: tmch_proto::trex::TrexInfo) -> Self {
TrexInfo {
enabled: from.enable,
until: from.until,
tlds: from.tlds.into_iter().map(Into::into).collect(),
}
}
}
impl From<tmch_proto::trex::TLDInfo> for TrexTLD {
fn from(from: tmch_proto::trex::TLDInfo) -> Self {
TrexTLD {
tld: from.tld,
comment: from.comment,
status: from.status.into(),
}
}
}
pub fn handle_trex_activate(
_client: &(),
req: &TrexActivateRequest,
) -> HandleReqReturn<TrexActivateResponse> {
super::mark::check_mark_id(&req.id)?;
let command = tmch_proto::TMCHUpdate {
id: req.id.clone(),
case: None,
add: None,
remove: None,
change: Some(tmch_proto::TMCHChange {
mark: None,
labels: req
.labels
.iter()
.map(|l| {
Ok(tmch_proto::TMCHLabel {
label: l.label.clone(),
smd_inclusion: None,
claims_notify: None,
trex_activate: Some(tmch_proto::trex::Activate {
period: match l.period.as_ref() {
Some(r) => Some(r.try_into().map_err(Result::Err)?),
None => None,
},
}),
trex_renew: None,
})
})
.collect::<Result<Vec<_>, _>>()?,
case: None,
}),
};
Ok(tmch_proto::TMCHCommandType::Update(Box::new(command)))
}
pub fn handle_trex_activate_response(
response: tmch_proto::TMCHResponse,
) -> Response<TrexActivateResponse> {
match response.data {
Some(_) => Err(Error::ServerInternal),
None => Response::Ok(TrexActivateResponse {}),
}
}
pub fn handle_trex_renew(
_client: &(),
req: &TrexRenewRequest,
) -> HandleReqReturn<TrexRenewResponse> {
super::mark::check_mark_id(&req.id)?;
let command = tmch_proto::TMCHUpdate {
id: req.id.clone(),
case: None,
add: None,
remove: None,
change: Some(tmch_proto::TMCHChange {
mark: None,
labels: req
.labels
.iter()
.map(|l| {
Ok(tmch_proto::TMCHLabel {
label: l.label.clone(),
smd_inclusion: None,
claims_notify: None,
trex_activate: None,
trex_renew: Some(tmch_proto::trex::Renew {
current_expiry_date: l.current_expiry_date,
period: match l.period.as_ref() {
Some(r) => Some(r.try_into().map_err(Result::Err)?),
None => None,
},
}),
})
})
.collect::<Result<Vec<_>, _>>()?,
case: None,
}),
};
Ok(tmch_proto::TMCHCommandType::Update(Box::new(command)))
}
pub fn handle_trex_renew_response(
response: tmch_proto::TMCHResponse,
) -> Response<TrexRenewResponse> {
match response.data {
Some(_) => Err(Error::ServerInternal),
None => Response::Ok(TrexRenewResponse {}),
}
}