From bfa26e59e5f8a68fce81cfe5bd4b8a3631588545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 4 Mar 2014 15:37:28 +0100 Subject: [PATCH] Add keyring support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes osc2 compatible with current configs generated by osc. Signed-off-by: Michal Čihař --- osc/cli/cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osc/cli/cli.py b/osc/cli/cli.py index 17d5642..1be82f4 100644 --- a/osc/cli/cli.py +++ b/osc/cli/cli.py @@ -3,6 +3,7 @@ import os import inspect import logging +import urlparse from ConfigParser import SafeConfigParser from osc.core import Osc @@ -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)