Skip to content

Commit df1b349

Browse files
committed
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
1 parent 5075460 commit df1b349

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/cli.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::collections::HashMap;
77
use std::io::{stdin, stdout, Write};
88

9-
use clap::{ArgMatches, FromArgMatches, Parser};
9+
use clap::{Parser};
1010

1111
use crate as deploy;
1212

@@ -69,6 +69,11 @@ fn print_deployment(parts: &[&data::DeployData]) -> Result<(), toml::ser::Error>
6969
let mut part_map: HashMap<String, HashMap<String, PromptPart>> = HashMap::new();
7070

7171
for data in parts {
72+
let hostname = if let Some(x) = &data.node.node_settings.hostname {
73+
x
74+
} else {
75+
panic!()
76+
};
7277
part_map
7378
.entry(data.node_name.to_string())
7479
.or_insert_with(HashMap::new)
@@ -78,7 +83,7 @@ fn print_deployment(parts: &[&data::DeployData]) -> Result<(), toml::ser::Error>
7883
user: &data.profile_user,
7984
ssh_user: &data.ssh_user,
8085
path: &data.profile.profile_settings.path,
81-
hostname: &data.node.node_settings.hostname,
86+
hostname,
8287
ssh_opts: &data.merged_settings.ssh_opts,
8388
},
8489
);

src/data.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ pub struct DeployData<'a> {
306306
pub enum DeployDataError {
307307
#[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")]
308308
NoProfileUser(String, String),
309-
#[error("Value `hostname` is not define for profile {0} of node {1}")]
310-
NoProfileHost(String, String),
309+
#[error("Value `hostname` is not define for node {0}")]
310+
NoHost(String),
311311
}
312312

313313
#[derive(Parser, Debug, Clone, Default)]
@@ -400,7 +400,11 @@ impl<'a> DeployData<'a> {
400400
};
401401
let hostname = match hostname {
402402
Some(x) => x,
403-
None => &node.node_settings.hostname,
403+
None => if let Some(ref x) = node.node_settings.hostname {
404+
x
405+
} else {
406+
return Err(DeployDataError::NoHost(node_name));
407+
},
404408
};
405409
let ssh_uri = format!("ssh://{}@{}", &ssh_user, &hostname);
406410

src/settings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl GenericSettings {
7171

7272
#[derive(Deserialize, Debug, Clone)]
7373
pub struct NodeSettings {
74-
pub hostname: String,
74+
pub hostname: Option<String>,
7575
pub profiles: HashMap<String, Profile>,
7676
#[serde(
7777
skip_serializing_if = "Vec::is_empty",

0 commit comments

Comments
 (0)