Basic check of user data structure for errors
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -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)?;
|
||||
|
Reference in New Issue
Block a user