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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//! EPP commands relating to host (nameserver) objects

use super::{CommandResponse, RequestMessage, Sender};
use chrono::prelude::*;

#[derive(Debug)]
pub struct CheckRequest {
    pub(super) name: String,
    pub return_path: Sender<CheckResponse>,
}

#[derive(Debug)]
pub struct CheckResponse {
    pub avail: bool,
    pub reason: Option<String>,
}

#[derive(Debug)]
pub struct InfoRequest {
    pub(super) name: String,
    pub return_path: Sender<InfoResponse>,
}

#[derive(Debug)]
pub struct InfoResponse {
    pub name: String,
    pub registry_id: String,
    pub statuses: Vec<Status>,
    pub addresses: Vec<Address>,
    pub client_id: String,
    pub client_created_id: Option<String>,
    pub creation_date: Option<DateTime<Utc>>,
    pub last_updated_client: Option<String>,
    pub last_updated_date: Option<DateTime<Utc>>,
    pub last_transfer_date: Option<DateTime<Utc>>,
}

#[derive(Debug)]
pub struct Address {
    pub address: String,
    pub ip_version: AddressVersion,
}

#[derive(Debug)]
pub enum AddressVersion {
    IPv4,
    IPv6,
}

#[derive(Debug)]
pub struct CreateRequest {
    pub(super) name: String,
    pub(super) addresses: Vec<Address>,
    pub(super) isnic_info: Option<super::isnic::HostInfo>,
    pub return_path: Sender<CreateResponse>,
}

#[derive(Debug)]
pub struct CreateResponse {
    pub name: String,
    pub pending: bool,
    pub transaction_id: String,
    pub creation_date: Option<DateTime<Utc>>,
}

#[derive(Debug)]
pub struct DeleteRequest {
    pub(super) name: String,
    pub return_path: Sender<DeleteResponse>,
}

#[derive(Debug)]
pub struct DeleteResponse {
    pub pending: bool,
    pub transaction_id: String,
}

#[derive(Debug)]
pub struct UpdateRequest {
    pub(super) name: String,
    pub(super) add: Vec<UpdateObject>,
    pub(super) remove: Vec<UpdateObject>,
    pub(super) new_name: Option<String>,
    pub(super) isnic_info: Option<super::isnic::HostInfo>,
    pub return_path: Sender<UpdateResponse>,
}

#[derive(Debug)]
pub enum UpdateObject {
    Address(Address),
    Status(Status),
}

#[derive(Debug)]
pub struct UpdateResponse {
    pub pending: bool,
    pub transaction_id: String,
}

#[derive(Debug)]
pub enum Status {
    ClientDeleteProhibited,
    ClientUpdateProhibited,
    Linked,
    Ok,
    PendingCreate,
    PendingDelete,
    PendingTransfer,
    PendingUpdate,
    ServerDeleteProhibited,
    ServerUpdateProhibited,
}

pub async fn check(
    host: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<CheckResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::HostCheck(Box::new(CheckRequest {
            name: host.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

pub async fn info(
    host: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<InfoResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::HostInfo(Box::new(InfoRequest {
            name: host.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

pub async fn create(
    host: &str,
    addresses: Vec<Address>,
    isnic_info: Option<super::isnic::HostInfo>,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<CreateResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::HostCreate(Box::new(CreateRequest {
            name: host.to_string(),
            addresses,
            isnic_info,
            return_path: sender,
        })),
        receiver,
    )
    .await
}

pub async fn delete(
    host: &str,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<DeleteResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::HostDelete(Box::new(DeleteRequest {
            name: host.to_string(),
            return_path: sender,
        })),
        receiver,
    )
    .await
}

pub async fn update<N: Into<Option<String>>>(
    host: &str,
    add: Vec<UpdateObject>,
    remove: Vec<UpdateObject>,
    new_name: N,
    isnic_info: Option<super::isnic::HostInfo>,
    client_sender: &mut futures::channel::mpsc::Sender<RequestMessage>,
) -> Result<CommandResponse<UpdateResponse>, super::Error> {
    let (sender, receiver) = futures::channel::oneshot::channel();
    super::send_epp_client_request(
        client_sender,
        RequestMessage::HostUpdate(Box::new(UpdateRequest {
            name: host.to_string(),
            add,
            remove,
            new_name: new_name.into(),
            isnic_info,
            return_path: sender,
        })),
        receiver,
    )
    .await
}