From 38e5c3b03f1a3ad2fa661c8ebe59459433127214 Mon Sep 17 00:00:00 2001 From: ldelossa Date: Thu, 19 Dec 2019 17:24:28 -0500 Subject: [PATCH 1/2] json state endpoint to json --- indexer/httptransport.go | 18 +++++++++++++++--- openapi.yaml | 10 ++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/indexer/httptransport.go b/indexer/httptransport.go index 784b55c390..0a520b91cf 100644 --- a/indexer/httptransport.go +++ b/indexer/httptransport.go @@ -145,9 +145,21 @@ func (h *HTTP) StateHandler(w http.ResponseWriter, r *http.Request) { } } w.Header().Set("content-type", "text/plain") - // No trailing newline, so a client can't get confused about whether it - // counts or not. - fmt.Fprint(w, s) + + err := json.NewEncoder(w).Encode(struct { + State string `json:"state"` + }{ + State: s, + }) + if err != nil { + resp := &je.Response{ + Code: "encoding-error", + Message: fmt.Sprintf("failed to encode scan report: %v", err), + } + je.Error(w, resp, http.StatusInternalServerError) + return + } + return } // Register will register the api on a given mux. diff --git a/openapi.yaml b/openapi.yaml index 9a2affec79..0115adb438 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -106,8 +106,8 @@ paths: operationId: State summary: Report the indexer's internal configuration and state. description: | - The state endpoint returns an opaque string indicating the indexer's - internal configuration and state. + The state endpoint returns a json structure indicating the indexer's + internal configuration state. A client may be interested in this as a signal that manifests may need to be reindexed. @@ -508,8 +508,10 @@ components: message: type: string description: "a message with further detail" + State: title: State - type: string + type: object description: an opaque identifier - example: deadbeefdeadbeefdeadbeefdeadbeef + example: + state: "aae368a064d7c5a433d0bf2c4f5554cc" From 782bcc1a76a45b1e48d3f46e0cfc220fd3b16715 Mon Sep 17 00:00:00 2001 From: Henry Donnay Date: Mon, 6 Jan 2020 10:48:04 -0500 Subject: [PATCH 2/2] Update httptransport.go --- indexer/httptransport.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indexer/httptransport.go b/indexer/httptransport.go index 0a520b91cf..df158366e9 100644 --- a/indexer/httptransport.go +++ b/indexer/httptransport.go @@ -144,7 +144,7 @@ func (h *HTTP) StateHandler(w http.ResponseWriter, r *http.Request) { return } } - w.Header().Set("content-type", "text/plain") + w.Header().Set("content-type", "application/json") err := json.NewEncoder(w).Encode(struct { State string `json:"state"` @@ -157,7 +157,6 @@ func (h *HTTP) StateHandler(w http.ResponseWriter, r *http.Request) { Message: fmt.Sprintf("failed to encode scan report: %v", err), } je.Error(w, resp, http.StatusInternalServerError) - return } return }