From 2d0651cfc7e68432893fb2d9125469915e8546ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0est=C3=A1k=20V=C3=ADt?= Date: Mon, 19 Jun 2017 13:09:17 +0200 Subject: [PATCH] Minor hashes refactoring --- app/binders/QueryBinders.scala | 2 +- app/com/ysoft/odc/OdcParser.scala | 5 +++-- app/controllers/Statistics.scala | 2 +- app/views/dependencyList.scala.html | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/binders/QueryBinders.scala b/app/binders/QueryBinders.scala index 541eb2a..9493aca 100644 --- a/app/binders/QueryBinders.scala +++ b/app/binders/QueryBinders.scala @@ -26,7 +26,7 @@ object QueryBinders { str => str.split('-') match { case Array(sha1, md5) => Hashes(sha1 = sha1, md5 = md5) }, - hashes => s"${hashes.sha1}-${hashes.md5}" + hashes => hashes.serialized ) implicit object MapStringIntJavascriptLiteral extends JavascriptLiteral[Map[String, Int]] { diff --git a/app/com/ysoft/odc/OdcParser.scala b/app/com/ysoft/odc/OdcParser.scala index e5bf4eb..0999934 100644 --- a/app/com/ysoft/odc/OdcParser.scala +++ b/app/com/ysoft/odc/OdcParser.scala @@ -30,6 +30,7 @@ final case class Analysis(scanInfo: SerializableXml, name: String, reportDate: D final case class Hashes(sha1: String, md5: String){ override def toString: String = s"Hashes(sha1=$sha1, md5=$md5)" + def serialized = s"$sha1-$md5" } final case class Exclusion(sha1: String) extends AnyVal { @@ -76,8 +77,8 @@ final case class GroupedDependency(dependencies: Map[Dependency, Set[ReportInfo] def descriptions = dependencies.keySet.map(_.description) def projects = dependencies.values.flatten.toSet def fileNames = dependencies.keySet.map(_.fileName) - def hashes = dependencies.keys.head.hashes // valid since all deps in a group have the same hashes - val sha1 = hashes.sha1 + val hashes: Hashes = dependencies.keys.head.hashes // valid since all deps in a group have the same hashes + def sha1: String = hashes.sha1 def identifiers: Set[Identifier] = dependencies.keySet.flatMap(_.identifiers) def evidenceCollected: Set[Evidence] = dependencies.keySet.flatMap(_.evidenceCollected) def suppressedIdentifiers: Set[Identifier] = dependencies.keySet.flatMap(_.suppressedIdentifiers) diff --git a/app/controllers/Statistics.scala b/app/controllers/Statistics.scala index 59f7733..eab4fae 100644 --- a/app/controllers/Statistics.scala +++ b/app/controllers/Statistics.scala @@ -48,7 +48,7 @@ object Statistics{ // TODO: Move this to a better place - implicit val hashesWrites = Writes[Hashes](h => JsString(s"${h.sha1}-${h.md5}")) + implicit val hashesWrites = Writes[Hashes](h => JsString(h.serialized)) implicit val confidenceWrites = Writes[Confidence](c => JsString(c.toString)) implicit val identifierWrites = Json.writes[Identifier] implicit val evidenceWrites = Json.writes[Evidence] diff --git a/app/views/dependencyList.scala.html b/app/views/dependencyList.scala.html index 5a5def4..aa888a2 100644 --- a/app/views/dependencyList.scala.html +++ b/app/views/dependencyList.scala.html @@ -12,7 +12,7 @@ - @for(dep <- list; depPrefix = s"$idPrefix-${dep.sha1}"){ + @for(dep <- list; depPrefix = s"$idPrefix-${dep.hashes.serialized}"){ @for(s <- dep.maxCvssScore) { @@ -23,7 +23,7 @@ } - @libraryIdentificationList(dep, Some(cpe => s"$idPrefix-${dep.sha1}-suppression-cpe-${cpeHtmlId(cpe)}"), addLink = false, addButtons = addButtons) + @libraryIdentificationList(dep, Some(cpe => s"$idPrefix-${dep.hashes.serialized}-suppression-cpe-${cpeHtmlId(cpe)}"), addLink = false, addButtons = addButtons) @for(s <- dep.maxCvssScore) {@dep.vulnerabilities.size}