in http-server/src/main/scala/com/twitter/finatra/http/routing/AdminHttpRouter.scala [30:84]
def addAdminRoutes(
server: AdminHttpServer,
router: HttpRouter,
twitterServerAdminRoutes: Seq[AdminHttpServer.Route]
): Unit = {
val allTwitterServerAdminRoutes = twitterServerAdminRoutes.map(_.path).union(HttpMuxer.patterns)
val duplicates = allTwitterServerAdminRoutes.intersect(router.routesByType.admin.map(_.path))
if (duplicates.nonEmpty) {
val errorMsg = "Duplicating pre-defined TwitterServer AdminHttpServer routes is not allowed."
val message = "The following routes are duplicates of pre-defined TwitterServer admin routes:"
error(s"$message \n\t${duplicates.mkString("\n\t")}")
error(errorMsg)
throw new java.lang.AssertionError(errorMsg)
}
// Partition routes into admin index routes and admin rich handler routes
val (adminIndexRoutes, adminRichHandlerRoutes) = router.routesByType.admin.partition { route =>
// admin index routes cannot start with /admin/finatra/ and must be a constant route
!route.path.startsWith(HttpRouter.FinatraAdminPrefix) && route.constantRoute
}
// Run linting rule for routes
GlobalRules.get.add(
Rule(
Category.Configuration,
"Non-indexable HTTP Admin Interface Finatra Routes",
s"""Only constant /GET or /POST routes prefixed with "/admin" that DO NOT begin
|with "${HttpRouter.FinatraAdminPrefix}" can be added to the TwitterServer
|HTTP Admin Interface index.""".stripMargin
) {
Seq(
checkRoutesWithRouteIndex(adminRichHandlerRoutes) { _ =>
true
},
checkRoutesWithRouteIndex(adminIndexRoutes) { !canIndexRoute(_) }
).flatten
}
)
// Add constant routes to admin index
server
.addAdminRoutes(
toAdminHttpServerRoutes(adminIndexRoutes, router)
.map(AdminThreadPoolFilter.isolateRoute)
)
// Add rich handler for all other routes
if (adminRichHandlerRoutes.nonEmpty) {
HttpMuxer
.addRichHandler(
HttpRouter.FinatraAdminPrefix,
AdminThreadPoolFilter.isolateService(router.services.adminService)
)
}
}