Skip to content

Commit 1d116f0

Browse files
author
Matthew Fisher
committed
Merge pull request #2140 from bacongobbler/whoami
feat(client): add auth:whoami
2 parents 4ef8c53 + 7987f41 commit 1d116f0

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

client/deis.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ def auth(self, args):
684684
auth:cancel remove the current account
685685
auth:login authenticate against a controller
686686
auth:logout clear the current user session
687+
auth:whoami display the authenticated user
687688
688689
Use `deis help [command]` to learn more.
689690
"""
@@ -803,6 +804,7 @@ def auth_login(self, args):
803804
response = self._session.post(url, data=payload, allow_redirects=False)
804805
if response.status_code == requests.codes.found: # @UndefinedVariable
805806
self._settings['controller'] = controller
807+
self._settings['username'] = username
806808
self._settings.save()
807809
self._logger.info("Logged in as {}".format(username))
808810
return username
@@ -824,9 +826,23 @@ def auth_logout(self, args):
824826
self._session.cookies.clear()
825827
self._session.cookies.save()
826828
self._settings['controller'] = None
829+
self._settings['username'] = None
827830
self._settings.save()
828831
self._logger.info('Logged out')
829832

833+
def auth_whoami(self, args):
834+
"""
835+
Displays the currently logged in user.
836+
837+
Usage: deis auth:whoami
838+
"""
839+
user = self._settings.get('username')
840+
if user:
841+
self._logger.info(user)
842+
else:
843+
self._logger.info(
844+
'Not logged in. Use `deis login` or `deis register` to get started.')
845+
830846
def builds(self, args):
831847
"""
832848
Valid commands for builds:
@@ -2130,6 +2146,7 @@ def shortcuts(self, args):
21302146
('sharing:list', 'perms:list'),
21312147
('sharing:add', 'perms:create'),
21322148
('sharing:remove', 'perms:delete'),
2149+
('whoami', 'auth:whoami'),
21332150
])
21342151

21352152

tests/auth_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestAuth(t *testing.T) {
1919
authRegisterTest(t, params)
2020
authLogoutTest(t, params)
2121
authLoginTest(t, params)
22+
authWhoamiTest(t, params)
2223
authCancel(t, params)
2324
}
2425

@@ -48,3 +49,7 @@ func authRegisterTest(t *testing.T, params *utils.DeisTestConfig) {
4849
utils.Execute(t, cmd, params, false, "")
4950
utils.Execute(t, cmd, params, true, "Registration failed")
5051
}
52+
53+
func authWhoamiTest(t *testing.T, params *utils.DeisTestConfig) {
54+
utils.Execute(t, "auth:whoami", params, true, params.UserName)
55+
}

0 commit comments

Comments
 (0)