Skip to content

Commit

Permalink
#1599 Add metadata in describe API
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 13, 2020
1 parent 0539f12 commit cc8ad7d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
44 changes: 38 additions & 6 deletions thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,39 @@ import scala.util.{Failure, Success, Try}
class DescribeCtrl @Inject() (
cacheApi: SyncCacheApi,
entrypoint: Entrypoint,
caseCtrl: CaseCtrl,
taskCtrl: TaskCtrl,
alertCtrl: AlertCtrl,
auditCtrl: AuditCtrl,
caseCtrl: CaseCtrl,
caseTemplateCtrl: CaseTemplateCtrl,
customFieldCtrl: CustomFieldCtrl,
dashboardCtrl: DashboardCtrl,
logCtrl: LogCtrl,
observableCtrl: ObservableCtrl,
observableTypeCtrl: ObservableTypeCtrl,
organisationCtrl: OrganisationCtrl,
pageCtrl: PageCtrl,
profileCtrl: ProfileCtrl,
taskCtrl: TaskCtrl,
userCtrl: UserCtrl,
logCtrl: LogCtrl,
auditCtrl: AuditCtrl,
customFieldSrv: CustomFieldSrv,
injector: Injector,
@Named("with-thehive-schema") db: Database,
applicationConfig: ApplicationConfig
) {

case class PropertyDescription(name: String, `type`: String, values: Seq[JsValue] = Nil, labels: Seq[String] = Nil)
val metadata = Seq(
PropertyDescription("createdBy", "user"),
PropertyDescription("createdAt", "date"),
PropertyDescription("updatedBy", "user"),
PropertyDescription("updatedAt", "date")
)
case class EntityDescription(label: String, path: String, attributes: Seq[PropertyDescription]) {
def toJson: JsObject =
Json.obj(
"label" -> label,
"path" -> path,
"attributes" -> attributes
"attributes" -> (attributes ++ metadata)
)
}

Expand Down Expand Up @@ -88,7 +101,26 @@ class DescribeCtrl @Inject() (
),
EntityDescription("user", "/user", userCtrl.publicData.publicProperties.list.flatMap(propertyToJson("user", _))),
EntityDescription("case_task_log", "/case/task/log", logCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", "/audit", auditCtrl.publicData.publicProperties.list.flatMap(propertyToJson("audit", _)))
EntityDescription("audit", "/audit", auditCtrl.publicData.publicProperties.list.flatMap(propertyToJson("audit", _))),
EntityDescription(
"caseTemplate",
"/caseTemplate",
caseTemplateCtrl.publicData.publicProperties.list.flatMap(propertyToJson("caseTemplate", _))
),
EntityDescription("customField", "/customField", customFieldCtrl.publicData.publicProperties.list.flatMap(propertyToJson("customField", _))),
EntityDescription(
"observableType",
"/observableType",
observableTypeCtrl.publicData.publicProperties.list.flatMap(propertyToJson("observableType", _))
),
EntityDescription(
"organisation",
"/organisation",
organisationCtrl.publicData.publicProperties.list.flatMap(propertyToJson("organisation", _))
),
EntityDescription("profile", "/profile", profileCtrl.publicData.publicProperties.list.flatMap(propertyToJson("profile", _))),
EntityDescription("dashboard", "/dashboard", dashboardCtrl.publicData.publicProperties.list.flatMap(propertyToJson("dashboard", _))),
EntityDescription("page", "/page", pageCtrl.publicData.publicProperties.list.flatMap(propertyToJson("page", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
}
Expand Down
34 changes: 27 additions & 7 deletions thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ import scala.util.{Failure, Success, Try}
class DescribeCtrl @Inject() (
cacheApi: SyncCacheApi,
entrypoint: Entrypoint,
caseCtrl: CaseCtrl,
taskCtrl: TaskCtrl,
alertCtrl: AlertCtrl,
auditCtrl: AuditCtrl,
caseCtrl: CaseCtrl,
caseTemplateCtrl: CaseTemplateCtrl,
customFieldCtrl: CustomFieldCtrl,
// dashboardCtrl: DashboardCtrl,
logCtrl: LogCtrl,
observableCtrl: ObservableCtrl,
observableTypeCtrl: ObservableTypeCtrl,
organisationCtrl: OrganisationCtrl,
// pageCtrl: PageCtrl,
profileCtrl: ProfileCtrl,
taskCtrl: TaskCtrl,
userCtrl: UserCtrl,
// logCtrl: LogCtrl,
auditCtrl: AuditCtrl,
customFieldSrv: CustomFieldSrv,
impactStatusSrv: ImpactStatusSrv,
resolutionStatusSrv: ResolutionStatusSrv,
Expand All @@ -42,11 +49,17 @@ class DescribeCtrl @Inject() (
) {

case class PropertyDescription(name: String, `type`: String, values: Seq[JsValue] = Nil, labels: Seq[String] = Nil)
val metadata = Seq(
PropertyDescription("_createdBy", "user"),
PropertyDescription("_createdAt", "date"),
PropertyDescription("_updatedBy", "user"),
PropertyDescription("_updatedAt", "date")
)
case class EntityDescription(label: String, attributes: Seq[PropertyDescription]) {
def toJson: JsObject =
Json.obj(
"label" -> label,
"attributes" -> attributes
"attributes" -> (attributes ++ metadata)
)
}

Expand Down Expand Up @@ -81,8 +94,15 @@ class DescribeCtrl @Inject() (
EntityDescription("alert", alertCtrl.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription("case_artifact", observableCtrl.publicProperties.list.flatMap(propertyToJson("case_artifact", _))),
EntityDescription("user", userCtrl.publicProperties.list.flatMap(propertyToJson("user", _))),
// EntityDescription("case_task_log", logCtrl.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", auditCtrl.publicProperties.list.flatMap(propertyToJson("audit", _)))
EntityDescription("case_task_log", logCtrl.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", auditCtrl.publicProperties.list.flatMap(propertyToJson("audit", _))),
EntityDescription("caseTemplate", caseTemplateCtrl.publicProperties.list.flatMap(propertyToJson("caseTemplate", _))),
EntityDescription("customField", customFieldCtrl.publicProperties.list.flatMap(propertyToJson("customField", _))),
EntityDescription("observableType", observableTypeCtrl.publicProperties.list.flatMap(propertyToJson("observableType", _))),
EntityDescription("organisation", organisationCtrl.publicProperties.list.flatMap(propertyToJson("organisation", _))),
EntityDescription("profile", profileCtrl.publicProperties.list.flatMap(propertyToJson("profile", _)))
// EntityDescription("dashboard", dashboardCtrl.publicProperties.list.flatMap(propertyToJson("dashboard", _))),
// EntityDescription("page", pageCtrl.publicProperties.list.flatMap(propertyToJson("page", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
}
Expand Down

0 comments on commit cc8ad7d

Please sign in to comment.