module Ecluse.Core.Osv.Schema (
osvSchemaEpoch,
osvDbFileName,
rangesTableDdl,
metaTableDdl,
ColumnSpec (..),
TableSpec (..),
osvTableSpecs,
MetaKey (..),
renderMetaKey,
) where
import Data.Universe.Class (Universe (..))
import Data.Universe.Generic (universeGeneric)
osvSchemaEpoch :: Int
osvSchemaEpoch :: Int
osvSchemaEpoch = Int
3
osvDbFileName :: Text -> FilePath
osvDbFileName :: Text -> FilePath
osvDbFileName Text
ecosystem =
Text -> FilePath
forall a. ToString a => a -> FilePath
toString Text
ecosystem FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
"-osv-schema" FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> Int -> FilePath
forall b a. (Show a, IsString b) => a -> b
show Int
osvSchemaEpoch FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
".db"
rangesTableDdl :: Text
rangesTableDdl :: Text
rangesTableDdl =
Text
"CREATE TABLE package_vulnerability_ranges (\
\ package_name TEXT NOT NULL,\
\ cve_id TEXT NOT NULL,\
\ introduced_version TEXT,\
\ fixed_version TEXT,\
\ last_affected_version TEXT,\
\ severity REAL\
\) STRICT"
metaTableDdl :: Text
metaTableDdl :: Text
metaTableDdl =
Text
"CREATE TABLE meta (\
\ key TEXT NOT NULL PRIMARY KEY,\
\ value TEXT NOT NULL\
\) STRICT"
data ColumnSpec = ColumnSpec
{ ColumnSpec -> Text
colName :: Text
, ColumnSpec -> Text
colDeclaredType :: Text
, ColumnSpec -> Bool
colNotNull :: Bool
}
deriving stock (ColumnSpec -> ColumnSpec -> Bool
(ColumnSpec -> ColumnSpec -> Bool)
-> (ColumnSpec -> ColumnSpec -> Bool) -> Eq ColumnSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ColumnSpec -> ColumnSpec -> Bool
== :: ColumnSpec -> ColumnSpec -> Bool
$c/= :: ColumnSpec -> ColumnSpec -> Bool
/= :: ColumnSpec -> ColumnSpec -> Bool
Eq, Int -> ColumnSpec -> FilePath -> FilePath
[ColumnSpec] -> FilePath -> FilePath
ColumnSpec -> FilePath
(Int -> ColumnSpec -> FilePath -> FilePath)
-> (ColumnSpec -> FilePath)
-> ([ColumnSpec] -> FilePath -> FilePath)
-> Show ColumnSpec
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> ColumnSpec -> FilePath -> FilePath
showsPrec :: Int -> ColumnSpec -> FilePath -> FilePath
$cshow :: ColumnSpec -> FilePath
show :: ColumnSpec -> FilePath
$cshowList :: [ColumnSpec] -> FilePath -> FilePath
showList :: [ColumnSpec] -> FilePath -> FilePath
Show)
data TableSpec = TableSpec
{ TableSpec -> Text
tableName :: Text
, TableSpec -> [ColumnSpec]
tableColumns :: [ColumnSpec]
}
deriving stock (TableSpec -> TableSpec -> Bool
(TableSpec -> TableSpec -> Bool)
-> (TableSpec -> TableSpec -> Bool) -> Eq TableSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TableSpec -> TableSpec -> Bool
== :: TableSpec -> TableSpec -> Bool
$c/= :: TableSpec -> TableSpec -> Bool
/= :: TableSpec -> TableSpec -> Bool
Eq, Int -> TableSpec -> FilePath -> FilePath
[TableSpec] -> FilePath -> FilePath
TableSpec -> FilePath
(Int -> TableSpec -> FilePath -> FilePath)
-> (TableSpec -> FilePath)
-> ([TableSpec] -> FilePath -> FilePath)
-> Show TableSpec
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> TableSpec -> FilePath -> FilePath
showsPrec :: Int -> TableSpec -> FilePath -> FilePath
$cshow :: TableSpec -> FilePath
show :: TableSpec -> FilePath
$cshowList :: [TableSpec] -> FilePath -> FilePath
showList :: [TableSpec] -> FilePath -> FilePath
Show)
osvTableSpecs :: [TableSpec]
osvTableSpecs :: [TableSpec]
osvTableSpecs =
[ TableSpec
{ tableName :: Text
tableName = Text
"package_vulnerability_ranges"
, tableColumns :: [ColumnSpec]
tableColumns =
[ ColumnSpec{colName :: Text
colName = Text
"package_name", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
True}
, ColumnSpec{colName :: Text
colName = Text
"cve_id", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
True}
, ColumnSpec{colName :: Text
colName = Text
"introduced_version", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
False}
, ColumnSpec{colName :: Text
colName = Text
"fixed_version", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
False}
, ColumnSpec{colName :: Text
colName = Text
"last_affected_version", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
False}
, ColumnSpec{colName :: Text
colName = Text
"severity", colDeclaredType :: Text
colDeclaredType = Text
"REAL", colNotNull :: Bool
colNotNull = Bool
False}
]
}
, TableSpec
{ tableName :: Text
tableName = Text
"meta"
, tableColumns :: [ColumnSpec]
tableColumns =
[ ColumnSpec{colName :: Text
colName = Text
"key", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
True}
, ColumnSpec{colName :: Text
colName = Text
"value", colDeclaredType :: Text
colDeclaredType = Text
"TEXT", colNotNull :: Bool
colNotNull = Bool
True}
]
}
]
data MetaKey
=
MetaPilotVersion
|
MetaEcosystem
|
MetaBuiltAt
|
MetaSourceUrl
|
MetaRowCount
deriving stock (MetaKey -> MetaKey -> Bool
(MetaKey -> MetaKey -> Bool)
-> (MetaKey -> MetaKey -> Bool) -> Eq MetaKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaKey -> MetaKey -> Bool
== :: MetaKey -> MetaKey -> Bool
$c/= :: MetaKey -> MetaKey -> Bool
/= :: MetaKey -> MetaKey -> Bool
Eq, (forall x. MetaKey -> Rep MetaKey x)
-> (forall x. Rep MetaKey x -> MetaKey) -> Generic MetaKey
forall x. Rep MetaKey x -> MetaKey
forall x. MetaKey -> Rep MetaKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MetaKey -> Rep MetaKey x
from :: forall x. MetaKey -> Rep MetaKey x
$cto :: forall x. Rep MetaKey x -> MetaKey
to :: forall x. Rep MetaKey x -> MetaKey
Generic, Int -> MetaKey -> FilePath -> FilePath
[MetaKey] -> FilePath -> FilePath
MetaKey -> FilePath
(Int -> MetaKey -> FilePath -> FilePath)
-> (MetaKey -> FilePath)
-> ([MetaKey] -> FilePath -> FilePath)
-> Show MetaKey
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
$cshowsPrec :: Int -> MetaKey -> FilePath -> FilePath
showsPrec :: Int -> MetaKey -> FilePath -> FilePath
$cshow :: MetaKey -> FilePath
show :: MetaKey -> FilePath
$cshowList :: [MetaKey] -> FilePath -> FilePath
showList :: [MetaKey] -> FilePath -> FilePath
Show)
instance Universe MetaKey where universe :: [MetaKey]
universe = [MetaKey]
forall a. (Generic a, GUniverse (Rep a)) => [a]
universeGeneric
renderMetaKey :: MetaKey -> Text
renderMetaKey :: MetaKey -> Text
renderMetaKey = \case
MetaKey
MetaPilotVersion -> Text
"pilot_version"
MetaKey
MetaEcosystem -> Text
"ecosystem"
MetaKey
MetaBuiltAt -> Text
"built_at"
MetaKey
MetaSourceUrl -> Text
"source_url"
MetaKey
MetaRowCount -> Text
"row_count"