This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsatellite.go
More file actions
51 lines (43 loc) · 1.38 KB
/
satellite.go
File metadata and controls
51 lines (43 loc) · 1.38 KB
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
package coder
import (
"context"
"net/http"
)
type Satellite struct {
ID string `json:"id"`
Name string `json:"name"`
Fingerprint string `json:"fingerprint"`
}
type satellites struct {
Data []Satellite `json:"data"`
}
type createSatelliteResponse struct {
Data Satellite `json:"data"`
}
// Satellites fetches all satellitess known to the Coder control plane.
func (c *DefaultClient) Satellites(ctx context.Context) ([]Satellite, error) {
var res satellites
err := c.requestBody(ctx, http.MethodGet, "/api/private/satellites", nil, &res)
if err != nil {
return nil, err
}
return res.Data, nil
}
// CreateSatelliteReq defines the request parameters for creating a new satellite entity.
type CreateSatelliteReq struct {
Name string `json:"name"`
PublicKey string `json:"public_key"`
}
// CreateSatellite creates a new satellite entity.
func (c *DefaultClient) CreateSatellite(ctx context.Context, req CreateSatelliteReq) (*Satellite, error) {
var res createSatelliteResponse
err := c.requestBody(ctx, http.MethodPost, "/api/private/satellites", req, &res)
if err != nil {
return nil, err
}
return &res.Data, nil
}
// DeleteSatelliteByID deletes a satellite entity from the Coder control plane.
func (c *DefaultClient) DeleteSatelliteByID(ctx context.Context, id string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/satellites/"+id, nil, nil)
}