forked from evergreen-ci/evergreen
/
cli_update.go
64 lines (55 loc) · 1.49 KB
/
cli_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package data
import (
"net/http"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/rest/model"
"github.com/evergreen-ci/gimlet"
)
type CLIUpdateConnector struct{}
func (c *CLIUpdateConnector) GetCLIUpdate() (*model.APICLIUpdate, error) {
update := &model.APICLIUpdate{}
env := evergreen.GetEnvironment()
config := env.ClientConfig()
if config == nil {
return nil, gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: "no clients configured",
}
}
if err := update.BuildFromService(*config); err != nil {
return nil, gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: err.Error(),
}
}
flags, err := evergreen.GetServiceFlags()
if err != nil {
return nil, gimlet.ErrorResponse{
StatusCode: http.StatusInternalServerError,
Message: err.Error(),
}
}
if flags != nil {
update.IgnoreUpdate = flags.CLIUpdatesDisabled
}
return update, nil
}
type MockCLIUpdateConnector struct {
degradedModeOn bool
}
func (c *MockCLIUpdateConnector) GetCLIUpdate() (*model.APICLIUpdate, error) {
update := &model.APICLIUpdate{
ClientConfig: model.APIClientConfig{
ClientBinaries: []model.APIClientBinary{
model.APIClientBinary{
Arch: model.ToAPIString("amd64"),
OS: model.ToAPIString("darwin"),
URL: model.ToAPIString("localhost/clients/darwin_amd64/evergreen"),
},
},
LatestRevision: model.ToAPIString("2017-12-29"),
},
IgnoreUpdate: c.degradedModeOn,
}
return update, nil
}