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
use std::net::IpAddr;
use super::XMLNS;
use crate::common::{serialize_host_addrs_option, NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction};
use serde::Serialize;
impl<'a> Transaction<NoExtension> for HostUpdate<'a> {}
impl<'a> Command for HostUpdate<'a> {
type Response = ();
const COMMAND: &'static str = "update";
}
impl<'a> HostUpdate<'a> {
pub fn new(name: &'a str) -> Self {
Self {
host: HostUpdateRequestData {
xmlns: XMLNS,
name: name.into(),
add: None,
remove: None,
change_info: None,
},
}
}
pub fn info(&mut self, info: HostChangeInfo<'a>) {
self.host.change_info = Some(info);
}
pub fn add(&mut self, add: HostAddRemove<'a>) {
self.host.add = Some(add);
}
pub fn remove(&mut self, remove: HostAddRemove<'a>) {
self.host.remove = Some(remove);
}
}
#[derive(Serialize, Debug)]
pub struct HostChangeInfo<'a> {
#[serde(rename = "host:name")]
pub name: StringValue<'a>,
}
#[derive(Serialize, Debug)]
pub struct HostAddRemove<'a> {
#[serde(rename = "host:addr", serialize_with = "serialize_host_addrs_option")]
pub addresses: Option<&'a [IpAddr]>,
#[serde(rename = "host:status")]
pub statuses: Option<&'a [ObjectStatus<'a>]>,
}
#[derive(Serialize, Debug)]
pub struct HostUpdateRequestData<'a> {
#[serde(rename = "xmlns:host")]
xmlns: &'a str,
#[serde(rename = "host:name")]
name: StringValue<'a>,
#[serde(rename = "host:add")]
add: Option<HostAddRemove<'a>>,
#[serde(rename = "host:rem")]
remove: Option<HostAddRemove<'a>>,
#[serde(rename = "host:chg")]
change_info: Option<HostChangeInfo<'a>>,
}
#[derive(Serialize, Debug)]
pub struct HostUpdate<'a> {
#[serde(rename = "host:update")]
host: HostUpdateRequestData<'a>,
}
#[cfg(test)]
mod tests {
use super::IpAddr;
use super::{HostAddRemove, HostChangeInfo, HostUpdate};
use crate::common::ObjectStatus;
use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let addr = &[IpAddr::from([
0x2404, 0x6800, 0x4001, 0x801, 0, 0, 0, 0x200e,
])];
let add = HostAddRemove {
addresses: Some(addr),
statuses: None,
};
let statuses = &[ObjectStatus {
status: "clientDeleteProhibited".into(),
}];
let remove = HostAddRemove {
addresses: None,
statuses: Some(statuses),
};
let mut object = HostUpdate::new("host1.eppdev-1.com");
object.add(add);
object.remove(remove);
object.info(HostChangeInfo {
name: "host2.eppdev-1.com".into(),
});
assert_serialized("request/host/update.xml", &object);
}
#[test]
fn response() {
let object = response_from_file::<HostUpdate>("response/host/update.xml");
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
}
}