Basic check of user data structure for errors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-06-10 21:57:58 +02:00
parent ee733b04f3
commit 978a881372
5 changed files with 57 additions and 1 deletions

View File

@ -35,6 +35,27 @@ pub struct CloudInitConfig {
}
impl CloudInitConfig {
/// Check cloud init configuration
pub fn check_error(&self) -> Option<String> {
if !self.user_data.is_empty() {
// Check YAML content
if let Err(e) = serde_yml::from_str::<serde_json::Value>(&self.user_data) {
return Some(format!(
"user data is an invalid YAML file! Deserialization error: {e}"
));
}
// Check first line
if !self.user_data.starts_with("#cloud-config\n") {
return Some(
"user data file MUST start with '#cloud-config' as first line!".to_string(),
);
}
}
None
}
/// Generate disk image for nocloud usage
pub fn generate_nocloud_disk(&self) -> anyhow::Result<Vec<u8>> {
let temp_path = tempfile::tempdir_in(&AppConfig::get().temp_dir)?;