clj / src / ird / transfers.clj
315 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
(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")))

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