From a8a227b97a2e1685ca52aacbde26ed745c404197 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 22 Feb 2016 15:40:03 -0500 Subject: [PATCH] Add the server's time in UTC to the health response. --- http/sys_health.go | 15 +++++++++------ http/sys_health_test.go | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/http/sys_health.go b/http/sys_health.go index e23905ba86..bde39a28e2 100644 --- a/http/sys_health.go +++ b/http/sys_health.go @@ -3,6 +3,7 @@ package http import ( "encoding/json" "net/http" + "time" "github.com/hashicorp/vault/vault" ) @@ -44,9 +45,10 @@ func handleSysHealthGet(core *vault.Core, w http.ResponseWriter, r *http.Request // Format the body body := &HealthResponse{ - Initialized: init, - Sealed: sealed, - Standby: standby, + Initialized: init, + Sealed: sealed, + Standby: standby, + ServerTimeUTC: time.Now().UTC().Unix(), } // Generate the response @@ -57,7 +59,8 @@ func handleSysHealthGet(core *vault.Core, w http.ResponseWriter, r *http.Request } type HealthResponse struct { - Initialized bool `json:"initialized"` - Sealed bool `json:"sealed"` - Standby bool `json:"standby"` + Initialized bool `json:"initialized"` + Sealed bool `json:"sealed"` + Standby bool `json:"standby"` + ServerTimeUTC int64 `json:"server_time_utc"` } diff --git a/http/sys_health_test.go b/http/sys_health_test.go index db9f8e1e4f..6e50e91dd4 100644 --- a/http/sys_health_test.go +++ b/http/sys_health_test.go @@ -26,6 +26,7 @@ func TestSysHealth_get(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + expected["server_time_utc"] = actual["server_time_utc"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("bad: %#v", actual) }