Skip to content

Commit

Permalink
fix: generate config schema and ensure they are up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 6, 2024
1 parent 59889af commit 6ff7e9b
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ jobs:
RUST_LOG: info,sqlx=error,sea_orm=error
- name: Validate Generated Openapi Spec
run: cargo xtask validate-openapi
- name: Ensure schemas are up-to-date
run: |
cargo xtask generate-schemas
git diff --quiet
if [ $? -gt 0 ]; then
echo "::error::Uncommitted changes (run `cargo xtask generate-schemas` after making changes to the models)"
exit 1
fi
4 changes: 4 additions & 0 deletions Cargo.lock

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

13 changes: 0 additions & 13 deletions common/auth/examples/generate_auth_schema.rs

This file was deleted.

1 change: 1 addition & 0 deletions entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trustify-cvss = { workspace = true }

async-graphql = { workspace = true, features = ["uuid", "time"] }
cpe = { workspace = true }
schemars = { workspace = true }
sea-orm = { workspace = true, features = [
"sqlx-postgres",
"runtime-tokio-rustls",
Expand Down
1 change: 1 addition & 0 deletions entity/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use utoipa::ToSchema;
::serde::Serialize,
::serde::Deserialize,
sea_orm::FromJsonQueryResult,
schemars::JsonSchema,
)]
pub struct Labels(pub HashMap<String, String>);

Expand Down
1 change: 1 addition & 0 deletions modules/importer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ osv = { workspace = true, features = ["schema"] }
parking_lot = { workspace = true }
regex = { workspace = true }
sbom-walker = { workspace = true }
schemars = { workspace = true, features = ["url"] }
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"] }
Expand Down
2 changes: 2 additions & 0 deletions modules/importer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![recursion_limit = "256"]

pub mod endpoints;
pub mod model;
pub mod server;
Expand Down
11 changes: 10 additions & 1 deletion modules/importer/src/model/csaf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use super::*;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct CsafImporter {
#[serde(flatten)]
Expand Down
11 changes: 10 additions & 1 deletion modules/importer/src/model/cve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
use super::*;
use std::collections::HashSet;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct CveImporter {
#[serde(flatten)]
Expand Down
27 changes: 25 additions & 2 deletions modules/importer/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ pub struct ImporterData {
pub continuation: serde_json::Value,
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub enum ImporterConfiguration {
Sbom(SbomImporter),
Expand Down Expand Up @@ -116,7 +125,16 @@ impl DerefMut for ImporterConfiguration {
}
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct CommonImporter {
/// A flag to disable the importer, without deleting it.
Expand All @@ -125,6 +143,7 @@ pub struct CommonImporter {

/// The period the importer should be run.
#[serde(with = "humantime_serde")]
#[schemars(with = "HumantimeSerde")]
pub period: Duration,

/// A description for users.
Expand All @@ -136,6 +155,10 @@ pub struct CommonImporter {
pub labels: Labels,
}

// Just here to create a schema for humantime_serde.
#[derive(schemars::JsonSchema)]
struct HumantimeSerde(#[allow(unused)] String);

impl TryFrom<Model> for Importer {
type Error = serde_json::Error;

Expand Down
11 changes: 10 additions & 1 deletion modules/importer/src/model/osv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use super::*;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct OsvImporter {
#[serde(flatten)]
Expand Down
11 changes: 10 additions & 1 deletion modules/importer/src/model/sbom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use super::*;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
ToSchema,
schemars::JsonSchema,
)]
#[serde(rename_all = "camelCase")]
pub struct SbomImporter {
#[serde(flatten)]
Expand Down
4 changes: 3 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ anyhow = { workspace = true }
clap = { workspace = true, features = ["derive", "env"] }
log = { workspace = true }
postgresql_commands = { workspace = true }
serde= { workspace = true}
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "tracing-log", "ansi"] }

trustify-auth = { workspace = true }
trustify-common = { workspace = true }
trustify-module-importer = { workspace = true }
trustify-module-ingestor = { workspace = true }
Expand Down
Loading

0 comments on commit 6ff7e9b

Please sign in to comment.