From 3919c8594f8003d5c9d8432594461e36868c6dc5 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Tue, 4 Feb 2020 15:52:48 -0500 Subject: [PATCH] Migration of Fleet -> ingest_manager affect the API paths The migration of the Fleet into the ingest_manager plugin will affect API path. This PR changed the existing routes to reflect that change. We need to synchronize the merge with https://github.com/elastic/kibana/issues/56452 --- .../agent/pkg/agent/application/enroll_cmd_test.go | 8 ++++---- x-pack/agent/pkg/fleetapi/ack_cmd.go | 2 +- x-pack/agent/pkg/fleetapi/ack_cmd_test.go | 2 +- x-pack/agent/pkg/fleetapi/checkin_cmd.go | 2 +- x-pack/agent/pkg/fleetapi/checkin_cmd_test.go | 12 ++++++------ x-pack/agent/pkg/fleetapi/enroll_cmd.go | 4 ++-- x-pack/agent/pkg/fleetapi/enroll_cmd_test.go | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/x-pack/agent/pkg/agent/application/enroll_cmd_test.go b/x-pack/agent/pkg/agent/application/enroll_cmd_test.go index a9b631261d1..75d64dcd2a2 100644 --- a/x-pack/agent/pkg/agent/application/enroll_cmd_test.go +++ b/x-pack/agent/pkg/agent/application/enroll_cmd_test.go @@ -47,7 +47,7 @@ func TestEnroll(t *testing.T) { t.Run("fail to save is propagated", withTLSServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(` { @@ -101,7 +101,7 @@ func TestEnroll(t *testing.T) { t.Run("successfully enroll with TLS and save access api key in the store", withTLSServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(` { @@ -163,7 +163,7 @@ func TestEnroll(t *testing.T) { t.Run("successfully enroll without TLS and save access api key in the store", withServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(` { @@ -223,7 +223,7 @@ func TestEnroll(t *testing.T) { t.Run("fail to enroll without TLS", withServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(` { diff --git a/x-pack/agent/pkg/fleetapi/ack_cmd.go b/x-pack/agent/pkg/fleetapi/ack_cmd.go index 00d14cf13aa..b6a2e4e4ee0 100644 --- a/x-pack/agent/pkg/fleetapi/ack_cmd.go +++ b/x-pack/agent/pkg/fleetapi/ack_cmd.go @@ -14,7 +14,7 @@ import ( "github.com/elastic/beats/x-pack/agent/pkg/agent/errors" ) -const ackPath = "/api/fleet/agents/%s/acks" +const ackPath = "/api/ingest_manager/fleet/agents/%s/acks" // AckRequest consists of multiple actions acked to fleet ui. // POST /agents/{agentId}/acks diff --git a/x-pack/agent/pkg/fleetapi/ack_cmd_test.go b/x-pack/agent/pkg/fleetapi/ack_cmd_test.go index 62b324f924b..7495d60dd0e 100644 --- a/x-pack/agent/pkg/fleetapi/ack_cmd_test.go +++ b/x-pack/agent/pkg/fleetapi/ack_cmd_test.go @@ -27,7 +27,7 @@ func TestAck(t *testing.T) { } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/acks", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/acks", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) diff --git a/x-pack/agent/pkg/fleetapi/checkin_cmd.go b/x-pack/agent/pkg/fleetapi/checkin_cmd.go index 65b19adb721..aa8f63d1f42 100644 --- a/x-pack/agent/pkg/fleetapi/checkin_cmd.go +++ b/x-pack/agent/pkg/fleetapi/checkin_cmd.go @@ -15,7 +15,7 @@ import ( "github.com/elastic/beats/x-pack/agent/pkg/agent/errors" ) -const checkingPath = "/api/fleet/agents/%s/checkin" +const checkingPath = "/api/ingest_manager/fleet/agents/%s/checkin" // CheckinRequest consists of multiple events reported to fleet ui. type CheckinRequest struct { diff --git a/x-pack/agent/pkg/fleetapi/checkin_cmd_test.go b/x-pack/agent/pkg/fleetapi/checkin_cmd_test.go index 05fbd153da8..3f92feac692 100644 --- a/x-pack/agent/pkg/fleetapi/checkin_cmd_test.go +++ b/x-pack/agent/pkg/fleetapi/checkin_cmd_test.go @@ -32,7 +32,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) fmt.Fprintf(w, raw) @@ -83,7 +83,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, raw) @@ -145,7 +145,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, raw) @@ -183,7 +183,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, raw) @@ -212,7 +212,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { type Request struct { Metadata map[string]interface{} `json:"local_metadata"` @@ -262,7 +262,7 @@ Something went wrong } ` mux := http.NewServeMux() - path := fmt.Sprintf("/api/fleet/agents/%s/checkin", agentInfo.AgentID()) + path := fmt.Sprintf("/api/ingest_manager/fleet/agents/%s/checkin", agentInfo.AgentID()) mux.HandleFunc(path, authHandler(func(w http.ResponseWriter, r *http.Request) { req := make(map[string]interface{}) diff --git a/x-pack/agent/pkg/fleetapi/enroll_cmd.go b/x-pack/agent/pkg/fleetapi/enroll_cmd.go index 64dbebbe417..c8ccec36556 100644 --- a/x-pack/agent/pkg/fleetapi/enroll_cmd.go +++ b/x-pack/agent/pkg/fleetapi/enroll_cmd.go @@ -67,7 +67,7 @@ func (p EnrollType) MarshalJSON() ([]byte, error) { // EnrollRequest is the data required to enroll the agent into Fleet. // // Example: -// POST /api/fleet/agents/enroll +// POST /api/ingest_manager/fleet/agents/enroll // { // "type": "PERMANENT", // "metadata": { @@ -166,7 +166,7 @@ type EnrollCmd struct { // Execute enroll the Agent in the Fleet. func (e *EnrollCmd) Execute(ctx context.Context, r *EnrollRequest) (*EnrollResponse, error) { - const p = "/api/fleet/agents/enroll" + const p = "/api/ingest_manager/fleet/agents/enroll" const key = "Authorization" const prefix = "ApiKey " diff --git a/x-pack/agent/pkg/fleetapi/enroll_cmd_test.go b/x-pack/agent/pkg/fleetapi/enroll_cmd_test.go index 05a8d0d4222..7003f6d0772 100644 --- a/x-pack/agent/pkg/fleetapi/enroll_cmd_test.go +++ b/x-pack/agent/pkg/fleetapi/enroll_cmd_test.go @@ -22,7 +22,7 @@ func TestEnroll(t *testing.T) { t.Run("Successful enroll", withServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") @@ -97,7 +97,7 @@ func TestEnroll(t *testing.T) { t.Run("Raise back any server errors", withServer( func(t *testing.T) *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/api/ingest_manager/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"statusCode": 500, "error":"Something is really bad here"}`))