(ns ird.transfers
"Cross-account handover of VPS resources (servers, volumes, snapshots):
offer to another account by email, they accept or decline.
NOTE: every operation here requires an account JWT (see
ird.auth/device-login); API keys are not accepted."
(:require
[ird.transport :as transport]))
(defn offer-instance
"POST /vps/instances/{id}/transfer — Offer this server to another account.
BODY is a plain map with :email and optional :totp_code.
Returns the parsed response map."
[client id body]
(transport/request client :post (str "/vps/instances/" id "/transfer")
{:body body}))
(defn withdraw-instance-offer
"DELETE /vps/instances/{id}/transfer — Withdraw the pending server
transfer offer.
Returns the parsed response map."
[client id]
(transport/request client :delete (str "/vps/instances/" id "/transfer")))
(defn offer-volume
"POST /vps/volumes/{id}/transfer — Offer this volume to another account.
BODY is a plain map with :email and optional :totp_code.
Returns the parsed response map."
[client id body]
(transport/request client :post (str "/vps/volumes/" id "/transfer")
{:body body}))
(defn withdraw-volume-offer
"DELETE /vps/volumes/{id}/transfer — Withdraw the pending volume transfer
offer.
Returns the parsed response map."
[client id]
(transport/request client :delete (str "/vps/volumes/" id "/transfer")))
(defn offer-image
"POST /vps/images/{id}/transfer — Offer this image to another account.
BODY is a plain map with :email and optional :totp_code.
Returns the parsed response map."
[client id body]
(transport/request client :post (str "/vps/images/" id "/transfer")
{:body body}))
(defn withdraw-image-offer
"DELETE /vps/images/{id}/transfer — Withdraw the pending image transfer
offer.
Returns the parsed response map."
[client id]
(transport/request client :delete (str "/vps/images/" id "/transfer")))
(defn list-transfers
"GET /vps/transfers — Pending handover offers, both directions.
Returns the parsed response map."
[client]
(transport/request client :get "/vps/transfers"))
(defn accept-transfer
"POST /vps/transfers/{id}/accept — Take over the offered resource.
BODY is a plain map with optional :totp_code.
Returns the parsed response map."
([client id] (accept-transfer client id nil))
([client id body]
(transport/request client :post (str "/vps/transfers/" id "/accept")
(when body {:body body}))))
(defn decline-transfer
"POST /vps/transfers/{id}/decline — Decline an incoming transfer offer.
Returns the parsed response map."
[client id]
(transport/request client :post (str "/vps/transfers/" id "/decline")))