Skip to content

Commit

Permalink
#1478 Fix date format in migration
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Oct 19, 2020
1 parent d5cd5ff commit 1af72f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
13 changes: 10 additions & 3 deletions migration/src/main/scala/org/thp/thehive/migration/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ object Filter {
new SimpleDateFormat("MMdd")
)
def parseDate(s: String): Try[Date] =
dateFormats.foldLeft[Try[Date]](Failure(new ParseException(s"Unparseable date: $s", 0))) { (acc, format) =>
acc.recoverWith { case _ => Try(format.parse(s)) }
}
dateFormats
.foldLeft[Try[Date]](Failure(new ParseException(s"Unparseable date: $s", 0))) { (acc, format) =>
acc.recoverWith { case _ => Try(format.parse(s)) }
}
.recoverWith {
case _ =>
Failure(
new ParseException(s"Unparseable date: $s\nExpected format is ${dateFormats.map(_.toPattern).mkString("\"", "\" or \"", "\"")}", 0)
)
}
def readDate(dateConfigName: String, ageConfigName: String) =
Try(config.getString(dateConfigName))
.flatMap(parseDate)
Expand Down
14 changes: 8 additions & 6 deletions migration/src/main/scala/org/thp/thehive/migration/Migrate.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.thp.thehive.migration

import java.io.File
import java.text.SimpleDateFormat
import java.util.Date

import akka.actor.ActorSystem
import akka.stream.Materializer
Expand Down Expand Up @@ -71,11 +73,11 @@ object Migrate extends App with MigrationOps {
.valueName("<duration>")
.text("migrate only cases whose age is greater than <duration>")
.action((v, c) => addConfig(c, "input.filter.minCaseAge" -> v.toString)),
opt[Duration]("case-from-date")
opt[String]("case-from-date")
.valueName("<date>")
.text("migrate only cases created from <date>")
.action((v, c) => addConfig(c, "input.filter.caseFromDate" -> v.toString)),
opt[Duration]("case-until-date")
opt[String]("case-until-date")
.valueName("<date>")
.text("migrate only cases created until <date>")
.action((v, c) => addConfig(c, "input.filter.caseUntilDate" -> v.toString)),
Expand All @@ -97,11 +99,11 @@ object Migrate extends App with MigrationOps {
.valueName("<duration>")
.text("migrate only alerts whose age is greater than <duration>")
.action((v, c) => addConfig(c, "input.filter.minAlertAge" -> v.toString)),
opt[Duration]("alert-from-date")
opt[String]("alert-from-date")
.valueName("<date>")
.text("migrate only alerts created from <date>")
.action((v, c) => addConfig(c, "input.filter.alertFromDate" -> v.toString)),
opt[Duration]("alert-until-date")
opt[String]("alert-until-date")
.valueName("<date>")
.text("migrate only alerts created until <date>")
.action((v, c) => addConfig(c, "input.filter.alertUntilDate" -> v.toString)),
Expand All @@ -114,11 +116,11 @@ object Migrate extends App with MigrationOps {
.valueName("<duration>")
.text("migrate only audits whose age is greater than <duration>")
.action((v, c) => addConfig(c, "input.filter.maxAuditAge" -> v.toString)),
opt[Duration]("audit-from-date")
opt[String]("audit-from-date")
.valueName("<date>")
.text("migrate only audits created from <date>")
.action((v, c) => addConfig(c, "input.filter.auditFromDate" -> v.toString)),
opt[Duration]("audit-until-date")
opt[String]("audit-until-date")
.valueName("<date>")
.text("migrate only audits created until <date>")
.action((v, c) => addConfig(c, "input.filter.auditUntilDate" -> v.toString)),
Expand Down

0 comments on commit 1af72f9

Please # to comment.