Add the server's time in UTC to the health response.

This commit is contained in:
Jeff Mitchell 2016-02-22 15:40:03 -05:00
parent 50082a61d8
commit a8a227b97a
2 changed files with 10 additions and 6 deletions

View file

@ -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"`
}

View file

@ -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)
}