SaltDns. Registrar. Adapter behaviour
(Salt v1.0.0)
The plug-in point for registrars. An adapter turns Salt's calls (check a
name, register it, renew it, change its name servers) into the calls of one
registrar's API. SaltDns.Registrar.Openprovider is the adapter Salt DNS
ships; another registrar implements this behaviour and is registered by name:
config :salt_dns, SaltDns.Registrar,
adapters: %{"openprovider" => SaltDns.Registrar.Openprovider,
"mine" => MyApp.MyRegistrar}Each SaltDns.Registrar.Provider row names the adapter it uses. Every
callback takes the provider (the account) first.
Rules for adapters
- Money is always
%{minor: integer, currency: "USD"}: integer minor units (cents) and an ISO 4217 code. Read the registrar's decimals withDecimal(seeSaltDns.Registrar.Money); never return a float. - Errors are
{:error, {kind, message}}withkindone of:insufficient_funds(the account cannot pay),:name_unavailable(the name cannot be registered),:invalid(the registrar refused the request as it is),:rate_limited,:registrar_unavailable(network or server trouble: try again later; a buying call that ends like this may or may not have bought),:not_found,:locked(the name is locked or in a state that forbids the change),:unauthorized(the credentials do not work) and:provider(anything else).messageis a short string that never holds credentials, auth codes or personal data. It may instead be a map with a:messageand extras::fields(a map of field errors) for:invalid,:retry_after(seconds) for:rate_limited. - Idempotency. Salt makes a buying call (
register/2,transfer/2,renew/3,restore/2) at most once per operation reference and only after it has re-read the price; an adapter does not retry them itself. Before Salt repeats a call that may have been made, it askslookup/2. - Logging. Never log request or response bodies: they hold personal data and auth codes.
- A domain is addressed by
ref, the registrar's own id as a string.
Summary
Types
The state of a name. :state is :pending when the registrar has taken an
order and not finished (a registration or a transfer that is still running).
:name_servers is nil when the registrar said nothing about them; otherwise
each entry carries the addresses the registrar reported, so that reading a
domain back keeps its glue.
A name server with the glue addresses that belong to it: :name is a host
name, and :ipv4 and :ipv6 are the address texts, either of which may be
nil. Only an in-bailiwick name server (the domain itself or under it) has
glue; Salt validates that before an adapter is called.
What a registration or a transfer needs: :name (the full name, example.org),
:period (years), :owner, :admin, :tech, :billing (contact handles
from put_contact/2), :name_servers (name_server/0 entries, with their
glue), :privacy (boolean), :autorenew (boolean), :auth_code (transfers
only) and :premium_fee (a money map: the premium price the caller accepts,
for premium names). For a transfer, the contact handles are the registrar's.
The price list of an extension for a period. create, renew and
transfer are totals for period years, as the registrar gives them for
that period (never a one-year price multiplied), restore is for one
restore and renew_yearly is the price of renewing for one year (what is
paid each year afterwards). promotion is nil, or %{ends_on, non_promotion}
with non_promotion the price for the same period without the promotion.
Callbacks
The account: balance and reserved balance in minor units, and the currency.
The transfer authorisation code. Treat it as a secret: do not log or store it.
What the adapter supports: operations and limits (a map; keys are up to the adapter).
Whether each name is free, with the price Salt would pay.
The state of the e-mail verification of the registrant contact handle:
%{state: :verified | :pending | :failed | :unknown | :none, status: String.t() | nil}
(status is the registrar's own word; a word the adapter does not know is
:unknown). :none means no verification is known for the contact.
Removes a contact the registrar holds.
The state of the name now.
Looks a name up in the account: {:ok, domain_state} or {:ok, nil} if the
account does not hold it. Salt asks before it repeats a buying call that
may already have gone through.
The price of one operation (:create, :renew, :transfer or :restore)
on one name for period years, with the premium and promotion flags. Salt
calls this just before it buys.
The price list of an extension, such as com or co.uk, for period years.
A period the extension does not allow is {:error, {:invalid, %{message: _, fields: %{"period" => _}}}}.
Creates a contact at the registrar from the registrant's data and returns its handle.
Registers a name.
Renews for period years.
Sends the verification e-mail of the contact again.
Restores a name in its redemption period.
Sets automatic renewal.
Turns DNSSEC on or off. dnssec is %{enabled: boolean, keys: [key]} with
key a map of :flags, :protocol, :alg and :pub_key (the DNSKEY
fields), for registries that take keys.
Sets the transfer lock.
Replaces the name servers, with their glue addresses. An adapter that cannot send glue must say so rather than drop it.
Turns WHOIS privacy (the registrar's own data-protection service) on or off.
A registrar that does not offer it returns {:error, {:invalid, message}}
rather than pretending the change was made.
Starts a transfer of a name in.
Updates the contact the registrar holds under handle with new data.
Types
@type check_result() :: %{ name: String.t(), status: name_status(), cost: money() | nil }
@type domain_state() :: %{ ref: ref(), state: :pending | :active | :expired | :deleted | :failed | :unknown, registered_on: DateTime.t() | nil, expires_at: DateTime.t() | nil, renewal_date: DateTime.t() | nil, autorenew: boolean() | nil, locked: boolean() | nil, privacy: boolean() | nil, name_servers: [name_server()] | nil, dnssec: :enabled | :disabled | :unknown, can_renew: boolean() | nil, restorable_until: DateTime.t() | nil, quarantine_until: DateTime.t() | nil }
The state of a name. :state is :pending when the registrar has taken an
order and not finished (a registration or a transfer that is still running).
:name_servers is nil when the registrar said nothing about them; otherwise
each entry carries the addresses the registrar reported, so that reading a
domain back keeps its glue.
@type money() :: SaltDns.Registrar.Money.amount()
A name server with the glue addresses that belong to it: :name is a host
name, and :ipv4 and :ipv6 are the address texts, either of which may be
nil. Only an in-bailiwick name server (the domain itself or under it) has
glue; Salt validates that before an adapter is called.
@type name_status() :: :free | :taken | :premium | :unavailable
What a registration or a transfer needs: :name (the full name, example.org),
:period (years), :owner, :admin, :tech, :billing (contact handles
from put_contact/2), :name_servers (name_server/0 entries, with their
glue), :privacy (boolean), :autorenew (boolean), :auth_code (transfers
only) and :premium_fee (a money map: the premium price the caller accepts,
for premium names). For a transfer, the contact handles are the registrar's.
@type price_list() :: %{ extension: String.t(), period: pos_integer(), create: money() | nil, renew: money() | nil, transfer: money() | nil, restore: money() | nil, renew_yearly: money() | nil, promotion: %{ends_on: Date.t() | nil, non_promotion: money() | nil} | nil, min_period: pos_integer() | nil, max_period: pos_integer() | nil, privacy_allowed: boolean() | nil, quarantine_days: non_neg_integer() | nil, soft_quarantine_days: non_neg_integer() | nil }
The price list of an extension for a period. create, renew and
transfer are totals for period years, as the registrar gives them for
that period (never a one-year price multiplied), restore is for one
restore and renew_yearly is the price of renewing for one year (what is
paid each year afterwards). promotion is nil, or %{ends_on, non_promotion}
with non_promotion the price for the same period without the promotion.
@type ref() :: String.t()
Callbacks
@callback account(SaltDns.Registrar.Provider.t()) :: {:ok, %{balance: integer(), reserved: integer(), currency: String.t()}} | error()
The account: balance and reserved balance in minor units, and the currency.
@callback auth_code(SaltDns.Registrar.Provider.t(), ref()) :: {:ok, String.t()} | error()
The transfer authorisation code. Treat it as a secret: do not log or store it.
@callback capabilities(SaltDns.Registrar.Provider.t()) :: {:ok, map()} | error()
What the adapter supports: operations and limits (a map; keys are up to the adapter).
@callback check(SaltDns.Registrar.Provider.t(), [String.t()]) :: {:ok, [check_result()]} | error()
Whether each name is free, with the price Salt would pay.
@callback contact_verification(SaltDns.Registrar.Provider.t(), handle :: String.t()) :: {:ok, %{state: atom(), status: String.t() | nil}} | error()
The state of the e-mail verification of the registrant contact handle:
%{state: :verified | :pending | :failed | :unknown | :none, status: String.t() | nil}
(status is the registrar's own word; a word the adapter does not know is
:unknown). :none means no verification is known for the contact.
@callback delete_contact(SaltDns.Registrar.Provider.t(), handle :: String.t()) :: :ok | error()
Removes a contact the registrar holds.
@callback domain(SaltDns.Registrar.Provider.t(), ref()) :: {:ok, domain_state()} | error()
The state of the name now.
@callback lookup(SaltDns.Registrar.Provider.t(), name :: String.t()) :: {:ok, domain_state() | nil} | error()
Looks a name up in the account: {:ok, domain_state} or {:ok, nil} if the
account does not hold it. Salt asks before it repeats a buying call that
may already have gone through.
@callback price( SaltDns.Registrar.Provider.t(), name :: String.t(), operation :: atom(), period :: pos_integer() ) :: {:ok, name_price()} | error()
The price of one operation (:create, :renew, :transfer or :restore)
on one name for period years, with the premium and promotion flags. Salt
calls this just before it buys.
@callback prices( SaltDns.Registrar.Provider.t(), extension :: String.t(), period :: pos_integer() ) :: {:ok, price_list()} | error()
The price list of an extension, such as com or co.uk, for period years.
A period the extension does not allow is {:error, {:invalid, %{message: _, fields: %{"period" => _}}}}.
@callback put_contact(SaltDns.Registrar.Provider.t(), contact :: map()) :: {:ok, handle :: String.t()} | error()
Creates a contact at the registrar from the registrant's data and returns its handle.
@callback register(SaltDns.Registrar.Provider.t(), order()) :: {:ok, domain_state()} | error()
Registers a name.
@callback renew(SaltDns.Registrar.Provider.t(), ref(), period :: pos_integer()) :: {:ok, domain_state()} | error()
Renews for period years.
@callback resend_contact_verification( SaltDns.Registrar.Provider.t(), handle :: String.t() ) :: :ok | error()
Sends the verification e-mail of the contact again.
@callback restore(SaltDns.Registrar.Provider.t(), ref()) :: {:ok, domain_state()} | error()
Restores a name in its redemption period.
@callback set_autorenew(SaltDns.Registrar.Provider.t(), ref(), boolean()) :: :ok | error()
Sets automatic renewal.
@callback set_dnssec(SaltDns.Registrar.Provider.t(), ref(), dnssec :: map()) :: :ok | error()
Turns DNSSEC on or off. dnssec is %{enabled: boolean, keys: [key]} with
key a map of :flags, :protocol, :alg and :pub_key (the DNSKEY
fields), for registries that take keys.
@callback set_lock(SaltDns.Registrar.Provider.t(), ref(), boolean()) :: :ok | error()
Sets the transfer lock.
@callback set_name_servers(SaltDns.Registrar.Provider.t(), ref(), [ name_server() | String.t() ]) :: :ok | error()
Replaces the name servers, with their glue addresses. An adapter that cannot send glue must say so rather than drop it.
@callback set_privacy(SaltDns.Registrar.Provider.t(), ref(), boolean()) :: :ok | error()
Turns WHOIS privacy (the registrar's own data-protection service) on or off.
A registrar that does not offer it returns {:error, {:invalid, message}}
rather than pretending the change was made.
@callback transfer(SaltDns.Registrar.Provider.t(), order()) :: {:ok, domain_state()} | error()
Starts a transfer of a name in.
@callback update_contact( SaltDns.Registrar.Provider.t(), handle :: String.t(), contact :: map() ) :: :ok | error()
Updates the contact the registrar holds under handle with new data.