mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
Add Service Banners (#5272)
This commit is contained in:
@@ -23,6 +23,7 @@ const (
|
||||
FeatureHighAvailability = "high_availability"
|
||||
FeatureMultipleGitAuth = "multiple_git_auth"
|
||||
FeatureExternalProvisionerDaemons = "external_provisioner_daemons"
|
||||
FeatureServiceBanners = "service_banners"
|
||||
)
|
||||
|
||||
var FeatureNames = []string{
|
||||
@@ -34,6 +35,7 @@ var FeatureNames = []string{
|
||||
FeatureHighAvailability,
|
||||
FeatureMultipleGitAuth,
|
||||
FeatureExternalProvisionerDaemons,
|
||||
FeatureServiceBanners,
|
||||
}
|
||||
|
||||
type Feature struct {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package codersdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ServiceBanner struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Message string `json:"message,omitempty"`
|
||||
BackgroundColor string `json:"background_color,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ServiceBanner(ctx context.Context) (*ServiceBanner, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/service-banner", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, readBodyAsError(res)
|
||||
}
|
||||
var b ServiceBanner
|
||||
return &b, json.NewDecoder(res.Body).Decode(&b)
|
||||
}
|
||||
|
||||
func (c *Client) SetServiceBanner(ctx context.Context, s *ServiceBanner) error {
|
||||
res, err := c.Request(ctx, http.MethodPut, "/api/v2/service-banner", s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return readBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user