Retry asking for password when it doesn't match or is empty (#252)

* Retry asking for password when it doesn't match or is empty

* Limit to 3 retries and let user know of add-user command on failure

* Throw error on failure
This commit is contained in:
Emlyn Corrin 2017-12-10 15:13:34 +00:00 коммит произвёл Pablo Selem
Родитель 0efadefb98
Коммит 86515038e9
1 изменённых файлов: 13 добавлений и 7 удалений

Просмотреть файл

@ -13,13 +13,19 @@ def get_ssh_key_or_prompt(ssh_key, username, password, secrets_config):
ssh_key = get_ssh_key.get_user_public_key(ssh_key, secrets_config)
if username is not None and password is None and ssh_key is None:
password = getpass.getpass("Please input a password for user '{0}': ".format(username))
confirm_password = getpass.getpass("Please confirm your password for user '{0}': ".format(username))
if password != confirm_password:
raise error.AztkError("Password confirmation did not match, please try again.")
if not password:
raise error.AztkError(
"Password is empty, cannot add user to cluster. Provide a ssh public key in .aztk/secrets.yaml. Or provide an ssh-key or password with commnad line parameters (--ssh-key or --password).")
for i in range(3):
if i > 0:
log.error("Please try again.")
password = getpass.getpass("Please input a password for user '{0}': ".format(username))
confirm_password = getpass.getpass("Please confirm your password for user '{0}': ".format(username))
if password != confirm_password:
log.error("Password confirmation did not match.")
elif not password:
log.error("Password cannot be empty.")
else:
break
else:
raise error.AztkError("Failed to get valid password, cannot add user to cluster. It is recommended that you provide a ssh public key in .aztk/secrets.yaml. Or provide an ssh-key or password with commnad line parameters (--ssh-key or --password). You may also run the 'aztk spark cluster add-user' command to add a user to this cluster.")
return ssh_key, password
def print_cluster(client, cluster: aztk.spark.models.Cluster):