Skip to content

Commit

Permalink
Change license get call to handle expected 204
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Feb 5, 2021
1 parent 0103622 commit d3a64ff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
22 changes: 20 additions & 2 deletions api/operator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"strconv"
Expand Down Expand Up @@ -297,10 +299,26 @@ func (op *Operator) LicensePut(license string, q *WriteOptions) (*WriteMeta, err
}

func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, *QueryMeta, error) {
req, err := op.c.newRequest("GET", "/v1/operator/license")
if err != nil {
return nil, nil, err
}

var reply LicenseReply
qm, err := op.c.query("/v1/operator/license", &reply, q)
_, resp, err := op.c.doRequest(req)
if err != nil {
return nil, nil, err
}
return &reply, qm, nil
defer resp.Body.Close()

if resp.StatusCode == 204 {
return nil, nil, errors.New("Nomad Enterprise only endpoint")
}

err = json.NewDecoder(resp.Body).Decode(&reply)
if err == nil {
return &reply, nil, nil
}

return nil, nil, err
}
2 changes: 1 addition & 1 deletion command/agent/operator_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (s *HTTPServer) LicenseRequest(resp http.ResponseWriter, req *http.Request)
switch req.Method {
case "GET":
resp.WriteHeader(http.StatusNoContent)
return "", nil
return nil, nil
default:
return nil, CodedError(405, ErrInvalidMethod)
}
Expand Down
22 changes: 20 additions & 2 deletions vendor/github.com/hashicorp/nomad/api/operator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3a64ff

Please sign in to comment.