Skip to content

Commit

Permalink
#65 Add PAP attribute in job entity
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 30, 2018
1 parent 921678d commit 9669c7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/org/thp/cortex/models/Job.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ trait JobAttributes {
val data = optionalAttribute("data", F.stringFmt, "Content of the artifact", O.readonly)
val attachment = optionalAttribute("attachment", F.attachmentFmt, "Artifact file content", O.readonly)
val tlp = attribute("tlp", TlpAttributeFormat, "TLP level", 2L)
val pap = attribute("pap", TlpAttributeFormat, "PAP level", 2L)
val message = optionalAttribute("message", F.textFmt, "Message associated to the analysis")
val errorMessage = optionalAttribute("message", F.textFmt, "Message returned by the worker when it fails")
val parameters = attribute("parameters", F.stringFmt, "Parameters for this job", "{}")
Expand Down
18 changes: 15 additions & 3 deletions app/org/thp/cortex/services/JobSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class JobSrv(
case None Bad(One(MissingAttributeError("data")))
}
val tlp = (attributes \ "tlp").asOpt[Long].getOrElse(2L)
val pap = (attributes \ "pap").asOpt[Long].getOrElse(2L)
val message = (attributes \ "message").asOpt[String].getOrElse("")
val parameters = (attributes \ "parameters").asOpt[JsObject].getOrElse(JsObject.empty)
val label = (attributes \ "label").asOpt[String]
Expand All @@ -180,7 +181,7 @@ class JobSrv(
}
.fold(
typeDataAttachment typeDataAttachment._2.flatMap(
da create(worker, typeDataAttachment._1, da, tlp, message, parameters, label, force)),
da create(worker, typeDataAttachment._1, da, tlp, pap, message, parameters, label, force)),
errors {
val attributeError = AttributeCheckingError("job", errors)
logger.error("legacy job create fails", attributeError)
Expand Down Expand Up @@ -232,6 +233,7 @@ class JobSrv(
}

val tlp = fields.getLong("tlp").getOrElse(2L)
val pap = fields.getLong("pap").getOrElse(2L)
val message = fields.getString("message").getOrElse("")
val force = fields.getBoolean("force").getOrElse(false)
val parameters = fields.getValue("parameters").collect {
Expand All @@ -244,13 +246,22 @@ class JobSrv(
case (dt, Left(data)) dt Future.successful(Left(data))
}
.fold(
typeDataAttachment typeDataAttachment._2.flatMap(da create(worker, typeDataAttachment._1, da, tlp, message, parameters, fields.getString("label"), force)),
typeDataAttachment typeDataAttachment._2.flatMap(da create(worker, typeDataAttachment._1, da, tlp, pap, message, parameters, fields.getString("label"), force)),
errors Future.failed(AttributeCheckingError("job", errors)))
}
}
}

def create(worker: Worker, dataType: String, dataAttachment: Either[String, Attachment], tlp: Long, message: String, parameters: JsObject, label: Option[String], force: Boolean)(implicit authContext: AuthContext): Future[Job] = {
def create(
worker: Worker,
dataType: String,
dataAttachment: Either[String, Attachment],
tlp: Long,
pap: Long,
message: String,
parameters: JsObject,
label: Option[String],
force: Boolean)(implicit authContext: AuthContext): Future[Job] = {
val previousJob = if (force) Future.successful(None)
else findSimilarJob(worker, dataType, dataAttachment, tlp, parameters)
previousJob.flatMap {
Expand All @@ -265,6 +276,7 @@ class JobSrv(
"status" JobStatus.Waiting,
"dataType" dataType,
"tlp" tlp,
"pap" pap,
"message" message,
"parameters" parameters.toString,
"type" worker.tpe()))
Expand Down
2 changes: 1 addition & 1 deletion app/org/thp/cortex/services/MispSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MispSrv @Inject() (

for {
analyzer workerSrv.get(module)
job jobSrv.create(analyzer, mispType2dataType(mispType), artifact, 0, "", JsObject.empty, None, force = false)
job jobSrv.create(analyzer, mispType2dataType(mispType), artifact, 0, 0, "", JsObject.empty, None, force = false)
_ auditActor.ask(Register(job.id, duration))(Timeout(duration))
updatedJob jobSrv.getForUser(authContext.userId, job.id)
mispOutput toMispOutput(authContext.userId, updatedJob)
Expand Down

0 comments on commit 9669c7d

Please sign in to comment.