Rust

registrar

Module

Domain registrars: search, price, buy, renew and transfer domains through an Adapter (Mock, NameCom, OpenSrs), driven by a Registrar.

Contents

4 submodules, and what the module defines itself.

use utopia_domains::registrar::Config;
Rust
pub struct Config

The settings a Registrar passes its adapter on every call.

Also implements Default.
use utopia_domains::registrar::Contact;
Rust
pub struct Contact

A contact of a domain registration (owner, admin, tech or billing).

Rust
use utopia_domains::registrar::Contact;

let contact = Contact { firstname: "Ada".into(), lastname: "Lovelace".into(), ..Contact::default() };
assert_eq!(contact.owner(), "Ada Lovelace");
use utopia_domains::registrar::Contacts;
Rust
pub struct Contacts(pub Vec<(ContactKey, Contact)>)

The contacts of a registration: one contact for every role, a list, or contacts by role.

Rust
use utopia_domains::registrar::{Contact, Contacts};

let contact = Contact { firstname: "Ada".into(), ..Contact::default() };
let one = Contacts::from(contact.clone());
let by_role = Contacts::from_iter([("owner", contact.clone()), ("admin", contact)]);
assert_eq!((one.len(), by_role.len()), (1, 2));
Also implements From, FromIterator.
use utopia_domains::Domain;
Rust
pub struct Domain

A registered domain.

use utopia_domains::registrar::NameserverUpdate;
Rust
pub struct NameserverUpdate

The outcome of a nameserver change. Each registrar reports a different subset of the fields.

use utopia_domains::registrar::Price;
Rust
pub struct Price

A price quote.

use utopia_domains::registrar::Purchase;
Rust
pub struct Purchase

A domain to buy, with the details of the registration.

use utopia_domains::registrar::Registrar;
Rust
pub struct Registrar<A>

A registrar: an Adapter with its settings.

Rust
use utopia_domains::registrar::{Contact, Mock, Purchase, RegType, Registrar};

let registrar = Registrar::new(Mock::new());
tokio::runtime::Runtime::new()?.block_on(async {
    let availability = registrar.available(&["my-app.com".to_owned(), "google.com".to_owned()]).await?;
    assert_eq!(availability["my-app.com"], true);
    assert_eq!(availability["google.com"], false);

    let price = registrar.price("my-app.com", 1, RegType::New, 3600).await?;
    assert_eq!(price.price, 12.99);
    Ok::<_, utopia_domains::Error>(())
})?;
use utopia_domains::registrar::Renewal;
Rust
pub struct Renewal

The outcome of a renewal.

use utopia_domains::registrar::Suggestion;
Rust
pub struct Suggestion

One suggested domain.

use utopia_domains::registrar::SuggestOptions;
Rust
pub struct SuggestOptions

What Adapter::suggest looks for besides the query.

use utopia_domains::registrar::TransferStatus;
Rust
pub struct TransferStatus

The status of a transfer.

use utopia_domains::registrar::UpdateDetails;
Rust
pub struct UpdateDetails

What to change on a domain. Adapters refuse details without auto_renew.

use utopia_domains::registrar::ContactKey;
Rust
pub enum ContactKey

Where a contact sits in [Contacts]: a position or a role (owner, admin, tech, billing, registrant).

use utopia_domains::registrar::RegType;
Rust
pub enum RegType

The kind of registration a price is for.

use utopia_domains::registrar::SuggestionKind;
Rust
pub enum SuggestionKind

What kind of domain a suggestion is.

use utopia_domains::registrar::TransferState;
Rust
pub enum TransferState

Where a transfer stands.

use utopia_domains::registrar::Adapter;
Rust
pub trait Adapter: Send + Sync

A registrar API. Implement it to add a registrar.

Implemented byMockNameComOpenSrs
Rust
pub type Availability = IndexMap<String, bool>

Availability of each domain asked about, in the order asked.

Rust
pub type Suggestions = IndexMap<String, Suggestion>

Suggested domains, in the order the registrar ranked them.

registrar::mock

Own page

An in-memory registrar for tests.

use utopia_domains::registrar::mock::Mock;
Rust
pub struct Mock

A registrar that keeps its registry in memory: google.com, facebook.com and amazon.com are taken, com, net, org, io, dev and app are sold at the default price, a few domains are premium, and purchases and transfers are remembered.

Rust
use utopia_domains::registrar::{Contact, Mock, Purchase, Registrar};

let contact = Contact {
    firstname: "Ada".into(), lastname: "Lovelace".into(), phone: "+18031234567".into(),
    email: "ada@example.com".into(), address1: "1 Main St".into(), city: "London".into(),
    state: "LDN".into(), country: "GB".into(), postalcode: "N1".into(), ..Contact::default()
};
let registrar = Registrar::new(Mock::new());
tokio::runtime::Runtime::new()?.block_on(async {
    let order = registrar.purchase(&Purchase::new("my-app.com", contact)).await?;
    assert!(order.starts_with("mock_"));
    assert_eq!(registrar.adapter().purchased(), ["my-app.com"]);
    Ok::<_, utopia_domains::Error>(())
})?;
Also implements Default.

registrar::namecom

Own page

The Name.com registrar, over its Core API.

use utopia_domains::registrar::namecom::NameCom;
Rust
pub struct NameCom

The Name.com registrar, over its Core API with HTTP basic authentication.

Availability is asked 50 domains per request; each answer carries the prices too, so with a cache a following Adapter::price for the same domain needs no request.

Rust
use std::sync::Arc;
use utopia_domains::registrar::{NameCom, Registrar};
use utopia_domains::transport::{Request, Response, Transport, TransportError};
use utopia_domains::BoxFuture;

/// Answers every request with the same recorded response.
struct Recorded(&'static str);

impl Transport for Recorded {
    fn send<'a>(&'a self, request: Request) -> BoxFuture<'a, Result<Response, TransportError>> {
        assert_eq!(request.url, "https://api.name.com/core/v1/domains/example.com:getAuthCode");
        Box::pin(async move { Ok(Response { status: 200, headers: vec![], body: self.0.into() }) })
    }
}

let adapter = NameCom::new("user", "token", "api.name.com", Some(Arc::new(Recorded(r#"{"authCode":"x1y2"}"#))));
let registrar = Registrar::new(adapter);
let code = tokio::runtime::Runtime::new()?.block_on(registrar.auth_code("example.com"))?;
assert_eq!(code, "x1y2");
Also implements Debug.

registrar::opensrs

Own page

The OpenSRS registrar, over its XML API (XCP envelopes over HTTPS).

use utopia_domains::registrar::opensrs::OpenSrs;
Rust
pub struct OpenSrs

The OpenSRS registrar: XCP messages signed with the reseller API key.

Rust
use std::sync::Arc;
use utopia_domains::registrar::{OpenSrs, Registrar};
use utopia_domains::transport::{Request, Response, Transport, TransportError};
use utopia_domains::BoxFuture;

/// Answers every lookup with "available".
struct Recorded;

impl Transport for Recorded {
    fn send<'a>(&'a self, request: Request) -> BoxFuture<'a, Result<Response, TransportError>> {
        assert!(request.header("X-Signature").is_some());
        let body = "<OPS_envelope><body><data_block><dt_assoc>\
            <item key=\"response_code\">210</item></dt_assoc></data_block></body></OPS_envelope>";
        Box::pin(async move { Ok(Response { status: 200, headers: vec![], body: body.into() }) })
    }
}

let adapter = OpenSrs::new("key", "reseller", "secret", "horizon.opensrs.net:55443", Some(Arc::new(Recorded)));
let registrar = Registrar::new(adapter);
let availability = tokio::runtime::Runtime::new()?.block_on(registrar.available(&["my-app.net".to_owned()]))?;
assert_eq!(availability["my-app.net"], true);
Also implements Debug.

registrar::xml

Own page

The XML OpenSRS answers in: a document of elements with attributes and text, queried with the location paths the adapter uses (//body/data_block/dt_assoc/item[@key="response_code"], dt_assoc/item, unions with |).