Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nodeBlsKey support #93

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ categories = [
"data-structures",
]
keywords = ["blockchain", "avalanche", "subnets", "ash"]

[patch.crates-io]
ash_api = { path = "../hai/ash-api-rs" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch is not appropriate here. We can just add a path field to the existing ash_cli dependency.

See https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies

Copy link
Contributor Author

@leopaul36 leopaul36 Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we had that until 1ff639b

Should we just go back to this?

5 changes: 5 additions & 0 deletions crates/ash_cli/examples/console/blueprint/devnet.yml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions crates/ash_cli/examples/console/blueprint/local-node-ids.yml

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions crates/ash_cli/src/console/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ fn load_node_id_tls_cert_key(
))
}
};
let bls_key = match node_id_secret.node_bls_key {
Some(ref key) => key,
None => {
return Err(CliError::dataerr(
"Error parsing node ID secret JSON: nodeBlsKey field is missing".to_string(),
))
}
};

let cert_path = PathBuf::from(&shellexpand::tilde(node_cert).to_string());
let key_path = PathBuf::from(&shellexpand::tilde(node_key).to_string());
let bls_key_path = PathBuf::from(&shellexpand::tilde(bls_key).to_string());

node_id_secret.node_cert = if cert_path.exists() {
Some(read_file_base64(cert_path)?)
Expand All @@ -111,6 +120,12 @@ fn load_node_id_tls_cert_key(
Some(node_key.clone())
};

node_id_secret.node_bls_key = if bls_key_path.exists() {
Some(read_file_bytes_base64(bls_key_path)?)
} else {
Some(bls_key.clone())
};

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions crates/ash_cli/src/utils/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub(crate) fn read_file_base64(file_path: PathBuf) -> Result<String, CliError> {
Ok(engine::general_purpose::STANDARD.encode(file_content))
}

// Read bytes from a file and return them as a Base64-encoded string
pub(crate) fn read_file_bytes_base64(file_path: PathBuf) -> Result<String, CliError> {
let file_content = fs::read(file_path)
.map_err(|e| CliError::dataerr(format!("Error reading file: {e}")))?;

Ok(engine::general_purpose::STANDARD.encode(file_content))
}

// Read content from stdin and return it as a string
pub(crate) fn read_stdin() -> Result<String, CliError> {
let mut content = String::new();
Expand Down
Loading