Add Service Banners (#5272)

This commit is contained in:
Ammar Bandukwala
2022-12-06 18:38:38 +00:00
committed by GitHub
parent df389d429c
commit 1cfe5de1c5
36 changed files with 959 additions and 4 deletions
+2
View File
@@ -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 {
+38
View File
@@ -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
}