Skip to content

Commit b8e44bf

Browse files
committed
2 parents 540c488 + 0f3f2db commit b8e44bf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

openstackclient/shell.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
import getpass
23+
import keyring
2324
import logging
2425
import os
2526
import sys
@@ -33,6 +34,7 @@
3334

3435

3536
VERSION = '0.1'
37+
KEYRING_SERVICE = 'openstack'
3638

3739

3840
def env(*vars, **kwargs):
@@ -149,12 +151,14 @@ def authenticate_user(self):
149151
"You must provide a username via"
150152
" either --os-username or env[OS_USERNAME]")
151153

154+
self.get_password_from_keyring()
152155
if not self.options.os_password:
153156
# No password, if we've got a tty, try prompting for it
154157
if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty():
155158
# Check for Ctl-D
156159
try:
157160
self.options.os_password = getpass.getpass()
161+
self.set_password_in_keyring()
158162
except EOFError:
159163
pass
160164
# No password because we did't have a tty or the
@@ -188,6 +192,24 @@ def authenticate_user(self):
188192
)
189193
return
190194

195+
def get_password_from_keyring(self):
196+
"""Get password from keyring, if it's set"""
197+
service = KEYRING_SERVICE
198+
if not self.options.os_password:
199+
password = keyring.get_password(service, self.options.os_username)
200+
os.options.os_password = password
201+
202+
def set_password_in_keyring(self):
203+
"""Set password in keyring for this user"""
204+
service = KEYRING_SERVICE
205+
if self.options.os_password:
206+
password = keyring.get_password(service, self.options.os_username)
207+
# either password is not set in keyring, or it is different
208+
if password != self.options.os_password:
209+
keyring.set_password(service,
210+
self.options.os_username,
211+
self.options.os_password)
212+
191213
def initialize_app(self, argv):
192214
"""Global app init bits:
193215

tools/pip-requires

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cliff
22
argparse
33
httplib2
4+
keyring
45
prettytable
56
python-keystoneclient>=0.1,<0.2
67
python-novaclient>=2,<3

0 commit comments

Comments
 (0)