1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
}
}
|