diff options
Diffstat (limited to 'src/spec.rs')
-rw-r--r-- | src/spec.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/spec.rs b/src/spec.rs new file mode 100644 index 0000000..1209040 --- /dev/null +++ b/src/spec.rs @@ -0,0 +1,37 @@ +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Specification { + pub name: String, + + #[serde(default)] + pub ssh_key_files: Vec<PathBuf>, + + pub base: PathBuf, + pub image: PathBuf, + pub image_size_gib: u64, + pub memory_mib: u64, + pub cpus: u64, +} + +#[derive(Debug, thiserror::Error)] +pub enum SpecificationError { + #[error(transparent)] + IoError(#[from] std::io::Error), + + #[error(transparent)] + FromUtf8Error(#[from] std::string::FromUtf8Error), +} + +impl Specification { + pub fn ssh_keys(&self) -> Result<String, SpecificationError> { + let mut keys = String::new(); + for filename in self.ssh_key_files.iter() { + let key = std::fs::read(filename)?; + let key = String::from_utf8(key)?; + keys.push_str(&key); + } + Ok(keys) + } +} |