diff --git a/gosuper/gosuper/api.go b/gosuper/gosuper/api.go index ba5dfe1d..59c90b9a 100644 --- a/gosuper/gosuper/api.go +++ b/gosuper/gosuper/api.go @@ -9,7 +9,6 @@ import ( "os" "regexp" "strconv" - "strings" "time" "resin-supervisor/gosuper/systemd" @@ -19,9 +18,10 @@ import ( // Use raw strings to avoid having to quote the backslashes. var dockerMatch = regexp.MustCompile(`(docker[0-9])|(rce[0-9])`) -type ApiResponse struct { - Status string - Error string +// API response sent from gosupervisor +type APIResponse struct { + Data interface{} + Error string } type PurgeBody struct { @@ -61,9 +61,9 @@ func parsePurgeBody(request *http.Request) (appId string, err error) { return } -func responseSender(writer http.ResponseWriter) func(string, string, int) { - return func(statusMsg, errorMsg string, statusCode int) { - jsonResponse(writer, ApiResponse{statusMsg, errorMsg}, statusCode) +func responseSender(writer http.ResponseWriter) func(interface{}, string, int) { + return func(data interface{}, errorMsg string, statusCode int) { + jsonResponse(writer, APIResponse{data, errorMsg}, statusCode) } } @@ -167,6 +167,8 @@ func IPAddressHandler(writer http.ResponseWriter, request *http.Request) { if ipAddr, err := ipAddress(); err != nil { sendError("Invalid request") } else { - sendResponse(strings.Join(ipAddr, " "), "", http.StatusOK) + payload := make(map[string][]string) + payload["IPAddress"] = ipAddr + sendResponse(payload, "", http.StatusOK) } } diff --git a/gosuper/gosuper/main_test.go b/gosuper/gosuper/main_test.go index ac62fdc8..70289c09 100644 --- a/gosuper/gosuper/main_test.go +++ b/gosuper/gosuper/main_test.go @@ -16,11 +16,11 @@ var purgeTests = []struct { IsSuccess bool HttpStatus int }{ - {`{"applicationId": "1"}`, "1", `{"Status":"OK","Error":""}`, true, http.StatusOK}, - {`{"applicationId": 1}`, "1", `{"Status":"OK","Error":""}`, true, http.StatusOK}, - {`{"applicationId": "hi"}`, "1", `{"Status":"Error","Error":"Invalid applicationId 'hi'"}`, false, http.StatusBadRequest}, - {`{"applicationId": "2"}`, "1", `{"Status":"Error","Error":"Invalid applicationId '2': Directory does not exist"}`, false, http.StatusNotFound}, - {`{}`, "1", `{"Status":"Error","Error":"applicationId is required"}`, false, http.StatusBadRequest}, + {`{"applicationId": "1"}`, "1", `{"Data":"OK","Error":""}`, true, http.StatusOK}, + {`{"applicationId": 1}`, "1", `{"Data":"OK","Error":""}`, true, http.StatusOK}, + {`{"applicationId": "hi"}`, "1", `{"Data":"Error","Error":"Invalid applicationId 'hi'"}`, false, http.StatusBadRequest}, + {`{"applicationId": "2"}`, "1", `{"Data":"Error","Error":"Invalid applicationId '2': Directory does not exist"}`, false, http.StatusNotFound}, + {`{}`, "1", `{"Data":"Error","Error":"applicationId is required"}`, false, http.StatusBadRequest}, } func TestPurge(t *testing.T) { diff --git a/gosuper/supertest/super_test.go b/gosuper/supertest/super_test.go index cf2ce425..fd1f8beb 100644 --- a/gosuper/supertest/super_test.go +++ b/gosuper/supertest/super_test.go @@ -62,7 +62,7 @@ func TestPurge(t *testing.T) { } else { if contents, err := ioutil.ReadAll(response.Body); err != nil { t.Fatal(err) - } else if !strings.EqualFold(string(contents), `{"Status":"OK","Error":""}`) { + } else if !strings.EqualFold(string(contents), `{"Data":"OK","Error":""}`) { t.Errorf("Purge response didn't match the expected JSON, got: %s", contents) } if dirContents, err := ioutil.ReadDir(dataPath); err != nil { diff --git a/src/app.coffee b/src/app.coffee index 70cd64e9..7d2d9020 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -58,7 +58,7 @@ knex.init.then -> callback = (error, response, body ) -> if !error && response.statusCode == 200 device.updateState( - ip_address: body.Status + ip_address: body.Data.IPAddress.join(' ') ) request.get({ url: "#{config.gosuperAddress}/v1/ipaddr", json: true }, callback )