Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling for license requests in OSS #9963

Merged
merged 4 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
1 change: 1 addition & 0 deletions command/agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {

s.mux.HandleFunc("/v1/search", s.wrap(s.SearchRequest))

s.mux.HandleFunc("/v1/operator/license", s.wrap(s.LicenseRequest))
s.mux.HandleFunc("/v1/operator/raft/", s.wrap(s.OperatorRequest))
s.mux.HandleFunc("/v1/operator/autopilot/configuration", s.wrap(s.OperatorAutopilotConfiguration))
s.mux.HandleFunc("/v1/operator/autopilot/health", s.wrap(s.OperatorServerHealth))
Expand Down
2 changes: 0 additions & 2 deletions command/agent/http_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ func (s *HTTPServer) registerEnterpriseHandlers() {
s.mux.HandleFunc("/v1/quota/", s.wrap(s.entOnly))
s.mux.HandleFunc("/v1/quota", s.wrap(s.entOnly))

s.mux.HandleFunc("/v1/operator/license", s.wrap(s.entOnly))

s.mux.HandleFunc("/v1/recommendation", s.wrap(s.entOnly))
s.mux.HandleFunc("/v1/recommendations", s.wrap(s.entOnly))
s.mux.HandleFunc("/v1/recommendations/apply", s.wrap(s.entOnly))
Expand Down
20 changes: 20 additions & 0 deletions command/agent/operator_endpoint_oss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build !ent

package agent

import (
"net/http"
)

func (s *HTTPServer) LicenseRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
switch req.Method {
case "GET":
resp.WriteHeader(http.StatusNoContent)
return nil, nil
case "PUT":
return nil, CodedError(501, ErrEntOnly)
default:
return nil, CodedError(405, ErrInvalidMethod)
}

}
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.