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 all commits
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.

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
2 changes: 1 addition & 1 deletion crates/ash_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rustls-pemfile = "1.0.3"
sha2 = "0.10.7"
oauth2 = "4.4.2"
url = "2.4.1"
ash_api = { version = "0.1.4" }
ash_api = { version = "0.1.5" }
rcgen = "0.11.3"

[dev-dependencies]
Expand Down
Loading