Move domain-related types from common to domain

This commit is contained in:
Dirkjan Ochtman 2021-12-09 12:37:04 +01:00 committed by masalachai
parent 2ac3a6398d
commit defd7cff9b
7 changed files with 107 additions and 108 deletions

View File

@ -119,78 +119,6 @@ impl HostAddr {
}
}
/// The <hostAttr> type for domain transactions
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAttr {
/// The <hostName> tag
#[serde(rename = "domain:hostName", alias = "hostName")]
pub name: StringValue,
/// The <hostAddr> tags
#[serde(rename = "domain:hostAddr", alias = "hostAddr")]
pub addresses: Option<Vec<HostAddr>>,
}
/// Enum that can accept one type which corresponds to either the &lt;hostObj&gt; or &lt;hostAttr&gt;
/// list of tags
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum HostList {
HostObjList(HostObjList),
HostAttrList(HostAttrList),
}
/// The list of &lt;hostAttr&gt; types for domain transactions. Typically under an &lt;ns&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAttrList {
/// The list of &lt;hostAttr&gt; tags
#[serde(rename = "domain:hostAttr", alias = "hostAttr")]
pub hosts: Vec<HostAttr>,
}
/// The list of &lt;hostObj&gt; types for domain transactions. Typically under an &lt;ns&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostObjList {
/// The list of &lt;hostObj&gt; tags
#[serde(rename = "domain:hostObj", alias = "hostObj")]
pub hosts: Vec<StringValue>,
}
/// The &lt;contact&gt; type on domain creation and update requests
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainContact {
/// The contact id
#[serde(rename = "$value")]
pub id: String,
/// The contact type attr (usually admin, billing, or tech in most registries)
#[serde(rename = "type")]
pub contact_type: String,
}
/// The &lt;period&gt; type for registration, renewal or transfer on domain transactions
#[derive(Serialize, Deserialize, Debug)]
pub struct Period {
/// The interval (usually 'y' indicating years)
unit: String,
/// The length of the registration, renewal or transfer period (usually in years)
#[serde(rename = "$value")]
length: u16,
}
impl Period {
/// Creates a new period in years
pub fn new(length: u16) -> Period {
Period {
unit: "y".to_string(),
length,
}
}
/// Sets the period unit ('y' for years, most commonly)
pub fn set_unit(&mut self, unit: &str) {
self.unit = unit.to_string();
}
}
/// The &lt;status&gt; type on contact transactions
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactStatus {
@ -266,14 +194,6 @@ pub struct PostalInfo {
pub address: Address,
}
/// The &lt;authInfo&gt; tag for domain and contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DomainAuthInfo {
/// The &lt;pw&gt; tag under &lt;authInfo&gt;
#[serde(rename = "domain:pw", alias = "pw")]
pub password: StringValue,
}
/// The &lt;authInfo&gt; tag for domain and contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ContactAuthInfo {
@ -297,15 +217,6 @@ impl Phone {
}
}
impl DomainAuthInfo {
/// Creates a DomainAuthInfo instance with the given password
pub fn new(password: &str) -> DomainAuthInfo {
DomainAuthInfo {
password: password.into(),
}
}
}
impl ContactAuthInfo {
/// Creates a ContactAuthInfo instance with the given password
pub fn new(password: &str) -> ContactAuthInfo {

View File

@ -1,3 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::common::{HostAddr, StringValue};
pub mod check;
pub mod create;
pub mod delete;
@ -8,4 +12,91 @@ pub mod update;
pub const XMLNS: &str = "urn:ietf:params:xml:ns:domain-1.0";
/// The &lt;hostAttr&gt; type for domain transactions
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAttr {
/// The &lt;hostName&gt; tag
#[serde(rename = "domain:hostName", alias = "hostName")]
pub name: StringValue,
/// The &lt;hostAddr&gt; tags
#[serde(rename = "domain:hostAddr", alias = "hostAddr")]
pub addresses: Option<Vec<HostAddr>>,
}
/// The list of &lt;hostAttr&gt; types for domain transactions. Typically under an &lt;ns&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostAttrList {
/// The list of &lt;hostAttr&gt; tags
#[serde(rename = "domain:hostAttr", alias = "hostAttr")]
pub hosts: Vec<HostAttr>,
}
/// The list of &lt;hostObj&gt; types for domain transactions. Typically under an &lt;ns&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostObjList {
/// The list of &lt;hostObj&gt; tags
#[serde(rename = "domain:hostObj", alias = "hostObj")]
pub hosts: Vec<StringValue>,
}
/// Enum that can accept one type which corresponds to either the &lt;hostObj&gt; or &lt;hostAttr&gt;
/// list of tags
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum HostList {
HostObjList(HostObjList),
HostAttrList(HostAttrList),
}
/// The &lt;contact&gt; type on domain creation and update requests
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainContact {
/// The contact id
#[serde(rename = "$value")]
pub id: String,
/// The contact type attr (usually admin, billing, or tech in most registries)
#[serde(rename = "type")]
pub contact_type: String,
}
/// The &lt;period&gt; type for registration, renewal or transfer on domain transactions
#[derive(Serialize, Deserialize, Debug)]
pub struct Period {
/// The interval (usually 'y' indicating years)
unit: String,
/// The length of the registration, renewal or transfer period (usually in years)
#[serde(rename = "$value")]
length: u16,
}
impl Period {
/// Creates a new period in years
pub fn new(length: u16) -> Period {
Period {
unit: "y".to_string(),
length,
}
}
/// Sets the period unit ('y' for years, most commonly)
pub fn set_unit(&mut self, unit: &str) {
self.unit = unit.to_string();
}
}
/// The &lt;authInfo&gt; tag for domain and contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DomainAuthInfo {
/// The &lt;pw&gt; tag under &lt;authInfo&gt;
#[serde(rename = "domain:pw", alias = "pw")]
pub password: StringValue,
}
impl DomainAuthInfo {
/// Creates a DomainAuthInfo instance with the given password
pub fn new(password: &str) -> DomainAuthInfo {
DomainAuthInfo {
password: password.into(),
}
}
}

View File

@ -1,8 +1,9 @@
//! Types for EPP domain create request
use super::XMLNS;
use crate::common::{DomainAuthInfo, DomainContact, HostList, NoExtension, Period, StringValue};
use super::{DomainAuthInfo, DomainContact, HostList, Period, XMLNS};
use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl Transaction<NoExtension> for DomainCreate {}
@ -102,10 +103,9 @@ pub struct DomainCreateResponse {
#[cfg(test)]
mod tests {
use super::DomainCreate;
use crate::common::{
DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList, NoExtension,
};
use super::{DomainContact, DomainCreate, HostList};
use crate::common::{HostAddr, NoExtension};
use crate::domain::{HostAttr, HostAttrList, HostObjList};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};

View File

@ -1,9 +1,7 @@
//! Types for EPP domain info request
use super::XMLNS;
use crate::common::{
DomainAuthInfo, DomainContact, DomainStatus, HostAttr, NoExtension, StringValue,
};
use super::{DomainAuthInfo, DomainContact, HostAttr, XMLNS};
use crate::common::{DomainStatus, NoExtension, StringValue};
use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
//! Types for EPP domain renew request
use super::XMLNS;
use crate::common::{NoExtension, Period, StringValue};
use super::{Period, XMLNS};
use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
//! Types for EPP domain transfer request
use super::XMLNS;
use crate::common::{DomainAuthInfo, NoExtension, Period, StringValue};
use super::{DomainAuthInfo, Period, XMLNS};
use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};

View File

@ -1,12 +1,11 @@
//! Types for EPP domain check request
//!
use super::{DomainAuthInfo, DomainContact, HostList, XMLNS};
use crate::{
common::{DomainAuthInfo, DomainContact, DomainStatus, HostList, NoExtension, StringValue},
common::{DomainStatus, NoExtension, StringValue},
request::{Command, Transaction},
};
use super::XMLNS;
use serde::Serialize;
impl Transaction<NoExtension> for DomainUpdate {}
@ -102,8 +101,8 @@ pub struct DomainUpdate {
#[cfg(test)]
mod tests {
use super::{DomainAddRemove, DomainChangeInfo, DomainUpdate};
use crate::common::{DomainAuthInfo, DomainContact, DomainStatus, NoExtension};
use super::{DomainAddRemove, DomainAuthInfo, DomainChangeInfo, DomainContact, DomainUpdate};
use crate::common::{DomainStatus, NoExtension};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};