Skip to content

Commit cb0656c

Browse files
committed
Merge appearance.go and buildinfo.go into deployment.go
1 parent b9a0e2e commit cb0656c

File tree

3 files changed

+74
-89
lines changed

3 files changed

+74
-89
lines changed

codersdk/appearance.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

codersdk/buildinfo.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

codersdk/deploymentconfig.go renamed to codersdk/deployment.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"context"
55
"encoding/json"
66
"net/http"
7+
"strings"
78
"time"
89

10+
"golang.org/x/mod/semver"
911
"golang.org/x/xerrors"
1012
)
1113

@@ -240,3 +242,75 @@ func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error)
240242
var df DeploymentConfig
241243
return df, json.NewDecoder(res.Body).Decode(&df)
242244
}
245+
246+
type AppearanceConfig struct {
247+
LogoURL string `json:"logo_url"`
248+
ServiceBanner ServiceBannerConfig `json:"service_banner"`
249+
}
250+
251+
type ServiceBannerConfig struct {
252+
Enabled bool `json:"enabled"`
253+
Message string `json:"message,omitempty"`
254+
BackgroundColor string `json:"background_color,omitempty"`
255+
}
256+
257+
// Appearance returns the configuration that modifies the visual
258+
// display of the dashboard.
259+
func (c *Client) Appearance(ctx context.Context) (AppearanceConfig, error) {
260+
res, err := c.Request(ctx, http.MethodGet, "/api/v2/appearance", nil)
261+
if err != nil {
262+
return AppearanceConfig{}, err
263+
}
264+
defer res.Body.Close()
265+
if res.StatusCode != http.StatusOK {
266+
return AppearanceConfig{}, readBodyAsError(res)
267+
}
268+
var cfg AppearanceConfig
269+
return cfg, json.NewDecoder(res.Body).Decode(&cfg)
270+
}
271+
272+
func (c *Client) UpdateAppearance(ctx context.Context, appearance AppearanceConfig) error {
273+
res, err := c.Request(ctx, http.MethodPut, "/api/v2/appearance", appearance)
274+
if err != nil {
275+
return err
276+
}
277+
defer res.Body.Close()
278+
if res.StatusCode != http.StatusOK {
279+
return readBodyAsError(res)
280+
}
281+
return nil
282+
}
283+
284+
// BuildInfoResponse contains build information for this instance of Coder.
285+
type BuildInfoResponse struct {
286+
// ExternalURL references the current Coder version.
287+
// For production builds, this will link directly to a release. For development builds, this will link to a commit.
288+
ExternalURL string `json:"external_url"`
289+
// Version returns the semantic version of the build.
290+
Version string `json:"version"`
291+
}
292+
293+
// CanonicalVersion trims build information from the version.
294+
// E.g. 'v0.7.4-devel+11573034' -> 'v0.7.4'.
295+
func (b BuildInfoResponse) CanonicalVersion() string {
296+
// We do a little hack here to massage the string into a form
297+
// that works well with semver.
298+
trimmed := strings.ReplaceAll(b.Version, "-devel+", "+devel-")
299+
return semver.Canonical(trimmed)
300+
}
301+
302+
// BuildInfo returns build information for this instance of Coder.
303+
func (c *Client) BuildInfo(ctx context.Context) (BuildInfoResponse, error) {
304+
res, err := c.Request(ctx, http.MethodGet, "/api/v2/buildinfo", nil)
305+
if err != nil {
306+
return BuildInfoResponse{}, err
307+
}
308+
defer res.Body.Close()
309+
310+
if res.StatusCode != http.StatusOK {
311+
return BuildInfoResponse{}, readBodyAsError(res)
312+
}
313+
314+
var buildInfo BuildInfoResponse
315+
return buildInfo, json.NewDecoder(res.Body).Decode(&buildInfo)
316+
}

0 commit comments

Comments
 (0)