mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
Add handling for license requests in OSS (#9963)
This changes the license-fetching endpoint to respond with 204 in OSS instead of 501. It closes #9827.
This commit is contained in:
@@ -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) {
|
||||
var reply LicenseReply
|
||||
qm, err := op.c.query("/v1/operator/license", &reply, q)
|
||||
req, err := op.c.newRequest("GET", "/v1/operator/license")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return &reply, qm, nil
|
||||
|
||||
var reply LicenseReply
|
||||
_, resp, err := op.c.doRequest(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
20
command/agent/operator_endpoint_oss.go
Normal file
20
command/agent/operator_endpoint_oss.go
Normal file
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
24
vendor/github.com/hashicorp/nomad/api/operator.go
generated
vendored
24
vendor/github.com/hashicorp/nomad/api/operator.go
generated
vendored
@@ -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) {
|
||||
var reply LicenseReply
|
||||
qm, err := op.c.query("/v1/operator/license", &reply, q)
|
||||
req, err := op.c.newRequest("GET", "/v1/operator/license")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return &reply, qm, nil
|
||||
|
||||
var reply LicenseReply
|
||||
_, resp, err := op.c.doRequest(req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user