Skip to content

Commit

Permalink
Merge pull request #897 from ldelossa/louis/state-json
Browse files Browse the repository at this point in the history
json state endpoint to json
  • Loading branch information
Louis DeLosSantos committed Jan 6, 2020
2 parents af4cd6e + 782bcc1 commit d099773
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 15 additions & 4 deletions indexer/httptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,21 @@ func (h *HTTP) StateHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
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)
w.Header().Set("content-type", "application/json")

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
}

// Register will register the api on a given mux.
Expand Down
10 changes: 6 additions & 4 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"

0 comments on commit d099773

Please sign in to comment.