|
| 1 | +package coder |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | +) |
| 7 | + |
| 8 | +// ResourcePool defines an entity capable of deploying and acting as an ingress for Coder environments. |
| 9 | +type ResourcePool struct { |
| 10 | + ID string `json:"id"` |
| 11 | + Name string `json:"name"` |
| 12 | + Local bool `json:"local"` |
| 13 | + ClusterAddress string `json:"cluster_address"` |
| 14 | + DefaultNamespace string `json:"default_namespace"` |
| 15 | + StorageClass string `json:"storage_class"` |
| 16 | + ClusterDomainSuffix string `json:"cluster_domain_suffix"` |
| 17 | + DevurlHost string `json:"devurl_host"` |
| 18 | + NamespaceWhitelist []string `json:"namespace_whitelist"` |
| 19 | + OrgWhitelist []string `json:"org_whitelist"` |
| 20 | +} |
| 21 | + |
| 22 | +// ResourcePoolByID fetches a resource pool entity by its unique ID. |
| 23 | +func (c *Client) ResourcePoolByID(ctx context.Context, id string) (*ResourcePool, error) { |
| 24 | + var rp ResourcePool |
| 25 | + if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools/"+id, nil, &rp); err != nil { |
| 26 | + return nil, err |
| 27 | + } |
| 28 | + return &rp, nil |
| 29 | +} |
| 30 | + |
| 31 | +// DeleteResourcePoolByID deletes a resource pool entity from the Coder control plane. |
| 32 | +func (c *Client) DeleteResourcePoolByID(ctx context.Context, id string) error { |
| 33 | + return c.requestBody(ctx, http.MethodDelete, "/api/private/resource-pools/"+id, nil, nil) |
| 34 | +} |
| 35 | + |
| 36 | +// ResourcePools fetches all resource pools known to the Coder control plane. |
| 37 | +func (c *Client) ResourcePools(ctx context.Context) ([]ResourcePool, error) { |
| 38 | + var pools []ResourcePool |
| 39 | + if err := c.requestBody(ctx, http.MethodGet, "/api/private/resource-pools", nil, &pools); err != nil { |
| 40 | + return nil, err |
| 41 | + } |
| 42 | + return pools, nil |
| 43 | +} |
| 44 | + |
| 45 | +// CreateResourcePoolReq defines the request parameters for creating a new resource pool entity. |
| 46 | +type CreateResourcePoolReq struct { |
| 47 | + Name string `json:"name"` |
| 48 | + Local bool `json:"local"` |
| 49 | + ClusterCA string `json:"cluster_ca"` |
| 50 | + ClusterAddress string `json:"cluster_address"` |
| 51 | + SAToken string `json:"sa_token"` |
| 52 | + DefaultNamespace string `json:"default_namespace"` |
| 53 | + StorageClass string `json:"storage_class"` |
| 54 | + ClusterDomainSuffix string `json:"cluster_domain_suffix"` |
| 55 | + DevurlHost string `json:"devurl_host"` |
| 56 | + NamespaceWhitelist []string `json:"namespace_whitelist"` |
| 57 | + OrgWhitelist []string `json:"org_whitelist"` |
| 58 | +} |
| 59 | + |
| 60 | +// CreateResourcePool creates a new ResourcePool entity. |
| 61 | +func (c *Client) CreateResourcePool(ctx context.Context, req CreateResourcePoolReq) error { |
| 62 | + return c.requestBody(ctx, http.MethodPost, "/api/private/resource-pools", req, nil) |
| 63 | +} |
0 commit comments