(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")))