clj / src / ird / tunnels.clj
299 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
(ns ird.tunnels
  "HTTPS tunnels on your own domain, reverse-tunneled to your device over
  SSH. Hourly billing while the tunnel exists. Creating a tunnel is subject
  to the client's domain gate on the hostname."
  (:require
   [ird.gate :as gate]
   [ird.transport :as transport]))

(defn list-tunnels
  "GET /tunnels — List your tunnels.
  Returns the parsed response map."
  [client]
  (transport/request client :get "/tunnels"))

(defn create-tunnel
  "POST /tunnels — Create a tunnel.
  BODY keys include :hostname, :transport, :ssh_key_id, :ssh_public_key,
  :settings, :totp_code. Subject to the client's domain gate on :hostname.
  Returns the parsed response map."
  [client body]
  (gate/check! client "POST /tunnels" {:domain (:hostname body)})
  (transport/request client :post "/tunnels" {:body body}))

(defn get-tunnel
  "GET /tunnels/{id} — Tunnel detail.
  Returns the parsed response map."
  [client id]
  (transport/request client :get (str "/tunnels/" id)))

(defn- check-tunnel-gate!
  "Gate check for a mutation on tunnel ID: resolve its hostname via
  `get-tunnel` (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-tunnel client id) [:tunnel :hostname])})))

(defn delete-tunnel
  "DELETE /tunnels/{id} — Delete a tunnel (billing stops).
  Optional BODY carries :totp_code. Subject to the client's domain gate on
  the tunnel's hostname (resolved via `get-tunnel` when a gate is set).
  Returns the parsed response map."
  ([client id] (delete-tunnel client id nil))
  ([client id body]
   (check-tunnel-gate! client "DELETE /tunnels/{id}" id)
   (transport/request client :delete (str "/tunnels/" id)
                      (when body {:body body}))))

(defn update-tunnel
  "PATCH /tunnels/{id} — Update tunnel settings.
  BODY carries :settings and optional :totp_code. Subject to the client's
  domain gate on the tunnel's hostname (resolved via `get-tunnel` when a
  gate is set).
  Returns the parsed response map."
  [client id body]
  (check-tunnel-gate! client "PATCH /tunnels/{id}" id)
  (transport/request client :patch (str "/tunnels/" id) {:body body}))

(defn verify-dns
  "POST /tunnels/{id}/verify-dns — Re-check DNS.
  Returns the parsed response map."
  [client id]
  (transport/request client :post (str "/tunnels/" id "/verify-dns")))

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