diff --git a/README.md b/README.md index 011a1b2..96fc4b1 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ $ guac vulnerabilities pkg:rpm/redhat/openssl@1.1.1k-7.el8_6 ### Get Packages -Returns list of all versions for the given package +Returns list of all versions for the given package purl ``` $ guac packages pkg:maven/io.vertx/vertx-web diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b192a2d..c3c5eb4 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -14,7 +14,12 @@ serde_derive = "1.0.114" serde_json = "1.0.56" colored_json = "3.0.1" clap = { version = "4.0.29", features = ["derive"] } +nats = "0.24.0" [[bin]] name = "guac" path = "src/main.rs" + +[[bin]] +name = "collector" +path = "src/collector.rs" \ No newline at end of file diff --git a/cli/src/collector.rs b/cli/src/collector.rs new file mode 100644 index 0000000..2abc9b2 --- /dev/null +++ b/cli/src/collector.rs @@ -0,0 +1,71 @@ +use std::fs; + +use anyhow::*; +use serde::{Deserialize, Serialize}; +use serde_json::json; + +#[tokio::main] +async fn main() -> Result<(), anyhow::Error> { + println!("Collecting"); + + let nc = nats::connect("127.0.0.1:4222")?; + + let path = "example/seedwing-java-example.bom"; + let content = fs::read(path)?; + //let content = Vec::new(); + + let document = Document { + blob: content, + r#type: DocumentType::UNKNOWN, + format: FormatType::UNKNOWN, + source_information: SourceInformation { + collector: "FileCollector".into(), + source: path.into(), + }, + }; + + //let payload = serde_json::json!(document); + //println!("{}", payload); + let bytes = serde_json::to_vec(&json!(document))?; + + nc.publish("DOCUMENTS.collected", bytes)?; + + Ok(()) +} + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Document { + blob: Vec, + r#type: DocumentType, + format: FormatType, + source_information: SourceInformation, +} + +#[derive(Serialize, Deserialize)] +pub enum DocumentType { + SLSA, + ITE6, + ITE6VUL, + DSSE, + SPDX, + JsonLines, + SCORECARD, + CyclonDX, + DepsDev, + UNKNOWN, +} + +#[derive(Serialize, Deserialize)] +pub enum FormatType { + JSON, + JsonLines, + XML, + UNKNOWN, +} + +#[derive(Serialize, Deserialize)] +pub struct SourceInformation { + collector: String, + source: String, +}