@@ -4,8 +4,10 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"net/http"
7
+ "strings"
7
8
"time"
8
9
10
+ "golang.org/x/mod/semver"
9
11
"golang.org/x/xerrors"
10
12
)
11
13
@@ -240,3 +242,75 @@ func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error)
240
242
var df DeploymentConfig
241
243
return df , json .NewDecoder (res .Body ).Decode (& df )
242
244
}
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