|
|
|
@ -380,7 +380,10 @@ func (s *HTTPHandlers) AgentServices(resp http.ResponseWriter, req *http.Request
|
|
|
|
|
// blocking watch using hash-based blocking.
|
|
|
|
|
func (s *HTTPHandlers) AgentService(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
// Get the proxy ID. Note that this is the ID of a proxy's service instance.
|
|
|
|
|
id := strings.TrimPrefix(req.URL.Path, "/v1/agent/service/")
|
|
|
|
|
id, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/service/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maybe block
|
|
|
|
|
var queryOpts structs.QueryOptions
|
|
|
|
@ -400,7 +403,7 @@ func (s *HTTPHandlers) AgentService(resp http.ResponseWriter, req *http.Request)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// need to resolve to default the meta
|
|
|
|
|
_, err := s.agent.delegate.ResolveTokenAndDefaultMeta(token, &entMeta, nil)
|
|
|
|
|
_, err = s.agent.delegate.ResolveTokenAndDefaultMeta(token, &entMeta, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -641,7 +644,10 @@ func (s *HTTPHandlers) AgentJoin(resp http.ResponseWriter, req *http.Request) (i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the address
|
|
|
|
|
addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/join/")
|
|
|
|
|
addr, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/join/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if wan {
|
|
|
|
|
if s.agent.config.ConnectMeshGatewayWANFederationEnabled {
|
|
|
|
@ -701,7 +707,10 @@ func (s *HTTPHandlers) AgentForceLeave(resp http.ResponseWriter, req *http.Reque
|
|
|
|
|
// Check if the WAN is being queried
|
|
|
|
|
_, wan := req.URL.Query()["wan"]
|
|
|
|
|
|
|
|
|
|
addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/force-leave/")
|
|
|
|
|
addr, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/force-leave/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if wan {
|
|
|
|
|
return nil, s.agent.ForceLeaveWAN(addr, prune, entMeta)
|
|
|
|
|
} else {
|
|
|
|
@ -788,7 +797,11 @@ func (s *HTTPHandlers) AgentRegisterCheck(resp http.ResponseWriter, req *http.Re
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentDeregisterCheck(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
checkID := structs.NewCheckID(types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/deregister/")), nil)
|
|
|
|
|
ID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/check/deregister/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
checkID := structs.NewCheckID(types.CheckID(ID), nil)
|
|
|
|
|
|
|
|
|
|
// Get the provided token, if any, and vet against any ACL policies.
|
|
|
|
|
var token string
|
|
|
|
@ -822,13 +835,21 @@ func (s *HTTPHandlers) AgentDeregisterCheck(resp http.ResponseWriter, req *http.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentCheckPass(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/pass/"))
|
|
|
|
|
ID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/check/pass/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
checkID := types.CheckID(ID)
|
|
|
|
|
note := req.URL.Query().Get("note")
|
|
|
|
|
return s.agentCheckUpdate(resp, req, checkID, api.HealthPassing, note)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentCheckWarn(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/warn/"))
|
|
|
|
|
ID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/check/warn/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
checkID := types.CheckID(ID)
|
|
|
|
|
note := req.URL.Query().Get("note")
|
|
|
|
|
|
|
|
|
|
return s.agentCheckUpdate(resp, req, checkID, api.HealthWarning, note)
|
|
|
|
@ -836,7 +857,11 @@ func (s *HTTPHandlers) AgentCheckWarn(resp http.ResponseWriter, req *http.Reques
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentCheckFail(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/fail/"))
|
|
|
|
|
ID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/check/fail/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
checkID := types.CheckID(ID)
|
|
|
|
|
note := req.URL.Query().Get("note")
|
|
|
|
|
|
|
|
|
|
return s.agentCheckUpdate(resp, req, checkID, api.HealthCritical, note)
|
|
|
|
@ -875,7 +900,12 @@ func (s *HTTPHandlers) AgentCheckUpdate(resp http.ResponseWriter, req *http.Requ
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkID := types.CheckID(strings.TrimPrefix(req.URL.Path, "/v1/agent/check/update/"))
|
|
|
|
|
ID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/check/update/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkID := types.CheckID(ID)
|
|
|
|
|
|
|
|
|
|
return s.agentCheckUpdate(resp, req, checkID, update.Status, update.Output)
|
|
|
|
|
}
|
|
|
|
@ -958,7 +988,10 @@ func returnTextPlain(req *http.Request) bool {
|
|
|
|
|
// AgentHealthServiceByID return the local Service Health given its ID
|
|
|
|
|
func (s *HTTPHandlers) AgentHealthServiceByID(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
// Pull out the service id (service id since there may be several instance of the same service on this host)
|
|
|
|
|
serviceID := strings.TrimPrefix(req.URL.Path, "/v1/agent/health/service/id/")
|
|
|
|
|
serviceID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/health/service/id/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if serviceID == "" {
|
|
|
|
|
return nil, &BadRequestError{Reason: "Missing serviceID"}
|
|
|
|
|
}
|
|
|
|
@ -1017,7 +1050,11 @@ func (s *HTTPHandlers) AgentHealthServiceByID(resp http.ResponseWriter, req *htt
|
|
|
|
|
// AgentHealthServiceByName return the worse status of all the services with given name on an agent
|
|
|
|
|
func (s *HTTPHandlers) AgentHealthServiceByName(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
// Pull out the service name
|
|
|
|
|
serviceName := strings.TrimPrefix(req.URL.Path, "/v1/agent/health/service/name/")
|
|
|
|
|
serviceName, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/health/service/name/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if serviceName == "" {
|
|
|
|
|
return nil, &BadRequestError{Reason: "Missing service Name"}
|
|
|
|
|
}
|
|
|
|
@ -1247,7 +1284,12 @@ func (s *HTTPHandlers) AgentRegisterService(resp http.ResponseWriter, req *http.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentDeregisterService(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
sid := structs.NewServiceID(strings.TrimPrefix(req.URL.Path, "/v1/agent/service/deregister/"), nil)
|
|
|
|
|
serviceID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/service/deregister/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sid := structs.NewServiceID(serviceID, nil)
|
|
|
|
|
|
|
|
|
|
// Get the provided token, if any, and vet against any ACL policies.
|
|
|
|
|
var token string
|
|
|
|
@ -1283,7 +1325,12 @@ func (s *HTTPHandlers) AgentDeregisterService(resp http.ResponseWriter, req *htt
|
|
|
|
|
|
|
|
|
|
func (s *HTTPHandlers) AgentServiceMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
// Ensure we have a service ID
|
|
|
|
|
sid := structs.NewServiceID(strings.TrimPrefix(req.URL.Path, "/v1/agent/service/maintenance/"), nil)
|
|
|
|
|
serviceID, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/service/maintenance/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sid := structs.NewServiceID(serviceID, nil)
|
|
|
|
|
|
|
|
|
|
if sid.ID == "" {
|
|
|
|
|
resp.WriteHeader(http.StatusBadRequest)
|
|
|
|
@ -1496,7 +1543,10 @@ func (s *HTTPHandlers) AgentToken(resp http.ResponseWriter, req *http.Request) (
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Figure out the target token.
|
|
|
|
|
target := strings.TrimPrefix(req.URL.Path, "/v1/agent/token/")
|
|
|
|
|
target, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/token/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = s.agent.tokens.WithPersistenceLock(func() error {
|
|
|
|
|
triggerAntiEntropySync := false
|
|
|
|
@ -1569,7 +1619,10 @@ func (s *HTTPHandlers) AgentConnectCARoots(resp http.ResponseWriter, req *http.R
|
|
|
|
|
func (s *HTTPHandlers) AgentConnectCALeafCert(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
|
|
|
|
// Get the service name. Note that this is the name of the service,
|
|
|
|
|
// not the ID of the service instance.
|
|
|
|
|
serviceName := strings.TrimPrefix(req.URL.Path, "/v1/agent/connect/ca/leaf/")
|
|
|
|
|
serviceName, err := getPathSuffixUnescaped(req.URL.Path, "/v1/agent/connect/ca/leaf/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := cachetype.ConnectCALeafRequest{
|
|
|
|
|
Service: serviceName, // Need name not ID
|
|
|
|
|