@@ -22,14 +22,18 @@ def profile():
2222 "-n" ,
2323 "--name" ,
2424 required = True ,
25- type = str ,
2625 help = "The name of the Code42 CLI profile to use when executing this command." ,
2726)
2827server_option = click .option (
29- "-s" , "--server" , required = True , type = str , help = "The url and port of the Code42 server."
28+ "-s" , "--server" , required = True , help = "The url and port of the Code42 server."
3029)
3130username_option = click .option (
32- "-u" , "--username" , required = True , type = str , help = "The username of the Code42 API user."
31+ "-u" , "--username" , required = True , help = "The username of the Code42 API user."
32+ )
33+ password_option = click .option (
34+ "--password" ,
35+ help = "The password for the Code42 API user. If this option is omitted, interactive prompts "
36+ "will be used to obtain the password." ,
3337)
3438disable_ssl_option = click .option (
3539 "--disable-ssl-errors" ,
@@ -58,32 +62,44 @@ def show(profile_name):
5862@name_option
5963@server_option
6064@username_option
65+ @password_option
6166@disable_ssl_option
62- def create (name , server , username , disable_ssl_errors = False ):
67+ def create (name , server , username , password , disable_ssl_errors ):
6368 """Create profile settings. The first profile created will be the default."""
6469 cliprofile .create_profile (name , server , username , disable_ssl_errors )
65- _prompt_for_allow_password_set (name )
70+ if password :
71+ _set_pw (name , password )
72+ else :
73+ _prompt_for_allow_password_set (name )
6674 echo ("Successfully created profile '{}'." .format (name ))
6775
6876
6977@profile .command ()
7078@name_option
7179@server_option
7280@username_option
81+ @password_option
7382@disable_ssl_option
74- def update (name = None , server = None , username = None , disable_ssl_errors = None ):
83+ def update (name , server , username , password , disable_ssl_errors ):
7584 """Update an existing profile."""
7685 c42profile = cliprofile .get_profile (name )
7786 cliprofile .update_profile (c42profile .name , server , username , disable_ssl_errors )
78- _prompt_for_allow_password_set (c42profile .name )
87+ if password :
88+ _set_pw (name , password )
89+ else :
90+ _prompt_for_allow_password_set (c42profile .name )
7991 echo ("Profile '{}' has been updated." .format (c42profile .name ))
8092
8193
8294@profile .command ()
8395@profile_name_arg
84- def reset_pw (profile_name = None ):
85- """Change the stored password for a profile."""
86- _reset_pw (profile_name )
96+ def reset_pw (profile_name ):
97+ """\b
98+ Change the stored password for a profile. Only affects what's stored in the local profile,
99+ does not make any changes to the Code42 user account."""
100+ password = getpass ()
101+ _set_pw (profile_name , password )
102+ echo ("Password updated for profile '{}'" .format (profile_name ))
87103
88104
89105@profile .command ("list" )
@@ -101,6 +117,7 @@ def _list():
101117def use (profile_name ):
102118 """Set a profile as the default."""
103119 cliprofile .switch_default_profile (profile_name )
120+ echo ("{} has been set as the default profile." .format (profile_name ))
104121
105122
106123@profile .command ()
@@ -136,15 +153,15 @@ def delete_all():
136153
137154def _prompt_for_allow_password_set (profile_name ):
138155 if does_user_agree ("Would you like to set a password? (y/n): " ):
139- _reset_pw (profile_name )
156+ password = getpass ()
157+ _set_pw (profile_name , password )
140158
141159
142- def _reset_pw (profile_name ):
160+ def _set_pw (profile_name , password ):
143161 c42profile = cliprofile .get_profile (profile_name )
144- new_password = getpass ()
145162 try :
146- validate_connection (c42profile .authority_url , c42profile .username , new_password )
163+ validate_connection (c42profile .authority_url , c42profile .username , password )
147164 except Exception :
148165 secho ("Password not stored!" , bold = True )
149166 raise
150- cliprofile .set_password (new_password , c42profile .name )
167+ cliprofile .set_password (password , c42profile .name )
0 commit comments