Documentation
¶
Overview ¶
Package serverorder is the laptop's half of a ready server (ADR-114): a server Caprock sells, created for the buyer and set up with the same script New server writes (internal/serverscript), which joins this computer with a key made here for that one order.
On the user's click (Settings → Computers → Add a computer → Get a ready server) the daemon makes an order id and a server key that lives 24 hours (peers.OrderJoinTTL), renders the setup script with that key inside, and registers the order with caprock.dev (Register): the order id, the size and the script, nothing else. caprock.dev keeps the script sealed until the server is created and deletes it then. It answers the Stripe payment link for that order, which the screen opens. Afterwards the daemon reads the order's status (Read) while the Computers screen shows it: whether it is paid, being created, booting, running, failed or stopping on a date.
The orders are kept in a 0600 file in the data directory (Store), with the kept form of each one's key (peers.KeptJoinKey, the secret's hash only), so a server that boots while this daemon restarts still finds its key open.
Index ¶
- Constants
- Variables
- func Base() string
- func CheckPayURL(raw, size, id string) error
- func NewID() (string, error)
- func Reference(size, id string) string
- func Register(ctx context.Context, hc *http.Client, base, id, size, setup string) (string, error)
- func ValidID(id string) bool
- type Order
- type Registered
- type Remote
- type Size
- type Store
Constants ¶
const ( DefaultBase = "https://caprock.dev" BaseEnv = "CAPROCK_SERVER_ORDER_URL" )
DefaultBase is caprock.dev. BaseEnv replaces it — for a preview stand or a test, which must never register an order with the real site.
const ( WaitingPayment = "waiting_payment" // registered, not paid yet Creating = "creating" // paid; the server is being created Booting = "booting" // created; not running with an address yet Running = "running" // running: the setup script is installing Caprock Failed = "failed" // Reason says why, in words for the buyer Stopped = "stopped" // the subscription ended; the server is stopped Unknown = "unknown" // caprock.dev has no such order (never paid, and expired) )
The statuses caprock.dev answers (Remote.Status).
const File = "server-orders.json"
File is the orders' file in the data directory, mode 0600.
Variables ¶
var ( // ErrNotOnSale is caprock.dev not taking orders: switched off, or no // payment link for that size. ErrNotOnSale = errors.New("ready servers are not on sale yet") // ErrUnreachable is caprock.dev not answering. ErrUnreachable = errors.New("could not reach caprock.dev") )
Errors the screen tells apart.
var Sizes = []Size{
{ID: "24", Memory: "24 GB", PriceUSD: 39},
{ID: "48", Memory: "48 GB", PriceUSD: 59},
}
Sizes are the two ready servers and their prices: the Stripe prices of the products "Caprock Server — 24 GB" (prod_Vi0ETgAutCfxdn) and "Caprock Server — 48 GB" (prod_Vi0FcXDgNS1GIS), monthly, set by the owner on 2026-11-28 (ADR-114; caprock-web docs/servers.md). A change of price in Stripe changes these in the same commit as the docs that state them.
Functions ¶
func CheckPayURL ¶
CheckPayURL holds caprock.dev's payment link to Stripe's pages and to this order's reference, so the screen never opens anything else.
func NewID ¶
NewID is an order id: 128 random bits, hex. It is the only thing that reads the order's status at caprock.dev, so it is unguessable.
func Reference ¶
Reference is the payment link's client_reference_id for an order: "server-24-<id>". Stripe takes letters, digits, "-" and "_" there, up to 200 characters, and silently drops anything else (so no ".").
Types ¶
type Order ¶
type Order struct {
ID string `json:"id"`
Size string `json:"size"`
// PayURL is the order's Stripe payment link, to open again until it is paid.
PayURL string `json:"pay_url,omitempty"`
// CreatedAt and ExpiresAt are unix milliseconds; ExpiresAt is the key's.
CreatedAt int64 `json:"created_at"`
ExpiresAt int64 `json:"expires_at"`
// Key reopens the order's key after a restart, until the server joins
// or the key expires; then it is dropped.
Key *peers.KeptJoinKey `json:"key,omitempty"`
// Machine is the computer that joined with the key, as GET /v1/machines
// lists it.
Machine string `json:"machine,omitempty"`
// KeyLost says the key stopped waiting without a join (withdrawn, burned
// by wrong tries, or not reopened): the server cannot join with it.
KeyLost bool `json:"key_lost,omitempty"`
// Remote is what caprock.dev said last, and ReadAt when (unix ms).
Remote Remote `json:"remote"`
ReadAt int64 `json:"read_at,omitempty"`
}
Order is one ready server ordered from this computer.
type Registered ¶
type Registered struct {
PayURL string `json:"pay_url"`
}
Registered is caprock.dev's answer to a registration.
type Remote ¶
type Remote struct {
Status string `json:"status"`
Size string `json:"size,omitempty"`
Reason string `json:"reason,omitempty"`
// StopsAt is unix seconds: the subscription is cancelled and the server
// stops then.
StopsAt int64 `json:"stops_at,omitempty"`
}
Remote is GET /api/server-order/<id>'s answer.
type Size ¶
type Size struct {
// ID is what an order and the payment link's reference carry: "24", "48".
ID string `json:"id"`
// Memory is what the screen names the size by.
Memory string `json:"memory"`
// PriceUSD is the Stripe price, US dollars a month.
PriceUSD int `json:"price_usd"`
}
Size is one server Caprock sells.