-
Notifications
You must be signed in to change notification settings - Fork 17
Allow username and password to be passed into register with flags #401
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,21 +444,35 @@ pub fn get_active_cluster<'a>( | |
} | ||
} | ||
|
||
pub fn get_username_and_password() -> Result<(String, String), ShellError> { | ||
println!("Please enter username:"); | ||
let username = match read_input() { | ||
Some(user) => user, | ||
None => { | ||
return Err(generic_error("Username required", None, None)); | ||
} | ||
}; | ||
|
||
let password = match rpassword::prompt_password("Password: ") { | ||
Ok(p) => p, | ||
Err(_) => { | ||
return Err(generic_error("Password required", None, None)); | ||
} | ||
}; | ||
pub fn get_username_and_password( | ||
user_flag: Option<String>, | ||
password_flag: Option<String>, | ||
) -> Result<(String, String), ShellError> { | ||
let username = user_flag.map_or_else( | ||
|| { | ||
println!("Please enter username:"); | ||
read_input().ok_or_else(|| generic_error("Username required", None, None)) | ||
}, | ||
Ok, | ||
)?; | ||
|
||
let password = password_flag.map_or_else( | ||
|| match rpassword::prompt_password("Password: ") { | ||
Ok(p) => { | ||
if p.is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like the original code had this check, is it needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code didn't have this check as I thought that Even when using certs cbshell needs the username and password to perform any doc ops. Also when we register a cluster through the config file we return an error if there is no username and password, so I think it should be the same when registering a cluster through this command. The other place this is used is when creating credentials, where we obviously need a username and password. I think if there was something that used wither certs or username/password it'd be the responsibility of the caller to call this func if they require a username and password, and don't if a cert has been supplied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the context, makes sense. |
||
Err(generic_error("Password required", None, None)) | ||
} else { | ||
Ok(p) | ||
} | ||
} | ||
Err(e) => Err(generic_error( | ||
format!("Failed to parse password: {}", e), | ||
None, | ||
None, | ||
)), | ||
}, | ||
Ok, | ||
)?; | ||
|
||
Ok((username, password)) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.