(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. Every function returns a
channel (see ird.async)."
(: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."
[client id body]
(transport/request client :post ["vps" "instances" id "transfer"] {:body body}))
(defn withdraw-instance-offer
"DELETE /vps/instances/{id}/transfer — Withdraw the pending server
transfer offer."
[client id]
(transport/request client :delete ["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."
[client id body]
(transport/request client :post ["vps" "volumes" id "transfer"] {:body body}))
(defn withdraw-volume-offer
"DELETE /vps/volumes/{id}/transfer — Withdraw the pending volume transfer
offer."
[client id]
(transport/request client :delete ["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."
[client id body]
(transport/request client :post ["vps" "images" id "transfer"] {:body body}))
(defn withdraw-image-offer
"DELETE /vps/images/{id}/transfer — Withdraw the pending image transfer
offer."
[client id]
(transport/request client :delete ["vps" "images" id "transfer"]))
(defn list-transfers
"GET /vps/transfers — Pending handover offers, both directions."
[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."
([client id] (accept-transfer client id nil))
([client id body]
(transport/request client :post ["vps" "transfers" id "accept"] (when body {:body body}))))
(defn decline-transfer
"POST /vps/transfers/{id}/decline — Decline an incoming transfer offer."
[client id]
(transport/request client :post ["vps" "transfers" id "decline"]))