Added API for lisling vulnerabilities

This commit is contained in:
Šesták Vít
2018-03-02 07:43:07 +01:00
parent d56ffbccc6
commit 15f8319de9
2 changed files with 14 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import models.LibraryTag
import modules.TemplateCustomization
import org.joda.time.DateTime
import play.api.i18n.MessagesApi
import play.api.libs.json.Json.JsValueWrapper
import play.api.libs.json._
import play.twirl.api.Txt
import services._
@@ -91,7 +92,6 @@ object Statistics{
//implicit val groupedDependencyFormats = Json.format[GroupedDependency]
implicit val groupedVulnerableDependencyDetailedIdentifierWrites = Json.writes[GroupedVulnerableDependencyDetailedIdentifier]
implicit val canonizedGroupedVulnerableDependencyDetailedIdentifierWrites = Json.writes[CanonizedGroupedVulnerableDependencyDetailedIdentifier]
}
//noinspection TypeAnnotation
@@ -373,6 +373,18 @@ class Statistics @Inject()(
}
}
def libraryVulnerabilities(depId: com.ysoft.odc.Hashes) = ApiAction(ScanResults).async { implicit req =>
val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions)
resultsFuture flatMap { allResults =>
select(allResults, None).fold(Future.successful(NotFound(Json.obj("error"->"not found")))) { selection =>
Future.successful(selection.result.groupedDependenciesByHashes.get(depId) match {
case None => NotFound(Json.obj("error"->"not found"))
case Some(dep) => Ok(Json.arr(dep.vulnerabilities.map(_.name).toIndexedSeq.sorted.map(x => x : JsValueWrapper) : _*))
})
}
}
}
def affectedProjects(depId: Hashes) = ReadAction.async { implicit req =>
val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions)
resultsFuture flatMap { case (successfulResults, failedResults) =>

View File

@@ -8,6 +8,7 @@ GET /api/table controllers.Statistics.table()
GET /api/all-dependencies.json controllers.Statistics.allDependencies(selector: Option[String])
GET /api/all-dependencies-verbose.json controllers.Statistics.allDependenciesVerbose(selector: Option[String])
POST /api/compare-scan controllers.Statistics.compareScan()
GET /api/library/:depId/vulnerabilities controllers.Statistics.libraryVulnerabilities(depId: com.ysoft.odc.Hashes)
GET /status controllers.Application.index(versions: Map[String, Int] = Map())
GET /versions controllers.Application.index(versions: Map[String, Int])
GET /dependencies controllers.Application.dependencies(classified: Option[Boolean] = None, requiredTags: Seq[Int] ?= Seq(), noTag: Boolean ?= false)