Skip to content

Commit

Permalink
Add keyring support
Browse files Browse the repository at this point in the history
This makes osc2 compatible with current configs generated by osc.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Mar 4, 2014
1 parent 793616f commit bfa26e5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions osc/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import inspect
import logging
import urlparse
from ConfigParser import SafeConfigParser

from osc.core import Osc
Expand Down Expand Up @@ -42,6 +43,13 @@ def _init(apiurl):
if cp.has_option(section, 'passx'):
password = cp.get(section, 'pass', raw=True)
password = password.decode('base64').decode('bz2')
if cp.has_option(section, 'keyring') and cp.get(section, 'keyring', raw=True) == '1':
try:
import keyring
host = urlparse.urlparse(apiurl).hostname
password = keyring.get_password(host, user)
except ImportError:
raise ValueError('Keyring module not available, but ~/.oscrc stores password there')
if password is None:
raise ValueError('No password provided for {0}'.format(section))
Osc.init(section, username=user, password=password)
Expand Down

0 comments on commit bfa26e5

Please sign in to comment.