From 14e35c4f4144495a2767a84fd4934fd5c2c9d8ce Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Nov 23 2016 15:57:26 +0000 Subject: Swtich to using CCColUtils to determine username from krb realms Signed-off-by: Patrick Uiterwijk --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 94374de..e488224 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -9,6 +9,7 @@ # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license. +import cccolutils import errno import fnmatch import git @@ -87,7 +88,7 @@ class Commands(object): gitbaseurl, anongiturl, branchre, kojiconfig, build_client, user=None, dist=None, target=None, quiet=False, - distgit_namespaced=False): + distgit_namespaced=False, realms=None): """Init the object and some configuration details.""" # Path to operate on, most often pwd @@ -183,6 +184,8 @@ class Commands(object): self.clone_config = None # Git namespacing for more than just rpm build artifacts self.distgit_namespaced = distgit_namespaced + # Kerberos realms used for username detection + self.realms = realms # Define properties here # Properties allow us to "lazy load" various attributes, which also means @@ -777,9 +780,27 @@ class Commands(object): """This property ensures the user attribute""" if not self._user: - self.load_user() + if not self._load_krb_user(): + self.load_user() return self._user + def _load_krb_user(self): + """This attempts to get the username from active tickets""" + + if not self.realms: + return False + + if not isinstance(self.realms, list): + self.realms = [self.realms] + + for realm in realms: + username = cccolutils.get_user_for_realm(realm) + if username: + self._user = username + return True + # We could not find a username for any of the realms, let's fall back + return False + def load_user(self): """This sets the user attribute""" diff --git a/setup.py b/setup.py index bfac7c6..ff9844e 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( scripts=['bin/rpkg'], data_files=[('/etc/bash_completion.d', ['etc/bash_completion.d/rpkg.bash']), ('/etc/rpkg', ['etc/rpkg/rpkg.conf'])], - install_requires=['six', 'pycurl'], # + koji, but it's not in PyPI + install_requires=['six', 'pycurl', 'cccolutils'], # + koji, but it's not in PyPI tests_require=['nose', 'mock', 'GitPython'], test_suite='nose.collector', classifiers=(