Skip to content

Commit

Permalink
imp(hostname): make hostname optional
Browse files Browse the repository at this point in the history
- generic nixosconfig be known that are hydrated with a target-ip
  during runtime (e.g. from a remote source)
- Example: auto scaling groups
  • Loading branch information
blaggacao committed Nov 6, 2021
1 parent 5075460 commit df1b349
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,6 +69,11 @@ fn print_deployment(parts: &[&data::DeployData]) -> Result<(), toml::ser::Error>
let mut part_map: HashMap<String, HashMap<String, PromptPart>> = 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)
Expand All @@ -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,
},
);
Expand Down
10 changes: 7 additions & 3 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl GenericSettings {

#[derive(Deserialize, Debug, Clone)]
pub struct NodeSettings {
pub hostname: String,
pub hostname: Option<String>,
pub profiles: HashMap<String, Profile>,
#[serde(
skip_serializing_if = "Vec::is_empty",
Expand Down

0 comments on commit df1b349

Please sign in to comment.