@@ -659,10 +659,11 @@ def auth(self, args):
659659 Valid commands for auth:
660660
661661 auth:register register a new user
662- auth:cancel remove the current account
663662 auth:login authenticate against a controller
664663 auth:logout clear the current user session
665- auth:whoami display the authenticated user
664+ auth:passwd change the password for the current user
665+ auth:whoami display the current user
666+ auth:cancel remove the current user account
666667
667668 Use `deis help [command]` to learn more.
668669 """
@@ -794,6 +795,40 @@ def auth_logout(self, args):
794795 self ._settings .save ()
795796 self ._logger .info ('Logged out' )
796797
798+ def auth_passwd (self , args ):
799+ """
800+ Changes the password for the current user.
801+
802+ Usage: deis auth:passwd [options]
803+
804+ Options:
805+ --password=<password>
806+ provide the current password for the account.
807+ --new-password=<new-password>
808+ provide a new password for the account.
809+ """
810+ if not self ._settings .get ('token' ):
811+ raise EnvironmentError (
812+ 'Could not find token. Use `deis login` or `deis register` to get started.' )
813+ password = args .get ('--password' )
814+ if not password :
815+ password = getpass ('current password: ' )
816+ new_password = args .get ('--new-password' )
817+ if not new_password :
818+ new_password = getpass ('new password: ' )
819+ confirm = getpass ('new password (confirm): ' )
820+ if new_password != confirm :
821+ self ._logger .error ('Password mismatch, not changing.' )
822+ sys .exit (1 )
823+ payload = {'password' : password , 'new_password' : new_password }
824+ response = self ._dispatch ('post' , "/v1/auth/passwd" , json .dumps (payload ))
825+ if response .status_code == requests .codes .ok :
826+ self ._logger .info ('Password change succeeded.' )
827+ else :
828+ self ._logger .info ("Password change failed: {}" .format (response .text ))
829+ sys .exit (1 )
830+ return True
831+
797832 def auth_whoami (self , args ):
798833 """
799834 Displays the currently logged in user.
@@ -1913,6 +1948,7 @@ def shortcuts(self, args):
19131948 ('logout' , 'auth:logout' ),
19141949 ('logs' , 'apps:logs' ),
19151950 ('open' , 'apps:open' ),
1951+ ('passwd' , 'auth:passwd' ),
19161952 ('pull' , 'builds:create' ),
19171953 ('register' , 'auth:register' ),
19181954 ('rollback' , 'releases:rollback' ),
0 commit comments