summaryrefslogtreecommitdiff
path: root/src/spec.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-10-16 11:18:48 +0300
committerLars Wirzenius <liw@liw.fi>2021-10-16 11:18:48 +0300
commitf7d5a9e11eed3f7f0769fbb154acb10bdc7fb58d (patch)
treee2e6e500848617920b53dd126c1392e4db49a2e2 /src/spec.rs
parent21521cfe1b0870e8552d19b022ac0c3902eb356e (diff)
downloadvmadm-f7d5a9e11eed3f7f0769fbb154acb10bdc7fb58d.tar.gz
feat: allow ~user/ in path names, not just ~/
Add the home-dir crate as a dependency for tilde expansion. Sponsored-by: author
Diffstat (limited to 'src/spec.rs')
-rw-r--r--src/spec.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/spec.rs b/src/spec.rs
index 5dc7714..87e59a2 100644
--- a/src/spec.rs
+++ b/src/spec.rs
@@ -245,6 +245,10 @@ pub enum SpecificationError {
/// Error parsing YAML.
#[error(transparent)]
YamlError(#[from] serde_yaml::Error),
+
+ /// Error expanding a ~user in a path name.
+ #[error(transparent)]
+ HomeDirError(#[from] home_dir::Error)
}
impl Specification {
@@ -284,7 +288,7 @@ impl Specification {
let key_filenames = input.ssh_key_files(config, name)?;
let ssh_keys = ssh_keys(&key_filenames)?;
let ca_key = if let Some(filename) = &input.ca_key {
- Some(expand_tilde(filename))
+ Some(expand_tilde(filename)?)
} else {
config.ca_key.clone()
};
@@ -307,8 +311,8 @@ impl Specification {
ecdsa_host_cert: input.ecdsa_host_cert.clone(),
ed25519_host_key: input.ed25519_host_key.clone(),
ed25519_host_cert: input.ed25519_host_cert.clone(),
- base: expand_tilde(&input.base_image(config, name)?),
- image: expand_tilde(&input.image(config, name)?),
+ base: expand_tilde(&input.base_image(config, name)?)?,
+ image: expand_tilde(&input.image(config, name)?)?,
image_size_gib: input.image_size_gib(config, name)?,
memory_mib: input.memory_mib(config, name)?,
cpus: input.cpus(config, name)?,
@@ -326,7 +330,7 @@ impl Specification {
fn ssh_keys(filenames: &[PathBuf]) -> Result<Vec<String>, SpecificationError> {
let mut keys = vec![];
for filename in filenames {
- let filename = expand_tilde(filename);
+ let filename = expand_tilde(filename)?;
let key =
std::fs::read(&filename).map_err(|e| SpecificationError::SshKeyRead(filename, e))?;
let key = String::from_utf8(key)?;