Skip to content

Commit

Permalink
#312 Add API to describe attributes of all entities
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om authored and nadouani committed Oct 19, 2017
1 parent 29845a1 commit a8e026b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions thehive-backend/app/controllers/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import javax.inject.{ Inject, Singleton }

import scala.concurrent.ExecutionContext

import play.api.libs.json.{ JsObject, Json }
import play.api.mvc.{ AbstractController, Action, AnyContent, ControllerComponents }

import models.Roles
Expand Down Expand Up @@ -32,4 +33,17 @@ class DescribeCtrl @Inject() (
}
.getOrElse(NotFound(s"Model $modelName not found"))
}

private val allModels: Seq[String] = Seq("case", "case_artifact", "case_task", "alert")
def describeAll: Action[AnyContent] = authenticated(Roles.read) { implicit request
val entityDefinitions = modelSrv.list
.collect {
case model if allModels.contains(model.name)
val attributeDefinitions = model.attributes.flatMap {
case attribute: Attribute[t] attribute.format.definition(dblists, attribute)
}
model.name Json.toJson(attributeDefinitions)
}
renderer.toOutput(OK, JsObject(entityDefinitions))
}
}
1 change: 1 addition & 0 deletions thehive-backend/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ POST /api/stream controllers.StreamCtrl.create(
GET /api/stream/status controllers.StreamCtrl.status
GET /api/stream/:streamId controllers.StreamCtrl.get(streamId)

GET /api/describe/_all controllers.DescribeCtrl.describeAll
GET /api/describe/:modelName controllers.DescribeCtrl.describe(modelName)

-> /api/connector connectors.ConnectorRouter
Expand Down

0 comments on commit a8e026b

Please sign in to comment.