2019-10-24 18:38:09 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
2017-11-29 00:06:26 +00:00
|
|
|
package agent
|
|
|
|
|
2019-10-24 18:38:09 +00:00
|
|
|
import (
|
2019-12-06 16:14:56 +00:00
|
|
|
"fmt"
|
2019-10-24 18:38:09 +00:00
|
|
|
"net/http"
|
2019-12-06 16:14:56 +00:00
|
|
|
"strings"
|
2019-10-24 18:38:09 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
2018-02-18 01:31:24 +00:00
|
|
|
|
2019-12-06 16:14:56 +00:00
|
|
|
func (s *HTTPServer) parseEntMeta(req *http.Request, entMeta *structs.EnterpriseMeta) error {
|
|
|
|
if headerNS := req.Header.Get("X-Consul-Namespace"); headerNS != "" {
|
|
|
|
return BadRequestError{Reason: "Invalid header: \"X-Consul-Namespace\" - Namespaces is a Consul Enterprise feature"}
|
|
|
|
}
|
|
|
|
if queryNS := req.URL.Query().Get("ns"); queryNS != "" {
|
|
|
|
return BadRequestError{Reason: "Invalid query parameter: \"ns\" - Namespaces is a Consul Enterprise feature"}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HTTPServer) rewordUnknownEnterpriseFieldError(err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := err.Error()
|
|
|
|
|
|
|
|
if strings.Contains(msg, "json: unknown field ") {
|
|
|
|
quotedField := strings.TrimPrefix(msg, "json: unknown field ")
|
|
|
|
|
|
|
|
switch quotedField {
|
|
|
|
case `"Namespace"`:
|
|
|
|
return fmt.Errorf("%v - Namespaces is a Consul Enterprise feature", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
2017-11-29 00:06:26 +00:00
|
|
|
}
|