-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boulder: Write a monitoring.yaml file with boulder new #375
Conversation
cf62693
to
e02e0c3
Compare
draft pending code cleanup |
e02e0c3
to
8f6086d
Compare
6fc836c
to
d114e4c
Compare
4be8c0a
to
158fda0
Compare
boulder/src/draft/monitoring.rs
Outdated
pub fn run(&self) -> Result<(), Error> { | ||
let client = self.create_reqwest_client(); | ||
|
||
let id = self.find_monitoring_id(&self.name, &client)?; | ||
let cpes = self.find_security_cpe(&self.name, &client)?; | ||
|
||
self.write_monitoring(id, cpes)?; | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run
doesn't describe this very well. Maybe fetch_and_output
, but that name is a bit of a code smell. Does this API really need to be responsible over outputting the data?
Maybe we should just make this Monitoring::fetch
which can be simplified to a module level function.. monitoring::fetch(name) -> Monitoring
and then the caller can handle this type / write it however they want (Monitoring
can be the name of what's currently MonitoringTemplate
)
bee6f84
to
9dc1efc
Compare
boulder/src/draft/monitoring.rs
Outdated
let mut yaml_string = serde_yaml::to_string(&monitoring_template).expect("Failed to serialize to YAML"); | ||
|
||
// We may not have matched any ID or CPE which is fine | ||
// Unwrap the default value then mangle it into a YAML ~ (null) value | ||
if monitoring_template.releases.id.unwrap_or_default() == 0 { | ||
let id_string = "id: 0"; | ||
let id_marker = yaml_string.find(id_string).expect("releases id marker not found"); | ||
yaml_string = yaml_string.replace(id_string, "id: ~"); | ||
const ID_HELP_TEXT: &str = | ||
" # https://release-monitoring.org/ and use the numeric id in the url of project"; | ||
yaml_string.insert_str(id_marker + id_string.len(), ID_HELP_TEXT); | ||
} | ||
|
||
if monitoring_template.releases.rss.is_none() { | ||
let rss_string = "rss: null"; | ||
yaml_string = yaml_string.replace(rss_string, "rss: ~"); | ||
} | ||
|
||
if monitoring_template.security.cpe.unwrap_or_default().is_empty() { | ||
let cpe_string = "cpe: []"; | ||
let cpe_marker = yaml_string.find(cpe_string).expect("security cpe marker not found"); | ||
yaml_string = yaml_string.replace(cpe_string, "cpe: ~"); | ||
let cpe_help_text = format!( | ||
" # Last checked {}", | ||
chrono::Local::now().date_naive().format("%Y-%m-%d") | ||
); | ||
yaml_string.insert_str(cpe_marker + cpe_string.len() - 1, &cpe_help_text); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it even worth using serde_yaml::to_string
vs building the formatted string ourselves since we're doing all these replaces?
let id = id.map_or_else(
|| "~ # https://release-monitoring.org/ and use the numeric id in the url of project".to_string(),
ToString::to_string
);
format!(r"---
releases:
id: {id}
")
A bit more readable imo and more robust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential multiple CPE matches make this more annoying
ef7fe57
to
752c7fa
Compare
Attempt to match ID from release-monitoring.org using the metadata name Attempt to match CPEs from cpe-guesser using the metadata name Attempt to match RSS from homepage (only github is currently supported) Output the recipe and monitoring to a folder instead
752c7fa
to
81d90a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, great addition. Thanks @joebonrichie!
Attempt to match the id from release-monitoring and any CPE from cpe-guesser.