Skip to content

Commit

Permalink
feat: add basic example of implementing collector
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb committed Jun 2, 2023
1 parent e5310f6 commit b4e1d15
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
71 changes: 71 additions & 0 deletions cli/src/collector.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
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,
}

0 comments on commit b4e1d15

Please sign in to comment.