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

removed all non control plane routes #2192

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
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
168 changes: 24 additions & 144 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {

handler := &handlers.Handler{A: a.A, RM: a.rm}

// TODO(subomi): left this here temporarily till the data plane is stable.
// Ingestion API.
router.Route("/ingest", func(ingestRouter chi.Router) {
ingestRouter.Use(middleware.RateLimiterHandler(a.A.Rate, a.cfg.ApiRateLimit))
ingestRouter.Get("/{maskID}", a.HandleCrcCheck)
ingestRouter.Post("/{maskID}", a.IngestEvent)
})

// Public API.
router.Route("/api", func(v1Router chi.Router) {
v1Router.Route("/v1", func(r chi.Router) {
Expand Down Expand Up @@ -165,49 +157,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {
})
})

// TODO(subomi): left this here temporarily till the data plane is stable.
projectSubRouter.Route("/events", func(eventRouter chi.Router) {
eventRouter.Route("/", func(writeEventRouter chi.Router) {
eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged)
eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents)

// TODO(all): should the InstrumentPath change?
eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/", handler.CreateEndpointEvent)
eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/fanout", handler.CreateEndpointFanoutEvent)
eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/broadcast", handler.CreateBroadcastEvent)
eventRouter.With(handler.RequireEnabledProject(), middleware.InstrumentPath(a.A.Licenser)).Post("/dynamic", handler.CreateDynamicEvent)
eventRouter.With(handler.RequireEnabledProject()).Post("/batchreplay", handler.BatchReplayEvents)

eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) {
eventSubRouter.With(handler.RequireEnabledProject()).Put("/replay", handler.ReplayEndpointEvent)
eventSubRouter.Get("/", handler.GetEndpointEvent)
})
})
})

projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) {
eventTypesRouter.Get("/", handler.GetEventTypes)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType)
})

projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) {
eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged)
eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/forceresend", handler.ForceResendEventDeliveries)
eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/batchretry", handler.BatchRetryEventDelivery)

eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) {
eventDeliverySubRouter.Get("/", handler.GetEventDelivery)
eventDeliverySubRouter.With(handler.RequireEnabledProject()).Put("/resend", handler.ResendEventDelivery)

eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) {
deliveryRouter.Get("/", handler.GetDeliveryAttempts)
deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt)
})
})
})

projectSubRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) {
subscriptionRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateSubscription)
subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter)
Expand Down Expand Up @@ -250,8 +199,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {
})
})



// Dashboard API.
router.Route("/ui", func(uiRouter chi.Router) {
uiRouter.Use(middleware.JsonResponse)
Expand All @@ -274,11 +221,11 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {
authRouter.Post("/logout", handler.LogoutUser)
})

uiRouter.Route("/saml", func(samlRouter chi.Router) {
samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser))
samlRouter.Get("/login", handler.RedeemLoginSSOToken)
samlRouter.Get("/register", handler.RedeemRegisterSSOToken)
})
uiRouter.Route("/saml", func(samlRouter chi.Router) {
samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser))
samlRouter.Get("/login", handler.RedeemLoginSSOToken)
samlRouter.Get("/register", handler.RedeemRegisterSSOToken)
})

uiRouter.Route("/users", func(userRouter chi.Router) {
userRouter.Route("/{userID}", func(userSubRouter chi.Router) {
Expand Down Expand Up @@ -350,48 +297,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {
})
})

// TODO(subomi): left this here temporarily till the data plane is stable.
projectSubRouter.Route("/events", func(eventRouter chi.Router) {
eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged)
eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents)

// TODO(all): should the InstrumentPath change?
eventRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEndpointEvent)
eventRouter.With(handler.RequireEnabledProject()).Post("/fanout", handler.CreateEndpointFanoutEvent)
eventRouter.With(handler.RequireEnabledProject()).Post("/broadcast", handler.CreateBroadcastEvent)
eventRouter.With(handler.RequireEnabledProject()).Post("/dynamic", handler.CreateDynamicEvent)
eventRouter.With(handler.RequireEnabledProject()).Post("/batchreplay", handler.BatchReplayEvents)

eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) {
eventSubRouter.With(handler.RequireEnabledProject()).Put("/replay", handler.ReplayEndpointEvent)
eventSubRouter.Get("/", handler.GetEndpointEvent)
})
})

projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) {
eventTypesRouter.Get("/", handler.GetEventTypes)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType)
})

projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) {
eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged)
eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/forceresend", handler.ForceResendEventDeliveries)
eventDeliveryRouter.With(handler.RequireEnabledProject()).Post("/batchretry", handler.BatchRetryEventDelivery)
eventDeliveryRouter.Get("/countbatchretryevents", handler.CountAffectedEventDeliveries)

eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) {
eventDeliverySubRouter.Get("/", handler.GetEventDelivery)
eventDeliverySubRouter.With(handler.RequireEnabledProject()).Put("/resend", handler.ResendEventDelivery)

eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) {
deliveryRouter.Get("/", handler.GetDeliveryAttempts)
deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt)
})
})
})

projectSubRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) {
subscriptionRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateSubscription)
subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter)
Expand Down Expand Up @@ -462,43 +367,6 @@ func (a *ApplicationHandler) BuildControlPlaneRoutes() *chi.Mux {
endpointRouter.With(handler.CanManageEndpoint()).Put("/{endpointID}/expire_secret", handler.ExpireSecret)
})

// TODO(subomi): left this here temporarily till the data plane is stable.
portalLinkRouter.Route("/events", func(eventRouter chi.Router) {
eventRouter.Post("/", handler.CreateEndpointEvent)
eventRouter.With(middleware.Pagination).Get("/", handler.GetEventsPaged)
eventRouter.Post("/batchreplay", handler.BatchReplayEvents)
eventRouter.Get("/countbatchreplayevents", handler.CountAffectedEvents)

eventRouter.Route("/{eventID}", func(eventSubRouter chi.Router) {
eventSubRouter.Get("/", handler.GetEndpointEvent)
eventSubRouter.Put("/replay", handler.ReplayEndpointEvent)
})
})

portalLinkRouter.Route("/event-types", func(eventTypesRouter chi.Router) {
eventTypesRouter.Get("/", handler.GetEventTypes)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType)
})

portalLinkRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) {
eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged)
eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries)
eventDeliveryRouter.Post("/batchretry", handler.BatchRetryEventDelivery)
eventDeliveryRouter.Get("/countbatchretryevents", handler.CountAffectedEventDeliveries)

eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) {
eventDeliverySubRouter.Get("/", handler.GetEventDelivery)
eventDeliverySubRouter.Put("/resend", handler.ResendEventDelivery)

eventDeliverySubRouter.Route("/deliveryattempts", func(deliveryRouter chi.Router) {
deliveryRouter.Get("/", handler.GetDeliveryAttempts)
deliveryRouter.Get("/{deliveryAttemptID}", handler.GetDeliveryAttempt)
})
})
})

portalLinkRouter.Route("/subscriptions", func(subscriptionRouter chi.Router) {
subscriptionRouter.Post("/", handler.CreateSubscription)
subscriptionRouter.Post("/test_filter", handler.TestSubscriptionFilter)
Expand Down Expand Up @@ -575,6 +443,13 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux {
})
})

projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) {
eventTypesRouter.Get("/", handler.GetEventTypes)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType)
})

projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) {
eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged)
eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries)
Expand All @@ -595,8 +470,6 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux {
})
})



// Dashboard API.
router.Route("/ui", func(uiRouter chi.Router) {
uiRouter.Use(middleware.JsonResponse)
Expand All @@ -612,11 +485,11 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux {
authRouter.Post("/logout", handler.LogoutUser)
})

uiRouter.Route("/saml", func(samlRouter chi.Router) {
samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser))
samlRouter.Get("/login", handler.RedeemLoginSSOToken)
samlRouter.Get("/register", handler.RedeemRegisterSSOToken)
})
uiRouter.Route("/saml", func(samlRouter chi.Router) {
samlRouter.Use(middleware.RequireValidEnterpriseSSOLicense(handler.A.Licenser))
samlRouter.Get("/login", handler.RedeemLoginSSOToken)
samlRouter.Get("/register", handler.RedeemRegisterSSOToken)
})

uiRouter.Route("/organisations", func(orgRouter chi.Router) {
orgRouter.Route("/{orgID}", func(orgSubRouter chi.Router) {
Expand All @@ -635,6 +508,13 @@ func (a *ApplicationHandler) BuildDataPlaneRoutes() *chi.Mux {
})
})

projectSubRouter.Route("/event-types", func(eventTypesRouter chi.Router) {
eventTypesRouter.Get("/", handler.GetEventTypes)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/", handler.CreateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Put("/{eventTypeId}", handler.UpdateEventType)
eventTypesRouter.With(handler.RequireEnabledProject()).Post("/{eventTypeId}/deprecate", handler.DeprecateEventType)
})

projectSubRouter.Route("/eventdeliveries", func(eventDeliveryRouter chi.Router) {
eventDeliveryRouter.With(middleware.Pagination).Get("/", handler.GetEventDeliveriesPaged)
eventDeliveryRouter.Post("/forceresend", handler.ForceResendEventDeliveries)
Expand Down
26 changes: 14 additions & 12 deletions api/dashboard_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ type EventIntegrationTestSuite struct {
suite.Suite
DB database.Database
Router http.Handler
DPRouter http.Handler
ConvoyApp *ApplicationHandler
AuthenticatorFn AuthenticatorFn
DefaultOrg *datastore.Organisation
Expand All @@ -1052,6 +1053,7 @@ func (s *EventIntegrationTestSuite) SetupSuite() {
s.DB = getDB()
s.ConvoyApp = buildServer()
s.Router = s.ConvoyApp.BuildControlPlaneRoutes()
s.DPRouter = s.ConvoyApp.BuildDataPlaneRoutes()
}

func (s *EventIntegrationTestSuite) SetupTest() {
Expand Down Expand Up @@ -1109,7 +1111,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1147,7 +1149,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent_With_App_ID_Valid_E

w := httptest.NewRecorder()
// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand All @@ -1171,7 +1173,7 @@ func (s *EventIntegrationTestSuite) Test_CreateEndpointEvent_Endpoint_is_disable

w := httptest.NewRecorder()
// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand All @@ -1197,7 +1199,7 @@ func (s *EventIntegrationTestSuite) Test_GetEndpointEvent_Valid_Event() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1225,7 +1227,7 @@ func (s *EventIntegrationTestSuite) Test_ReplayEndpointEvent_Valid_Event() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1275,7 +1277,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventDelivery_Valid_EventDelivery()
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1334,7 +1336,7 @@ func (s *EventIntegrationTestSuite) Test_ResendEventDelivery_Valid_Resend() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1376,7 +1378,7 @@ func (s *EventIntegrationTestSuite) Test_BatchRetryEventDelivery_Valid_EventDeli
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1412,7 +1414,7 @@ func (s *EventIntegrationTestSuite) Test_CountAffectedEventDeliveries_Valid_Filt
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1457,7 +1459,7 @@ func (s *EventIntegrationTestSuite) Test_ForceResendEventDeliveries_Valid_EventD
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1510,7 +1512,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventsPaged() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down Expand Up @@ -1568,7 +1570,7 @@ func (s *EventIntegrationTestSuite) Test_GetEventDeliveriesPaged() {
w := httptest.NewRecorder()

// Act.
s.Router.ServeHTTP(w, req)
s.DPRouter.ServeHTTP(w, req)

// Assert.
require.Equal(s.T(), expectedStatusCode, w.Code)
Expand Down
Loading
Loading