From d95727f2d49051204f6df4d5ba8fa282cd4a0b5a Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 6 Nov 2021 00:50:44 -0500 Subject: [PATCH] imp(hostname): make hostname optional - generic nixosconfig be known that are hydrated with a target-ip during runtime (e.g. from a remote source) - Example: auto scaling groups --- src/cli.rs | 9 +++++++-- src/data.rs | 10 +++++++--- src/settings.rs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 9e21b48d..f56caccc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::io::{stdin, stdout, Write}; -use clap::{ArgMatches, FromArgMatches, Parser}; +use clap::{Parser}; use crate as deploy; @@ -69,6 +69,11 @@ fn print_deployment(parts: &[&data::DeployData]) -> Result<(), toml::ser::Error> let mut part_map: HashMap> = HashMap::new(); for data in parts { + let hostname = if let Some(x) = &data.node.node_settings.hostname { + x + } else { + panic!() + }; part_map .entry(data.node_name.to_string()) .or_insert_with(HashMap::new) @@ -78,7 +83,7 @@ fn print_deployment(parts: &[&data::DeployData]) -> Result<(), toml::ser::Error> user: &data.profile_user, ssh_user: &data.ssh_user, path: &data.profile.profile_settings.path, - hostname: &data.node.node_settings.hostname, + hostname, ssh_opts: &data.merged_settings.ssh_opts, }, ); diff --git a/src/data.rs b/src/data.rs index c9b2fd59..7ab4e544 100644 --- a/src/data.rs +++ b/src/data.rs @@ -306,8 +306,8 @@ pub struct DeployData<'a> { pub enum DeployDataError { #[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")] NoProfileUser(String, String), - #[error("Value `hostname` is not define for profile {0} of node {1}")] - NoProfileHost(String, String), + #[error("Value `hostname` is not define for node {0}")] + NoHost(String), } #[derive(Parser, Debug, Clone, Default)] @@ -400,7 +400,11 @@ impl<'a> DeployData<'a> { }; let hostname = match hostname { Some(x) => x, - None => &node.node_settings.hostname, + None => if let Some(ref x) = node.node_settings.hostname { + x + } else { + return Err(DeployDataError::NoHost(node_name)); + }, }; let ssh_uri = format!("ssh://{}@{}", &ssh_user, &hostname); diff --git a/src/settings.rs b/src/settings.rs index 2be4e92b..f2929a2b 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -71,7 +71,7 @@ impl GenericSettings { #[derive(Deserialize, Debug, Clone)] pub struct NodeSettings { - pub hostname: String, + pub hostname: Option, pub profiles: HashMap, #[serde( skip_serializing_if = "Vec::is_empty",