Add version to /status endpoint (#2295)

* Add version to /status endpoint

* Add version to test

* Fix linting errors
This commit is contained in:
nitrocode
2022-06-05 23:06:37 -04:00
committed by GitHub
parent 82cf170d8f
commit 2b772541f5
3 changed files with 21 additions and 14 deletions

View File

@@ -11,21 +11,24 @@ import (
// StatusController handles the status of Atlantis.
type StatusController struct {
Logger logging.SimpleLogging
Drainer *events.Drainer
Logger logging.SimpleLogging
Drainer *events.Drainer
AtlantisVersion string
}
type StatusResponse struct {
ShuttingDown bool `json:"shutting_down"`
InProgressOps int `json:"in_progress_operations"`
ShuttingDown bool `json:"shutting_down"`
InProgressOps int `json:"in_progress_operations"`
AtlantisVersion string `json:"version"`
}
// Get is the GET /status route.
func (d *StatusController) Get(w http.ResponseWriter, r *http.Request) {
status := d.Drainer.GetStatus()
data, err := json.MarshalIndent(&StatusResponse{
ShuttingDown: status.ShuttingDown,
InProgressOps: status.InProgressOps,
ShuttingDown: status.ShuttingDown,
InProgressOps: status.InProgressOps,
AtlantisVersion: d.AtlantisVersion,
}, "", " ")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)

View File

@@ -20,8 +20,9 @@ func TestStatusController_Startup(t *testing.T) {
w := httptest.NewRecorder()
dr := &events.Drainer{}
d := &controllers.StatusController{
Logger: logger,
Drainer: dr,
Logger: logger,
Drainer: dr,
AtlantisVersion: "1.0.0",
}
d.Get(w, r)
@@ -43,8 +44,9 @@ func TestStatusController_InProgress(t *testing.T) {
dr.StartOp()
d := &controllers.StatusController{
Logger: logger,
Drainer: dr,
Logger: logger,
Drainer: dr,
AtlantisVersion: "1.0.0",
}
d.Get(w, r)
@@ -66,8 +68,9 @@ func TestStatusController_Shutdown(t *testing.T) {
dr.ShutdownBlocking()
d := &controllers.StatusController{
Logger: logger,
Drainer: dr,
Logger: logger,
Drainer: dr,
AtlantisVersion: "1.0.0",
}
d.Get(w, r)

View File

@@ -472,8 +472,9 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
}
drainer := &events.Drainer{}
statusController := &controllers.StatusController{
Logger: logger,
Drainer: drainer,
Logger: logger,
Drainer: drainer,
AtlantisVersion: config.AtlantisVersion,
}
preWorkflowHooksCommandRunner := &events.DefaultPreWorkflowHooksCommandRunner{
VCSClient: vcsClient,