-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(cli): remove hardcoded SSH key paths from config #293
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
Conversation
Remove ssh.key_path and ssh.private_key_path from CLI config. Instead, dynamically locate the private key by matching against the public key registered with Basilica using find_private_key_for_public_key(). This simplifies configuration and enables SSH to work correctly when the user has multiple SSH keys.
WalkthroughThe PR refactors SSH key path handling by removing configuration-based storage and switching to dynamic discovery via API. Instead of reading SSH key paths from config, the CLI now derives the private key for the current SSH public key and explicitly passes it through SSH operation handlers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/basilica-cli/src/cli/handlers/gpu_rental.rs (1)
479-494: Consider extracting repeated private key lookup into a helper function.This 12-line pattern for looking up the private key via
get_ssh_key()andfind_private_key_for_public_key()is duplicated at least 4 times in this file (lines 479-494, 523-537, 664-679, 699-713). Consider extracting to a helper like:async fn get_private_key_path(api_client: &BasilicaClient) -> Result<PathBuf, CliError> { let ssh_key = api_client .get_ssh_key() .await .map_err(|e| CliError::Internal(eyre!(e)))? .ok_or_else(|| { CliError::Internal( eyre!("No SSH key registered with Basilica") .suggestion("Run 'basilica ssh-keys add' to register your SSH key"), ) })?; find_private_key_for_public_key(&ssh_key.public_key) .map_err(CliError::Internal) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
config/cli.toml.example(1 hunks)crates/basilica-cli/src/cli/handlers/gpu_rental.rs(18 hunks)crates/basilica-cli/src/config/mod.rs(0 hunks)crates/basilica-cli/src/ssh/mod.rs(7 hunks)
💤 Files with no reviewable changes (1)
- crates/basilica-cli/src/config/mod.rs
🧰 Additional context used
🧬 Code graph analysis (1)
crates/basilica-cli/src/cli/handlers/gpu_rental.rs (2)
crates/basilica-cli/src/ssh/key_matcher.rs (1)
find_private_key_for_public_key(24-103)crates/basilica-cli/src/output/mod.rs (1)
compress_path(45-53)
🔇 Additional comments (7)
crates/basilica-cli/src/ssh/mod.rs (1)
53-78: LGTM! Clean refactor to explicit private key path.The change from optional override to required
PathBufsimplifies the API contract. The existence check at line 58 with actionable suggestions is a good UX improvement. All callers are now forced at compile-time to provide a valid path.config/cli.toml.example (1)
12-15: LGTM! Config simplified by removing SSH key path settings.The removal of
key_pathandprivate_key_pathaligns with the PR objective to use dynamic key discovery. Theconnection_timeoutis appropriately retained for operational configuration.crates/basilica-cli/src/cli/handlers/gpu_rental.rs (5)
1259-1269: Good use of graceful degradation for status display.The use of
ok().flatten().and_then()appropriately allows the status command to succeed even when the private key cannot be found locally. This is the right pattern for a read-only informational command.
1768-1769: LGTM! Efficient private key lookup using rental's public key.Using the public key from
resolve_rental_with_sshrather than making an additional API call is efficient. The ownership transfer ofprivate_key_pathtoexecute_commandis correct.
2002-2019: LGTM! Correct RFC 1918 private IP detection.The implementation correctly checks all three RFC 1918 private address ranges. The safe default of returning
falsefor unparseable addresses is appropriate for this use case.
2127-2158: LGTM! Correct handling of PathBuf in retry loop.The use of
private_key_path.clone()in the loop (line 2150) is necessary since we may retry multiple times. The final successful connection appropriately moves ownership tointeractive_session(line 2157).
2335-2358: Good graceful degradation for SSH display when key is unavailable.The conditional logic properly handles both cases: showing the full SSH command with private key path when available, or a basic command with a helpful warning when the key isn't found locally. This provides a good user experience.
Removes
ssh.key_pathandssh.private_key_pathfrom CLI config. Instead, the private key is dynamically located by matching against the public key registered with Basilica usingfind_private_key_for_public_key().This simplifies configuration and enables SSH to work correctly when the user has multiple SSH keys.
Summary by CodeRabbit
Release Notes
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.