clj / src / ird / dns.clj
996 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
(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."
  (:require
   [ird.gate :as gate]
   [ird.transport :as transport]))

(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.
  Returns the parsed response map."
  ([client id] (enable-hosting client id nil))
  ([client id body]
   (gate/check! client "POST /domains/registrations/{id}/dns" {:registration-id id})
   (transport/request client :post (str "/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.
  Returns the parsed response map."
  ([client id] (disable-hosting client id nil))
  ([client id body]
   (gate/check! client "DELETE /domains/registrations/{id}/dns" {:registration-id id})
   (transport/request client :delete (str "/domains/registrations/" id "/dns")
                      (when body {:body body}))))

(defn get-dnssec
  "GET /domains/registrations/{id}/dns/dnssec — DNSSEC state of the hosted
  zone.
  Returns the parsed response map."
  [client id]
  (transport/request client :get (str "/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.
  Returns the parsed response map."
  ([client id] (enable-dnssec client id nil))
  ([client id body]
   (gate/check! client "POST /domains/registrations/{id}/dns/dnssec" {:registration-id id})
   (transport/request client :post (str "/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.
  Returns the parsed response map."
  ([client id] (disable-dnssec client id nil))
  ([client id body]
   (gate/check! client "DELETE /domains/registrations/{id}/dns/dnssec" {:registration-id id})
   (transport/request client :delete (str "/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. Free.
  Returns the parsed response map."
  [client id]
  (transport/request client :get (str "/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.
  Returns the parsed response map."
  [client id body]
  (gate/check! client "POST /domains/registrations/{id}/dns/nameservers" {:registration-id id})
  (transport/request client :post (str "/domains/registrations/" id "/dns/nameservers")
                     {:body body}))

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

(defn get-zone
  "GET /dns/domains/{domain} — A hosted domain's zone.
  Returns the parsed response map."
  [client domain]
  (transport/request client :get (str "/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.
  Returns the parsed response map."
  [client domain body]
  (gate/check! client "PUT /dns/domains/{domain}/records" {:domain domain})
  (transport/request client :put (str "/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.
  Returns the parsed response map."
  [client domain body]
  (gate/check! client "DELETE /dns/domains/{domain}/records" {:domain domain})
  (transport/request client :delete (str "/dns/domains/" domain "/records")
                     {:body body}))

(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).
  Returns the parsed response map."
  ([client] (list-claims client nil))
  ([client query]
   (transport/request client :get "/dns/claims" (when query {:query query}))))

(defn create-claim
  "POST /dns/claims — Claim a registrable domain registered elsewhere so ird
  can be its DNS (201). BODY carries :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.
  Returns the parsed response map."
  [client body]
  (gate/check! client "POST /dns/claims" {:domain (:domain body)})
  (transport/request client :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.
  Returns the parsed response map."
  [client id]
  (transport/request client :get (str "/dns/claims/" id)))

(defn- check-claim-gate!
  "Gate check for a mutation on claim ID: resolve its domain via `get-claim`
  (only when the client has a gate) and run gate/check!."
  [client op id]
  (when (:gate client)
    (gate/check! client op
                 {: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).
  Returns the parsed response map."
  [client id]
  (check-claim-gate! client "DELETE /dns/claims/{id}" id)
  (transport/request client :delete (str "/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 carries :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
  (resolved via `get-claim` when a gate is set).
  Returns the parsed response map."
  [client id body]
  (check-claim-gate! client "PUT /dns/claims/{id}/seed" id)
  (transport/request client :put (str "/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 (resolved via `get-claim` when a gate is set).
  Returns the parsed response map."
  [client id]
  (check-claim-gate! client "DELETE /dns/claims/{id}/seed" id)
  (transport/request client :delete (str "/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.
  Returns the parsed response map."
  [client id]
  (transport/request client :post (str "/dns/claims/" id "/verify")))

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