forked from trustification/guac-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic example of implementing collector
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |