mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: manage health settings using Coder API (#10861)
This commit is contained in:
@@ -24,6 +24,7 @@ const (
|
||||
ResourceTypeGroup ResourceType = "group"
|
||||
ResourceTypeLicense ResourceType = "license"
|
||||
ResourceTypeConvertLogin ResourceType = "convert_login"
|
||||
ResourceTypeHealthSettings ResourceType = "health_settings"
|
||||
ResourceTypeWorkspaceProxy ResourceType = "workspace_proxy"
|
||||
ResourceTypeOrganization ResourceType = "organization"
|
||||
)
|
||||
@@ -56,6 +57,8 @@ func (r ResourceType) FriendlyString() string {
|
||||
return "workspace proxy"
|
||||
case ResourceTypeOrganization:
|
||||
return "organization"
|
||||
case ResourceTypeHealthSettings:
|
||||
return "health_settings"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package codersdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
type HealthSettings struct {
|
||||
DismissedHealthchecks []string `json:"dismissed_healthchecks"`
|
||||
}
|
||||
|
||||
type UpdateHealthSettings struct {
|
||||
DismissedHealthchecks []string `json:"dismissed_healthchecks"`
|
||||
}
|
||||
|
||||
func (c *Client) HealthSettings(ctx context.Context) (HealthSettings, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/debug/health/settings", nil)
|
||||
if err != nil {
|
||||
return HealthSettings{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return HealthSettings{}, ReadBodyAsError(res)
|
||||
}
|
||||
var settings HealthSettings
|
||||
return settings, json.NewDecoder(res.Body).Decode(&settings)
|
||||
}
|
||||
|
||||
func (c *Client) PutHealthSettings(ctx context.Context, settings HealthSettings) error {
|
||||
res, err := c.Request(ctx, http.MethodPut, "/api/v2/debug/health/settings", settings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode == http.StatusNotModified {
|
||||
return xerrors.New("health settings not modified")
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return ReadBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user