Skip to content

Commit

Permalink
fix: fixup for --devmode
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Oct 10, 2023
1 parent 876b916 commit dc3d655
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
32 changes: 32 additions & 0 deletions collectorist/api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,45 @@ use reqwest::Url;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::Duration;
use trustification_infrastructure::endpoint::{self, Endpoint};

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct CollectorsConfig {
pub collectors: HashMap<String, CollectorConfig>,
}

impl CollectorsConfig {
pub fn devmode() -> Self {
let mut collectors = HashMap::new();
collectors.insert(
"osv".into(),
CollectorConfig {
url: endpoint::CollectorOsv::url(),
interests: vec![Interest::Package, Interest::Vulnerability],
cadence: default_cadence(),
},
);
collectors.insert(
"snyk".into(),
CollectorConfig {
url: endpoint::CollectorSnyk::url(),
interests: vec![Interest::Package],
cadence: default_cadence(),
},
);
collectors.insert(
"nvd".into(),
CollectorConfig {
url: endpoint::CollectorNvd::url(),
interests: vec![Interest::Vulnerability],
cadence: default_cadence(),
},
);
Self { collectors }
}
}

#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum Interest {
Expand Down
7 changes: 6 additions & 1 deletion collectorist/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl Run {
self.collector_config,
self.csub_url,
provider,
self.devmode,
)
.await?;

Expand Down Expand Up @@ -142,6 +143,7 @@ impl Run {
collector_config: Option<PathBuf>,
csub_url: Url,
provider: P,
devmode: bool,
) -> anyhow::Result<Arc<AppState>>
where
P: TokenProvider + Clone + 'static,
Expand All @@ -150,11 +152,14 @@ impl Run {

let collectorist_config = if collectorist_config.exists() {
serde_yaml::from_reader(File::open(collectorist_config)?)?
} else if devmode {
CollectorsConfig::devmode()
} else {
log::info!(
log::error!(
"configuration file {} missing, no collectors configured",
collectorist_config.to_str().unwrap_or("<unknown>")
);

CollectorsConfig {
collectors: Default::default(),
}
Expand Down

0 comments on commit dc3d655

Please sign in to comment.