From bc43f8bdfc1eb793c72bec4fc147f98ea7ecd752 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Sep 14 2017 22:18:35 +0000 Subject: modify activate_session to be easily used without CLI Related: https://pagure.io/koji/issue/436 --- diff --git a/cli/koji_cli/lib.py b/cli/koji_cli/lib.py index 4b4a504..2f3aa8e 100644 --- a/cli/koji_cli/lib.py +++ b/cli/koji_cli/lib.py @@ -540,21 +540,25 @@ def has_krb_creds(): def activate_session(session, options): """Test and login the session is applicable""" - if options.authtype == "noauth" or options.noauth: + if isinstance(options, dict): + options = optparse.Values(options) + noauth = options.authtype == "noauth" or getattr(options, 'noauth', False) + if noauth: #skip authentication pass elif options.authtype == "ssl" or os.path.isfile(options.cert) and options.authtype is None: # authenticate using SSL client cert session.ssl_login(options.cert, None, options.serverca, proxyuser=options.runas) - elif options.authtype == "password" or options.user and options.authtype is None: + elif options.authtype == "password" or getattr(options, 'user', None) and options.authtype is None: # authenticate using user/password session.login() elif options.authtype == "kerberos" or has_krb_creds() and options.authtype is None: try: + runas = getattr(options, 'runas', None) if options.keytab and options.principal: - session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=options.runas) + session.krb_login(principal=options.principal, keytab=options.keytab, proxyuser=runas) else: - session.krb_login(proxyuser=options.runas) + session.krb_login(proxyuser=runas) except socket.error as e: warn(_("Could not connect to Kerberos authentication service: %s") % e.args[1]) except Exception as e: @@ -562,7 +566,7 @@ def activate_session(session, options): error(_("Kerberos authentication failed: %s (%s)") % (e.args[1], e.args[0])) else: raise - if not options.noauth and options.authtype != "noauth" and not session.logged_in: + if not noauth and not session.logged_in: error(_("Unable to log in, no authentication methods available")) ensure_connection(session) if options.debug: