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

cli args for connection options #95

Merged
merged 5 commits into from
Sep 22, 2024
Merged

Conversation

achristmascarl
Copy link
Owner

allows many different ways to run and pass in options. also closes #75

@achristmascarl
Copy link
Owner Author

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements significant improvements to the rainfrog CLI, addressing the security concerns raised in Issue #75 regarding password handling. Key changes include:

  • New CLI options for individual connection parameters (username, password, host, port, database)
  • Flexible input methods, including prompting for missing information
  • Use of PgConnectOptions instead of connection strings for improved security
  • Updated README with clear instructions on various ways to provide connection details
  • Removal of tick_rate and frame_rate options for simplified configuration

These changes enhance the tool's security and usability, providing users with more secure ways to input database credentials.

6 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

@@ -29,7 +35,8 @@ async fn tokio_main() -> Result<()> {
initialize_panic_handler()?;

let args = Cli::parse();
let mut app = App::new(args.connection_url, args.tick_rate, args.frame_rate)?;
let connection_opts = build_connection_opts(args.clone())?;
Copy link

Choose a reason for hiding this comment

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

style: Cloning args here may be unnecessary. Consider passing by reference if possible.

Comment on lines +67 to +68
io::stdout().flush().unwrap();
io::stdin().read_line(&mut user).unwrap();
Copy link

Choose a reason for hiding this comment

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

logic: Use of unwrap() here and in other similar places could lead to panics. Consider using ? or proper error handling.

if let Some(password) = args.password {
opts = opts.password(&password);
} else {
let mut password = rpassword::prompt_password(format!("password for user {}: ", opts.get_username())).unwrap();
Copy link

Choose a reason for hiding this comment

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

logic: Using unwrap() on prompt_password could lead to a panic if there's an error. Consider proper error handling.

io::stdin().read_line(&mut port).unwrap();
port = port.trim().to_string();
if !port.is_empty() {
opts = opts.port(port.parse()?);
Copy link

Choose a reason for hiding this comment

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

style: Parsing the port here could fail. The error is propagated, but consider providing a more specific error message.

@@ -44,3 +51,77 @@ async fn main() -> Result<()> {
Ok(())
}
}

// sqlx defaults to reading from environment variables if no inputs are provided
Copy link

Choose a reason for hiding this comment

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

style: The build_connection_opts function is quite long. Consider breaking it down into smaller, more manageable functions.

@achristmascarl achristmascarl merged commit 0a509c5 into main Sep 22, 2024
8 checks passed
@achristmascarl achristmascarl deleted the feat/obscured-password-entry branch September 22, 2024 21:44
Copy link

Included in release v0.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Secure way of specifying password
1 participant