Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"modules/storage",
"modules/ui",
"modules/user",
"modules/validation",
"query",
"query/query-derive",
"server",
Expand Down Expand Up @@ -175,6 +176,7 @@ trustify-module-ingestor = { path = "modules/ingestor" }
trustify-module-storage = { path = "modules/storage" }
trustify-module-ui = { path = "modules/ui", default-features = false }
trustify-module-user = { path = "modules/user" }
trustify-module-validation = { path = "modules/validation" }
trustify-query = {path = "query" }
trustify-query-derive = {path = "query/query-derive" }
trustify-server = { path = "server", default-features = false }
Expand Down
21 changes: 21 additions & 0 deletions entity/src/document_validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use sea_orm::entity::prelude::*;
use time::OffsetDateTime;

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "document_validation")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub entity_type: String,
pub entity_id: Uuid,
pub level: String,
pub message: String,
pub source: String,
pub key: String,
pub timestamp: OffsetDateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
1 change: 1 addition & 0 deletions entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub mod sbom_node_purl_ref;
pub mod sbom_package;
pub mod sbom_package_license;
pub mod source_document;
pub mod document_validation;
pub mod status;
pub mod user_preferences;
pub mod version_range;
Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod m0002260_cpe_part_vendor_product_index;
mod m0002270_fix_vulnerability_base_score_type;
mod m0002280_backfill_sbom_suppliers;
mod m0002290_create_exploit_intelligence_job;
mod m0002310_create_document_validation;

pub trait MigratorExt: Send {
fn build_migrations() -> Migrations;
Expand Down Expand Up @@ -157,6 +158,7 @@ impl MigratorExt for Migrator {
.normal(m0002270_fix_vulnerability_base_score_type::Migration)
.data(m0002280_backfill_sbom_suppliers::Migration)
.normal(m0002290_create_exploit_intelligence_job::Migration)
.normal(m0002310_create_document_validation::Migration)
}
}

Expand Down
141 changes: 141 additions & 0 deletions migration/src/m0002310_create_document_validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(DocumentValidation::Table)
.if_not_exists()
.col(
ColumnDef::new(DocumentValidation::Id)
.uuid()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(DocumentValidation::EntityType)
.text()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::EntityId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::Level)
.text()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::Message)
.text()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::Source)
.text()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::Key)
.text()
.not_null(),
)
.col(
ColumnDef::new(DocumentValidation::Timestamp)
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;

manager
.create_index(
Index::create()
.if_not_exists()
.table(DocumentValidation::Table)
.name(Indexes::UqDocumentValidationSourceKey.to_string())
.col(DocumentValidation::EntityType)
.col(DocumentValidation::EntityId)
.col(DocumentValidation::Source)
.col(DocumentValidation::Key)
.unique()
.to_owned(),
)
.await?;

manager
.create_index(
Index::create()
.if_not_exists()
.table(DocumentValidation::Table)
.name(Indexes::IdxDocumentValidationEntity.to_string())
.col(DocumentValidation::EntityType)
.col(DocumentValidation::EntityId)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.if_exists()
.table(DocumentValidation::Table)
.name(Indexes::IdxDocumentValidationEntity.to_string())
.to_owned(),
)
.await?;

manager
.drop_index(
Index::drop()
.if_exists()
.table(DocumentValidation::Table)
.name(Indexes::UqDocumentValidationSourceKey.to_string())
.to_owned(),
)
.await?;

manager
.drop_table(
Table::drop()
.if_exists()
.table(DocumentValidation::Table)
.to_owned(),
)
.await?;

Ok(())
}
}

#[derive(DeriveIden)]
enum DocumentValidation {
Table,
Id,
EntityType,
EntityId,
Level,
Message,
Source,
Key,
Timestamp,
}

#[derive(DeriveIden)]
enum Indexes {
UqDocumentValidationSourceKey,
IdxDocumentValidationEntity,
}
23 changes: 23 additions & 0 deletions modules/validation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "trustify-module-validation"
version.workspace = true
edition.workspace = true
publish.workspace = true
license.workspace = true
rust-version.workspace = true

[dependencies]
trustify-auth = { workspace = true }
trustify-common = { workspace = true }
trustify-entity = { workspace = true }

actix-web = { workspace = true }
sea-orm = { workspace = true, features = ["sea-query-binder", "sqlx-postgres", "runtime-tokio-rustls", "macros", "debug-print"] }
sea-query = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
time = { workspace = true, features = ["serde-well-known"] }
utoipa = { workspace = true, features = ["actix_extras", "time", "url", "uuid"] }
utoipa-actix-web = { workspace = true }
uuid = { workspace = true }
Loading
Loading