Added a node name to init so we can run multiple nodes with stable identifiers

This commit is contained in:
Dave Hrycyszyn
2024-06-06 16:02:00 +01:00
parent 1e1f452cff
commit c05cc7b15c
5 changed files with 8 additions and 7 deletions

View File

@@ -21,5 +21,5 @@ pub(crate) enum Commands {
Run {},
/// initializes the Side Node with a new keypair
Init {},
Init { name: String },
}

View File

@@ -10,10 +10,11 @@ pub(crate) struct SideNodeConfig {
pub(crate) name: String,
}
pub(crate) fn write_config_to_file(
pub(crate) fn write(
config: &SideNodeConfig,
file_path: &PathBuf,
) -> Result<(), Box<dyn std::error::Error>> {
println!("Writing config to: {:?}", file_path);
let toml_string = to_string(config)?;
let mut file = File::create(file_path)?;
file.write_all(toml_string.as_bytes())?;

View File

@@ -13,7 +13,7 @@ pub(crate) fn setup() -> String {
}
/// Writes a PEM-encoded string to a file at key_path.
pub(crate) fn write_pem(key_path: PathBuf, pem: String) -> Result<(), std::io::Error> {
pub(crate) fn write(key_path: PathBuf, pem: String) -> Result<(), std::io::Error> {
println!("Writing key to: {:?}", key_path);
let mut file = File::create(key_path)?;
file.write(pem.to_string().as_bytes())?;

View File

@@ -13,9 +13,9 @@ pub(crate) fn init(home: PathBuf, config: SideNodeConfig) -> Result<(), std::io:
let (key_path, config_path) = side_paths(home.clone());
let pem = keys::setup();
keys::write_pem(key_path, pem)?;
keys::write(key_path, pem)?;
config::write_config_to_file(&config, &config_path).expect("unable to write config file");
config::write(&config, &config_path).expect("unable to write config file");
Ok(())
}

View File

@@ -10,9 +10,9 @@ async fn main() {
let args = parse_args();
match &args.command {
Some(Commands::Init {}) => {
Some(Commands::Init { name }) => {
let config = init::config::SideNodeConfig {
name: "alice".to_string(),
name: name.to_string(),
};
let _ = init::init(home(), config);