cljs / src / ird / dns.cljs
906 words
  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
(ns ird.dns
  "Hosted DNS: put registered domains on ird nameservers, manage the hosted
  zones' records, DNSSEC and nameserver set, and bring domains held at other
  registrars onto ird DNS through claims. Mutations are subject to the
  client's domain gate (ird.gate) when configured. Every function returns a
  channel (see ird.async)."
  (:require [ird.async :refer [go-try <?]]
            [ird.gate :as gate]
            [ird.transport :as transport]))

;; ---------------------------------------------------------------------------
;; Hosting registered domains

(defn enable-hosting
  "POST /domains/registrations/{id}/dns — Put a domain on ird nameservers
  (202). Optional BODY keys include :records, :default_ttl,
  :apply_registry_ns, :totp_code."
  ([client id] (enable-hosting client id nil))
  ([client id body]
   (gate/request client "POST /domains/registrations/{id}/dns" {:registration-id id}
                 :post ["domains" "registrations" id "dns"] (when body {:body body}))))

(defn disable-hosting
  "DELETE /domains/registrations/{id}/dns — Take a domain off ird DNS.
  Optional BODY carries :totp_code."
  ([client id] (disable-hosting client id nil))
  ([client id body]
   (gate/request client "DELETE /domains/registrations/{id}/dns" {:registration-id id}
                 :delete ["domains" "registrations" id "dns"] (when body {:body body}))))

(defn get-dnssec
  "GET /domains/registrations/{id}/dns/dnssec — DNSSEC state of the hosted
  zone."
  [client id]
  (transport/request client :get ["domains" "registrations" id "dns" "dnssec"]))

(defn enable-dnssec
  "POST /domains/registrations/{id}/dns/dnssec — Enable DNSSEC on the
  hosted zone (202). Optional BODY carries :totp_code."
  ([client id] (enable-dnssec client id nil))
  ([client id body]
   (gate/request client "POST /domains/registrations/{id}/dns/dnssec" {:registration-id id}
                 :post ["domains" "registrations" id "dns" "dnssec"] (when body {:body body}))))

(defn disable-dnssec
  "DELETE /domains/registrations/{id}/dns/dnssec — Disable DNSSEC on the
  hosted zone (202). Optional BODY carries :totp_code."
  ([client id] (disable-dnssec client id nil))
  ([client id body]
   (gate/request client "DELETE /domains/registrations/{id}/dns/dnssec" {:registration-id id}
                 :delete ["domains" "registrations" id "dns" "dnssec"] (when body {:body body}))))

(defn hosted-nameservers
  "GET /domains/registrations/{id}/dns/nameservers — The nameserver set the
  hosted zone is published under: :mode \"shared\" (ird's public
  nameservers) or \"labels\" (private nameservers unique to the domain),
  with :nameservers, :nameservers_ready and :available_modes."
  [client id]
  (transport/request client :get ["domains" "registrations" id "dns" "nameservers"]))

(defn set-hosted-nameservers
  "POST /domains/registrations/{id}/dns/nameservers — Move the hosted zone
  between nameserver sets. BODY carries :mode (\"shared\" or \"labels\";
  labels are offered for .ro domains only) and optional :totp_code. Answers
  200 when nothing had to change, 202 with a :registry_action when a
  registrar nameserver change was enqueued — poll `hosted-nameservers` for
  :nameservers_ready. Free."
  [client id body]
  (gate/request client "POST /domains/registrations/{id}/dns/nameservers" {:registration-id id}
                :post ["domains" "registrations" id "dns" "nameservers"] {:body body}))

;; ---------------------------------------------------------------------------
;; Zones and records

(defn list-zones
  "GET /dns/domains — Your hosted DNS domains."
  [client]
  (transport/request client :get "/dns/domains"))

(defn get-zone
  "GET /dns/domains/{domain} — A hosted domain's zone."
  [client domain]
  (transport/request client :get ["dns" "domains" domain]))

(defn set-record
  "PUT /dns/domains/{domain}/records — Set a DNS record or RRset.
  BODY carries :record or :records and optional :totp_code."
  [client domain body]
  (gate/request client "PUT /dns/domains/{domain}/records" {:domain domain}
                :put ["dns" "domains" domain "records"] {:body body}))

(defn delete-record
  "DELETE /dns/domains/{domain}/records — Delete a DNS record.
  BODY keys include :name, :type, :class, :totp_code."
  [client domain body]
  (gate/request client "DELETE /dns/domains/{domain}/records" {:domain domain}
                :delete ["dns" "domains" domain "records"] {:body body}))

;; ---------------------------------------------------------------------------
;; Bring-your-own-domain claims

(defn list-claims
  "GET /dns/claims — Domains you hold at another registrar and host (or are
  about to host) on ird DNS: every live claim plus those ended in the last
  30 days, newest first. Optional QUERY keys: :state (pending / verified /
  active / lapsed / revoked / expired) and :limit (1..500, default 50)."
  ([client] (list-claims client nil))
  ([client query]
   (transport/request client :get "/dns/claims" {:query query})))

(defn create-claim
  "POST /dns/claims — Claim a registrable domain registered elsewhere so ird
  can be its DNS (201). BODY is a plain map with :domain. The response's
  :claim carries the :nameservers to set at your registrar; the claim
  activates once the parent zone lists exactly those (checked every few
  minutes, or now via `verify-claim`). Subject to the client's domain gate
  on :domain."
  [client body]
  (gate/request client "POST /dns/claims" {:domain (:domain body)}
                :post "/dns/claims" {:body body}))

(defn get-claim
  "GET /dns/claims/{id} — A claim: nameservers to set, its window while
  pending, the latest delegation read and registry facts."
  [client id]
  (transport/request client :get ["dns" "claims" id]))

(defn- claim-target
  "Gate target for a claim-addressed mutation: the claim's domain (DNS form),
  resolved through `get-claim`. Called only when the client has a gate."
  [client id]
  (go-try {:domain (get-in (<? (get-claim client id)) [:claim :domain])}))

(defn release-claim
  "DELETE /dns/claims/{id} — Release a claim: it ends (state revoked) and the
  hosted zone goes out of service, a snapshot of its records kept. Point the
  domain's nameservers elsewhere first. Subject to the client's domain gate
  on the claim's domain (resolved via `get-claim` when a gate is set)."
  [client id]
  (gate/request client "DELETE /dns/claims/{id}" #(claim-target client id)
                :delete ["dns" "claims" id]))

(defn seed-claim
  "PUT /dns/claims/{id}/seed — Attach a copy of the domain's current records
  to a pending claim, so the zone ird creates at activation starts from them
  instead of empty. BODY is a plain map with :snapshot_id, from
  ird.domains/dns-snapshot taken while the domain still resolves at its
  previous host. Subject to the client's domain gate on the claim's domain."
  [client id body]
  (gate/request client "PUT /dns/claims/{id}/seed" #(claim-target client id)
                :put ["dns" "claims" id "seed"] {:body body}))

(defn unseed-claim
  "DELETE /dns/claims/{id}/seed — Drop the attached copy; the zone then
  starts empty at activation. Subject to the client's domain gate on the
  claim's domain."
  [client id]
  (gate/request client "DELETE /dns/claims/{id}/seed" #(claim-target client id)
                :delete ["dns" "claims" id "seed"]))

(defn verify-claim
  "POST /dns/claims/{id}/verify — Read the domain's delegation at its parent
  zone now and activate the claim when it lists the claim's nameservers.
  Anything else is not an error: the response is 200 with :check :ok false
  and a :reason."
  [client id]
  (transport/request client :post ["dns" "claims" id "verify"]))

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/cljs.git