Skip to content

Commit

Permalink
feat: add token provider to v11y client
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron authored and bobmcwhirter committed Sep 7, 2023
1 parent 1516ff6 commit 8f788bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion collector/osv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl AppState {
addr: RwLock::new(None),
connected: AtomicBool::new(false),
collectorist_client: collectorist_client::CollectoristClient::new(collector_id, collectorist_url),
v11y_client: v11y_client::V11yClient::new(v11y_url),
v11y_client: v11y_client::V11yClient::new(v11y_url, ()),
guac_url: RwLock::new(None),
}
}
Expand Down
3 changes: 2 additions & 1 deletion v11y/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ humantime-serde = "1.1.1"
#clap = { version = "4", features = ["derive"] }
reqwest = "0.11.18"
anyhow = "1"
chrono = { version = "0.4.26", features = [ "serde"] }
chrono = { version = "0.4.26", features = ["serde"] }
utoipa = { version = "3", features = ["actix_extras"] }

trustification-auth = { path = "../../auth" }

[dev-dependencies]
tokio = "*"
Expand Down
10 changes: 9 additions & 1 deletion v11y/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::hash::{Hash, Hasher};
use chrono::{DateTime, Utc};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use trustification_auth::client::{TokenInjector, TokenProvider};
use utoipa::ToSchema;

#[derive(Serialize, Deserialize, Debug, ToSchema)]
Expand Down Expand Up @@ -170,18 +171,25 @@ impl V11yUrl {
#[allow(unused)]
pub struct V11yClient {
v11y_url: V11yUrl,
provider: Box<dyn TokenProvider>,
}

impl V11yClient {
pub fn new(url: Url) -> Self {
pub fn new<P: TokenProvider>(url: Url, provider: P) -> Self
where
P: TokenProvider + 'static,
{
Self {
v11y_url: V11yUrl::new(url),
provider: Box::new(provider),
}
}

pub async fn ingest_vulnerability(&self, vuln: &Vulnerability) -> Result<(), anyhow::Error> {
Ok(reqwest::Client::new()
.post(self.v11y_url.vulnerability_url())
.inject_token(self.provider.as_ref())
.await?
.json(&vuln)
.send()
.await
Expand Down

0 comments on commit 8f788bd

Please sign in to comment.