Skip to content
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

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

joebonrichie
Copy link
Contributor

@joebonrichie joebonrichie commented Dec 27, 2024

Attempt to match the id from release-monitoring and any CPE from cpe-guesser.

@joebonrichie joebonrichie force-pushed the write-monitoring-template branch 2 times, most recently from cf62693 to e02e0c3 Compare December 30, 2024 08:03
@joebonrichie joebonrichie marked this pull request as draft December 30, 2024 08:03
@joebonrichie
Copy link
Contributor Author

draft pending code cleanup

@joebonrichie joebonrichie force-pushed the write-monitoring-template branch from e02e0c3 to 8f6086d Compare December 31, 2024 13:47
@joebonrichie joebonrichie changed the title boulder: Write a template monitoring.yaml file with boulder new boulder: Write a monitoring.yaml file with boulder new Dec 31, 2024
@joebonrichie joebonrichie force-pushed the write-monitoring-template branch 6 times, most recently from 6fc836c to d114e4c Compare December 31, 2024 18:32
@joebonrichie joebonrichie marked this pull request as ready for review December 31, 2024 18:34
@joebonrichie joebonrichie force-pushed the write-monitoring-template branch 3 times, most recently from 4be8c0a to 158fda0 Compare January 4, 2025 10:05
boulder/src/draft/monitoring.rs Outdated Show resolved Hide resolved
boulder/src/draft.rs Outdated Show resolved Hide resolved
boulder/src/draft/monitoring.rs Outdated Show resolved Hide resolved
boulder/src/draft/monitoring.rs Outdated Show resolved Hide resolved
boulder/src/draft/monitoring.rs Outdated Show resolved Hide resolved
Comment on lines 58 to 67
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(())
}
Copy link
Collaborator

@tarkah tarkah Jan 6, 2025

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)

@joebonrichie joebonrichie force-pushed the write-monitoring-template branch 7 times, most recently from bee6f84 to 9dc1efc Compare January 8, 2025 19:34
Comment on lines 175 to 209
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);
}
Copy link
Collaborator

@tarkah tarkah Jan 8, 2025

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

Copy link
Contributor Author

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

boulder/src/draft.rs Outdated Show resolved Hide resolved
@joebonrichie joebonrichie force-pushed the write-monitoring-template branch 2 times, most recently from ef7fe57 to 752c7fa Compare January 9, 2025 11:38
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
@joebonrichie joebonrichie force-pushed the write-monitoring-template branch from 752c7fa to 81d90a4 Compare January 9, 2025 12:59
Copy link
Collaborator

@tarkah tarkah left a 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!

@ikeycode ikeycode merged commit 04ad263 into main Jan 9, 2025
2 checks passed
@ikeycode ikeycode deleted the write-monitoring-template branch January 9, 2025 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants