From f999ec946e5fdde0c13098a6b657e40772ee70c7 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Sun, 5 Jun 2022 09:14:42 -0500 Subject: [PATCH 1/3] Add version to /status endpoint --- server/controllers/status_controller.go | 11 +++++++---- server/server.go | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/controllers/status_controller.go b/server/controllers/status_controller.go index e54b3e1140..306d4519c0 100644 --- a/server/controllers/status_controller.go +++ b/server/controllers/status_controller.go @@ -11,13 +11,15 @@ 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. @@ -26,6 +28,7 @@ func (d *StatusController) Get(w http.ResponseWriter, r *http.Request) { data, err := json.MarshalIndent(&StatusResponse{ ShuttingDown: status.ShuttingDown, InProgressOps: status.InProgressOps, + AtlantisVersion: d.AtlantisVersion, }, "", " ") if err != nil { w.WriteHeader(http.StatusInternalServerError) diff --git a/server/server.go b/server/server.go index a6546a70ca..397da5cef5 100644 --- a/server/server.go +++ b/server/server.go @@ -474,6 +474,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { statusController := &controllers.StatusController{ Logger: logger, Drainer: drainer, + AtlantisVersion: config.AtlantisVersion, } preWorkflowHooksCommandRunner := &events.DefaultPreWorkflowHooksCommandRunner{ VCSClient: vcsClient, From 8bc9bd9ca7f04c0b86dbaae4b38ac5fb131183f3 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Sun, 5 Jun 2022 09:51:36 -0500 Subject: [PATCH 2/3] Add version to test --- server/controllers/status_controller_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/controllers/status_controller_test.go b/server/controllers/status_controller_test.go index bc51611558..6e3bdaf9ff 100644 --- a/server/controllers/status_controller_test.go +++ b/server/controllers/status_controller_test.go @@ -22,6 +22,7 @@ func TestStatusController_Startup(t *testing.T) { d := &controllers.StatusController{ Logger: logger, Drainer: dr, + AtlantisVersion: "1.0.0", } d.Get(w, r) @@ -45,6 +46,7 @@ func TestStatusController_InProgress(t *testing.T) { d := &controllers.StatusController{ Logger: logger, Drainer: dr, + AtlantisVersion: "1.0.0", } d.Get(w, r) @@ -68,6 +70,7 @@ func TestStatusController_Shutdown(t *testing.T) { d := &controllers.StatusController{ Logger: logger, Drainer: dr, + AtlantisVersion: "1.0.0", } d.Get(w, r) From 00f81e4e870b184374de44f39e52870284384f65 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Sun, 5 Jun 2022 13:10:19 -0500 Subject: [PATCH 3/3] Fix linting errors --- server/controllers/status_controller.go | 4 ++-- server/controllers/status_controller_test.go | 12 ++++++------ server/server.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/controllers/status_controller.go b/server/controllers/status_controller.go index 306d4519c0..b26a52f04d 100644 --- a/server/controllers/status_controller.go +++ b/server/controllers/status_controller.go @@ -26,8 +26,8 @@ type StatusResponse struct { 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 { diff --git a/server/controllers/status_controller_test.go b/server/controllers/status_controller_test.go index 6e3bdaf9ff..7cd4df4b3b 100644 --- a/server/controllers/status_controller_test.go +++ b/server/controllers/status_controller_test.go @@ -20,8 +20,8 @@ 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) @@ -44,8 +44,8 @@ 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) @@ -68,8 +68,8 @@ 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) diff --git a/server/server.go b/server/server.go index 397da5cef5..284bdbbf8d 100644 --- a/server/server.go +++ b/server/server.go @@ -472,8 +472,8 @@ 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{