diff --git a/api/operator.go b/api/operator.go index d5bc5d061d5..a4d8c56c2d1 100644 --- a/api/operator.go +++ b/api/operator.go @@ -1,6 +1,8 @@ package api import ( + "encoding/json" + "errors" "io" "io/ioutil" "strconv" @@ -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 } diff --git a/command/agent/operator_endpoint.go b/command/agent/operator_endpoint.go index f2bd6b20561..c1084e1574d 100644 --- a/command/agent/operator_endpoint.go +++ b/command/agent/operator_endpoint.go @@ -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) } diff --git a/vendor/github.com/hashicorp/nomad/api/operator.go b/vendor/github.com/hashicorp/nomad/api/operator.go index d5bc5d061d5..a4d8c56c2d1 100644 --- a/vendor/github.com/hashicorp/nomad/api/operator.go +++ b/vendor/github.com/hashicorp/nomad/api/operator.go @@ -1,6 +1,8 @@ package api import ( + "encoding/json" + "errors" "io" "io/ioutil" "strconv" @@ -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 }