|
| 1 | +package coder |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | +) |
| 7 | + |
| 8 | +type Satellite struct { |
| 9 | + ID string `json:"id"` |
| 10 | + Name string `json:"name"` |
| 11 | + Fingerprint string `json:"fingerprint"` |
| 12 | +} |
| 13 | + |
| 14 | +type satellites struct { |
| 15 | + Data []Satellite `json:"data"` |
| 16 | +} |
| 17 | + |
| 18 | +type createSatelliteResponse struct { |
| 19 | + Data Satellite `json:"data"` |
| 20 | +} |
| 21 | + |
| 22 | +// Satellites fetches all satellitess known to the Coder control plane. |
| 23 | +func (c *DefaultClient) Satellites(ctx context.Context) ([]Satellite, error) { |
| 24 | + var res satellites |
| 25 | + err := c.requestBody(ctx, http.MethodGet, "/api/private/satellites", nil, &res) |
| 26 | + if err != nil { |
| 27 | + return nil, err |
| 28 | + } |
| 29 | + return res.Data, nil |
| 30 | +} |
| 31 | + |
| 32 | +// CreateSatelliteReq defines the request parameters for creating a new satellite entity. |
| 33 | +type CreateSatelliteReq struct { |
| 34 | + Name string `json:"name"` |
| 35 | + PublicKey string `json:"public_key"` |
| 36 | +} |
| 37 | + |
| 38 | +// CreateSatellite creates a new satellite entity. |
| 39 | +func (c *DefaultClient) CreateSatellite(ctx context.Context, req CreateSatelliteReq) (*Satellite, error) { |
| 40 | + var res createSatelliteResponse |
| 41 | + err := c.requestBody(ctx, http.MethodPost, "/api/private/satellites", req, &res) |
| 42 | + if err != nil { |
| 43 | + return nil, err |
| 44 | + } |
| 45 | + return &res.Data, nil |
| 46 | +} |
| 47 | + |
| 48 | +// DeleteSatelliteByID deletes a satellite entity from the Coder control plane. |
| 49 | +func (c *DefaultClient) DeleteSatelliteByID(ctx context.Context, id string) error { |
| 50 | + return c.requestBody(ctx, http.MethodDelete, "/api/private/satellites/"+id, nil, nil) |
| 51 | +} |
0 commit comments