From 1af72f9a92d52e09bc081650e34945c091831174 Mon Sep 17 00:00:00 2001 From: To-om Date: Mon, 19 Oct 2020 16:49:48 +0200 Subject: [PATCH] #1478 Fix date format in migration --- .../scala/org/thp/thehive/migration/Input.scala | 13 ++++++++++--- .../scala/org/thp/thehive/migration/Migrate.scala | 14 ++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/migration/src/main/scala/org/thp/thehive/migration/Input.scala b/migration/src/main/scala/org/thp/thehive/migration/Input.scala index 6e685d5405..e06a97cefb 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/Input.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/Input.scala @@ -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) diff --git a/migration/src/main/scala/org/thp/thehive/migration/Migrate.scala b/migration/src/main/scala/org/thp/thehive/migration/Migrate.scala index b55d474621..3c244a5085 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/Migrate.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/Migrate.scala @@ -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 @@ -71,11 +73,11 @@ object Migrate extends App with MigrationOps { .valueName("") .text("migrate only cases whose age is greater than ") .action((v, c) => addConfig(c, "input.filter.minCaseAge" -> v.toString)), - opt[Duration]("case-from-date") + opt[String]("case-from-date") .valueName("") .text("migrate only cases created from ") .action((v, c) => addConfig(c, "input.filter.caseFromDate" -> v.toString)), - opt[Duration]("case-until-date") + opt[String]("case-until-date") .valueName("") .text("migrate only cases created until ") .action((v, c) => addConfig(c, "input.filter.caseUntilDate" -> v.toString)), @@ -97,11 +99,11 @@ object Migrate extends App with MigrationOps { .valueName("") .text("migrate only alerts whose age is greater than ") .action((v, c) => addConfig(c, "input.filter.minAlertAge" -> v.toString)), - opt[Duration]("alert-from-date") + opt[String]("alert-from-date") .valueName("") .text("migrate only alerts created from ") .action((v, c) => addConfig(c, "input.filter.alertFromDate" -> v.toString)), - opt[Duration]("alert-until-date") + opt[String]("alert-until-date") .valueName("") .text("migrate only alerts created until ") .action((v, c) => addConfig(c, "input.filter.alertUntilDate" -> v.toString)), @@ -114,11 +116,11 @@ object Migrate extends App with MigrationOps { .valueName("") .text("migrate only audits whose age is greater than ") .action((v, c) => addConfig(c, "input.filter.maxAuditAge" -> v.toString)), - opt[Duration]("audit-from-date") + opt[String]("audit-from-date") .valueName("") .text("migrate only audits created from ") .action((v, c) => addConfig(c, "input.filter.auditFromDate" -> v.toString)), - opt[Duration]("audit-until-date") + opt[String]("audit-until-date") .valueName("") .text("migrate only audits created until ") .action((v, c) => addConfig(c, "input.filter.auditUntilDate" -> v.toString)),