Skip to content

Commit

Permalink
#2144 Add API for index rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 23, 2021
1 parent 80ccc7f commit 3c1ad94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/AdminCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ class AdminCtrl @Inject() (
Success(Results.NoContent)
}

def rebuild(name: String): Action[AnyContent] =
entrypoint("Rebuild index")
.authPermitted(Permissions.managePlatform) { _ =>
db
.removeIndex(name, IndexType.fulltext, Nil)
.flatMap(_ => schemas.toTry(db.addSchemaIndexes))
.map(_ => Results.NoContent)
}

private val rangeRegex = "(\\d+)-(\\d+)".r
private def getOperations(schemaName: String, select: Option[String], filter: Option[String]): Seq[(Operation, Int)] = {
val ranges = select.fold(Seq(0 until Int.MaxValue))(_.split(',').toSeq.map {
Expand Down
1 change: 1 addition & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Router @Inject() (
case GET(p"/admin/check/$name/trigger") => adminCtrl.triggerCheck(name)
case GET(p"/admin/index/status") => adminCtrl.indexStatus
case GET(p"/admin/index/$name/reindex") => adminCtrl.reindex(name)
case POST(p"/admin/index/$name/rebuild") => adminCtrl.rebuild(name)
case GET(p"/admin/log/set/$packageName/$level") => adminCtrl.setLogLevel(packageName, level)
case POST(p"/admin/schema/repair/$schemaName" ? q_o"select=$select" ? q_o"filter=$filter") => adminCtrl.schemaRepair(schemaName, select, filter)
case POST(p"/admin/schema/info/$schemaName" ? q_o"select=$select" ? q_o"filter=$filter") => adminCtrl.schemaInfo(schemaName, select, filter)
Expand Down

0 comments on commit 3c1ad94

Please sign in to comment.