commit 341896e1ee15d2509fe3a6efe23d25a99bed4228
Author: Till Maas <opensource(a)till.name>
Date: Fri May 30 10:05:00 2014 +0200
pkgdb2_cli: Ask for password only if required
Use login_callback to ask for username/password only when it is
required.
pkgdb2_cli.py | 40 ++++++++--------------------------------
pkgdb2client.py | 1 +
2 files changed, 9 insertions(+), 32 deletions(-)
---
diff --git a/pkgdb2_cli.py b/pkgdb2_cli.py
index e698dc7..8f5be19 100644
--- a/pkgdb2_cli.py
+++ b/pkgdb2_cli.py
@@ -18,17 +18,17 @@
from fedora.client import (AccountSystem, AppError, ServerError)
from bugzilla.rhbugzilla import RHBugzilla
from pkgdb2client import PkgDB, PkgDBException, __version__
+import pkgdb2client
import argparse
import logging
-import getpass
import koji
-import fedora_cert
KOJI_HUB = 'http://koji.fedoraproject.org/kojihub'
RH_BZ_API = 'https://bugzilla.redhat.com/xmlrpc.cgi'
-pkgdbclient =
PkgDB('https://admin.fedoraproject.org/pkgdb')
+pkgdbclient =
PkgDB('https://admin.fedoraproject.org/pkgdb';,
+ login_callback=pkgdb2client.ask_password)
fasclient =
AccountSystem('https://admin.fedoraproject.org/accounts')
BOLD = "\033[1m"
RED = "\033[0;31m"
@@ -48,31 +48,6 @@ class ActionError(Exception):
pass
-def __do_login(username=None, password=None):
- ''' Returned a BaseClient with authentification
-
- If the username is None, tries to retrieve it from fedora_cert.
-
- :arg pkgdbclient a PackageDB object to which username and password
- are added
- :karg username FAS username, if None it is asked to the user
- :karg password FAS password, if None it is asked to the user
- '''
- if pkgdbclient.is_logged_in:
- return
- else:
- if username is None and pkgdbclient.username is None:
- try:
- username = fedora_cert.read_user_cert()
- except:
- LOG.debug('Could not read Fedora cert, using login name')
- username = raw_input('FAS username: ')
- pkgdbclient.username = username
- if password is None and pkgdbclient.password is None:
- password = getpass.getpass('FAS password: ')
- pkgdbclient.login(username, password)
-
-
def _get_acls_info(acls):
''' Re-order the ACLs as provided by the PkgDB API in a way that can be
easily printed.
@@ -499,7 +474,7 @@ def do_orphan(args):
else:
branches = [args.branch]
- __do_login(args.username)
+ pkgdbclient.username = args.username
output = pkgdbclient.orphan_packages(pkgs, branches)
for msg in output.get('messages', []):
@@ -528,7 +503,7 @@ def do_unorphan(args):
else:
branches = [args.branch]
- __do_login(args.username)
+ pkgdbclient.username = args.username
username = args.poc or args.username or pkgdbclient.username
LOG.info("new poc : {0}".format(username))
@@ -563,7 +538,7 @@ def do_request(args):
if args.cancel:
status = 'Obsolete'
- __do_login(args.username)
+ pkgdbclient.username = args.username
LOG.info("user : {0}".format(pkgdbclient.username))
output = pkgdbclient.update_acl(
@@ -605,7 +580,7 @@ def do_update(args):
if args.approve:
status = "Approved"
- __do_login(args.username)
+ pkgdbclient.username = args.username
output = pkgdbclient.update_acl(
args.package,
@@ -669,6 +644,7 @@ def main():
insecure=True)
pkgdbclient = PkgDB(
'https://admin.stg.fedoraproject.org/pkgdb',
+ login_callback=pkgdb2client.ask_password,
insecure=True)
return_code = 0
diff --git a/pkgdb2client.py b/pkgdb2client.py
index 2e029bf..e74caf6 100644
--- a/pkgdb2client.py
+++ b/pkgdb2client.py
@@ -79,6 +79,7 @@ def ask_password(username=None, bad_password=False):
try:
username = fedora_cert.read_user_cert()
except fedora_cert.fedora_cert_error:
+ LOG.debug('Could not read Fedora cert, asking for username')
username = raw_input("Username: ")
password = getpass.getpass("FAS password for user {0}: ".format(username))
return username, password