Initial commit

This commit is contained in:
Šesták Vít
2016-01-10 17:31:07 +01:00
commit 4b87ced31f
104 changed files with 4870 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package models
import scala.concurrent.duration._
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import models.profile.MappedJdbcType
import models.jodaSupport._
import models.profile.api._
import org.joda.time.DateTime
import slick.lifted.{ProvenShape, Tag}
import scala.concurrent.duration.FiniteDuration
class CookieAuthenticators(tag: Tag) extends Table[CookieAuthenticator](tag, "cookie_authenticators") {
private implicit val FiniteDurationType = MappedJdbcType.base[FiniteDuration, Long](_.toSeconds, FiniteDuration.apply(_, SECONDS))
def id = column[String]("id")
def providerId = column[String]("provider_id")
def providerKey = column[String]("provider_key")
def lastUsedDateTime = column[DateTime]("last_used")
def expirationDateTime = column[DateTime]("expiration")
def idleTimeout = column[FiniteDuration]("idle_timeout").?
def cookieMaxAge = column[FiniteDuration]("cookie_max_age").?
def fingerprint = column[String]("fingerprint").?
def loginInfo = (providerId, providerKey) <> (LoginInfo.tupled, LoginInfo.unapply)
override def * : ProvenShape[CookieAuthenticator] = (id, loginInfo, lastUsedDateTime, expirationDateTime, idleTimeout, cookieMaxAge, fingerprint) <> ((CookieAuthenticator.apply _).tupled, CookieAuthenticator.unapply)
}

52
app/models/Library.scala Normal file
View File

@@ -0,0 +1,52 @@
package models
import models.profile.MappedJdbcType
import models.profile.api._
import slick.lifted.Tag
abstract sealed class LibraryType(val name: String){
override final def toString: String = name
}
object LibraryType{
case object Maven extends LibraryType("maven")
case object DotNet extends LibraryType("dotnet")
val All = Set(Maven, DotNet)
val ByName = All.map(x => x.name -> x).toMap
implicit val libraryTypeMapper = MappedJdbcType.base[LibraryType, String](_.name, LibraryType.ByName)
}
final case class Library(plainLibraryIdentifier: PlainLibraryIdentifier, classified: Boolean)
final case class PlainLibraryIdentifier(libraryType: LibraryType, libraryIdentifier: String){
override def toString: String = s"$libraryType:$libraryIdentifier"
}
object PlainLibraryIdentifier extends ((LibraryType, String) => PlainLibraryIdentifier) {
def fromString(id: String) = {
val (libraryType, libraryNameWithColon) = id.span(_ != ':')
if(libraryNameWithColon(0) != ':'){
sys.error("Expected colon")
}
val libraryName = libraryNameWithColon.drop(1)
PlainLibraryIdentifier(
libraryType = LibraryType.ByName(libraryType),
libraryIdentifier = libraryName
)
}
}
class Libraries(tag: Tag) extends Table[(Int, Library)](tag, "library") {
import LibraryType.libraryTypeMapper
def id = column[Int]("id", O.PrimaryKey)
def libraryType = column[LibraryType]("library_type")
def libraryIdentifier = column[String]("identifier")
def classified = column[Boolean]("classified")
def plainLibraryIdentifierUnmapped = (libraryType, libraryIdentifier)
def plainLibraryIdentifier = plainLibraryIdentifierUnmapped <> (PlainLibraryIdentifier.tupled, PlainLibraryIdentifier.unapply)
def base = (plainLibraryIdentifier, classified) <> (Library.tupled, Library.unapply)
def * = (id, base)
}

View File

@@ -0,0 +1,16 @@
package models
import models.profile.api._
import slick.lifted.Tag
final case class LibraryTag (name: String, note: Option[String], warningOrder: Option[Int])
class LibraryTags(tag: Tag) extends Table[(Int, LibraryTag)](tag, "library_tag") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def note = column[Option[String]]("note")
def warningOrder = column[Option[Int]]("warning_order")
def base = (name, note, warningOrder) <> (LibraryTag.tupled, LibraryTag.unapply)
def * = (id, base)
}

View File

@@ -0,0 +1,19 @@
package models
import models.profile.api._
import slick.lifted.Tag
final case class LibraryTagPair(libraryId: Int, tagId: Int)
final case class LibraryTagAssignment(libraryTagPair: LibraryTagPair, contextDependent: Boolean){
def libraryId = libraryTagPair.libraryId
def tagId = libraryTagPair.tagId
}
class LibraryTagAssignments(tag: Tag) extends Table[LibraryTagAssignment](tag, "library_to_library_tag") {
def libraryId = column[Int]("library_id")
def libraryTagId = column[Int]("library_tag_id")
def contextDependent = column[Boolean]("context_dependent")
def libraryTagPair = (libraryId, libraryTagId) <> (LibraryTagPair.tupled, LibraryTagPair.unapply)
def * = (libraryTagPair, contextDependent) <> (LibraryTagAssignment.tupled, LibraryTagAssignment.unapply)
}

44
app/models/Snooze.scala Normal file
View File

@@ -0,0 +1,44 @@
package models
import models.jodaSupport._
import models.profile.api._
import org.joda.time.LocalDate
import play.api.data.Form
import slick.lifted.Tag
case class Snooze(until: LocalDate, snoozedObjectId: String, reason: String)
case class ObjectSnooze(until: LocalDate, reason: String){
def toSnooze(objectId: String) = Snooze(until, objectId, reason)
}
class Snoozes(tag: Tag) extends Table[(Int, Snooze)](tag, "snooze") {
def id = column[Int]("id", O.PrimaryKey)
def until = column[LocalDate]("until")
def snoozedObjectId = column[String]("snoozed_object_identifier")
def reason = column[String]("reason")
def base = (until, snoozedObjectId, reason) <> (Snooze.tupled, Snooze.unapply)
def * = (id, base)
}
case class SnoozeInfo(form: Form[ObjectSnooze], snoozes: Seq[(Int, Snooze)]){
def shouldCollapse(default: Boolean) = {
shouldExpandForm match {
case true => false
case false =>
isSnoozed match {
case true => true
case false => default
}
}
}
def isSnoozed = snoozes.nonEmpty
def shouldExpandForm = form.hasErrors || form.hasGlobalErrors
def adjustForm(f: Form[ObjectSnooze] => Form[ObjectSnooze]): SnoozeInfo = copy(form = f(form))
def adjustSnoozes(f: Seq[(Int, Snooze)] => Seq[(Int, Snooze)]): SnoozeInfo = copy(snoozes = f(snoozes))
}

5
app/models/User.scala Normal file
View File

@@ -0,0 +1,5 @@
package models
import com.mohiva.play.silhouette.api.Identity
case class User(username: String) extends Identity

View File

@@ -0,0 +1,20 @@
package models.odc
import models.odc.profile.api._
import slick.lifted.Tag
final case class CpeEntry(cpe: String, vendor: String, product: String)
class CpeEntries(tag: Tag) extends Table[(Int, CpeEntry)](tag, "cpeEntry") {
def id = column[Int]("id", O.PrimaryKey)
def cpe = column[String]("cpe")
def vendor = column[String]("vendor")
def product = column[String]("product")
def base = (cpe, vendor, product) <> (CpeEntry.tupled, CpeEntry.unapply)
def * = (id, base)
}

View File

@@ -0,0 +1,11 @@
package models.odc
import models.odc.profile.api._
final case class OdcProperty (id: String, value: String)
final class OdcProperties(tag: Tag) extends Table[OdcProperty](tag, "properties"){
def id = column[String]("id")
def value = column[String]("value")
def * = (id, value) <> (OdcProperty.tupled, OdcProperty.unapply)
}

View File

@@ -0,0 +1,17 @@
package models.odc
import com.ysoft.odc.Reference
import models.odc
import models.odc.profile.MappedJdbcType
import models.odc.profile.api._
import slick.lifted.Tag
class References (tag: Tag) extends Table[(Int, Reference)](tag, "reference") {
def cveId = column[Int]("cveid")
def name = column[String]("name")
def url = column[String]("url")
def source = column[String]("source")
def base = (source, url, name) <> (Reference.tupled, Reference.unapply)
def * = (cveId, base)
}

View File

@@ -0,0 +1,39 @@
package models.odc
import models.odc.profile.api._
import models.odc.profile.jdbcTypeFor
import slick.ast.TypedType
import models.odc.profile.MappedJdbcType
import slick.jdbc.JdbcType
import scala.reflect.ClassTag
// TODO: consider renaming to CpeEntryVulnerability or something like that
final case class SoftwareVulnerability (vulnerabilityId: Int, cpeEntryId: Int, includesAllPreviousVersionsRaw: Option[String]){
def includesAllPreviousVersions: Boolean = includesAllPreviousVersionsRaw match {
case Some("1") => true
case None => false
}
}
/*private class OdcBooleanType(implicit t: JdbcType[Option[String]]) extends MappedJdbcType[Boolean, Option[String]] {
override def map(t: Boolean): Option[String] = t match {
case true => Some("1")
case false => None
}
override def comap(u: Option[String]): Boolean = u match {
case Some("1") => true
case None => false
}
}*/
class SoftwareVulnerabilities(tag: Tag) extends Table[SoftwareVulnerability](tag, "software") {
def vulnerabilityId = column[Int]("cveid")
def cpeEntryId = column[Int]("cpeEntryId")
//private val bt = new OdcBooleanType()(jdbcTypeFor(implicitly[BaseColumnType[String]].optionType).asInstanceOf[JdbcType[Option[String]]])
//MappedJdbcType.base[Boolean, Option[String]](???, ???)(implicitly[ClassTag[Boolean]], )
def includesAllPreviousVersionsRaw = column[String]("previousVersion").?
def * = (vulnerabilityId, cpeEntryId, includesAllPreviousVersionsRaw) <> (SoftwareVulnerability.tupled, SoftwareVulnerability.unapply)
}

View File

@@ -0,0 +1,26 @@
package models.odc
import com.ysoft.odc.{CvssRating, CWE}
import models.odc.profile.api._
import slick.lifted.Tag
case class Vulnerability (cve: String, description: String, cweOption: Option[CWE], cvss: CvssRating)
class Vulnerabilities(tag: Tag) extends Table[(Int, Vulnerability)](tag, "vulnerability") {
def id = column[Int]("id")
def cve = column[String]("cve")
def description = column[String]("description")
def cweOption = column[String]("cwe").?
def cvssScore = column[Double]("cvssScore").?
def authentication = column[String]("cvssAuthentication").?
def availabilityImpact = column[String]("cvssAvailabilityImpact").?
def accessVector = column[String]("cvssAccessVector").?
def integrityImpact = column[String]("cvssIntegrityImpact").?
def cvssAccessComplexity = column[String]("cvssAccessComplexity").?
def cvssConfidentialityImpact = column[String]("cvssConfidentialityImpact").?
def cvssRating = (cvssScore, authentication, availabilityImpact, accessVector, integrityImpact, cvssAccessComplexity, cvssConfidentialityImpact) <> (CvssRating.tupled, CvssRating.unapply)
def cweOptionMapped = cweOption <> ((_: Option[String]).map(CWE.apply), (_: Option[CWE]).map(CWE.unapply))
def base = (cve, description, cweOptionMapped, cvssRating) <> (Vulnerability.tupled, Vulnerability.unapply)
def * = (id, base)
}

View File

@@ -0,0 +1,17 @@
package models
import slick.lifted.TableQuery
package object odc {
val profile = slick.driver.MySQLDriver
object tables {
val cpeEntries = TableQuery[CpeEntries]
val softwareVulnerabilities = TableQuery[SoftwareVulnerabilities]
val vulnerabilities = TableQuery[Vulnerabilities]
val references = TableQuery[References]
val properties = TableQuery[OdcProperties]
}
}

20
app/models/package.scala Normal file
View File

@@ -0,0 +1,20 @@
import slick.lifted.TableQuery
/**
* Created by user on 8/12/15.
*/
package object models {
val profile = slick.driver.PostgresDriver
val jodaSupport = com.github.tototoshi.slick.PostgresJodaSupport
object tables {
val libraries = TableQuery[Libraries]
val libraryTagAssignments = TableQuery[LibraryTagAssignments]
val tags = TableQuery[LibraryTags]
val snoozesTable = TableQuery[Snoozes]
val authTokens = TableQuery[CookieAuthenticators]
}
}