From 906958c81498c0f930d994808d17e1cebb492754 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Feb 01 2023 14:01:15 +0000 Subject: renew exclusive status as part of login --- diff --git a/koji/__init__.py b/koji/__init__.py index e12b0b3..966b374 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2498,8 +2498,11 @@ class ClientSession(object): """ # store calling parameters self.auth_method = {'method': 'login', 'kwargs': {'opts': opts}} - sinfo = self.callMethod('login', self.opts['user'], self.opts['password'], opts=opts, - renew=renew) + kwargs = {'opts': opts} + if renew: + kwargs['renew'] = True + kwargs['exclusive'] = self.exclusive + sinfo = self.callMethod('login', self.opts['user'], self.opts['password'], **kwargs) if not sinfo: return False self.setSession(sinfo) @@ -2575,7 +2578,10 @@ class ClientSession(object): # will fail with a handshake failure, which is retried by default. # For this case we're now using retry=False and test errors for # this exact usecase. - kwargs = {'proxyuser': proxyuser, 'renew': renew} + kwargs = {'proxyuser': proxyuser} + if renew: + kwargs['renew'] = True + kwargs['exclusive'] = self.exclusive if proxyauthtype is not None: kwargs['proxyauthtype'] = proxyauthtype for tries in range(self.opts.get('max_retries', 30)): @@ -2671,7 +2677,10 @@ class ClientSession(object): self.opts['serverca'] = serverca e_str = None try: - kwargs = {'proxyuser': proxyuser, 'renew': renew} + kwargs = {'proxyuser': proxyuser} + if renew: + kwargs['renew'] = True + kwargs['exclusive'] = self.exclusive if proxyauthtype is not None: kwargs['proxyauthtype'] = proxyauthtype sinfo = self._callMethod('sslLogin', [], kwargs) @@ -2903,8 +2912,6 @@ class ClientSession(object): kwargs['renew'] = True self.logged_in = False auth_method(*args, **kwargs) - if self.exclusive: - self.exclusiveSession() def renew_expired_session(func): """Decorator to renew expirated session or subsession.""" diff --git a/koji/auth.py b/koji/auth.py index d381848..efcb1b6 100644 --- a/koji/auth.py +++ b/koji/auth.py @@ -120,7 +120,8 @@ class Session(object): columns, aliases = zip(*fields) query = QueryProcessor(tables=['sessions'], columns=columns, aliases=aliases, - clauses=['id = %(id)i', 'key = %(key)s', 'hostip = %(hostip)s'], + clauses=['id = %(id)i', 'key = %(key)s', 'hostip = %(hostip)s', + 'closed IS FALSE'], values={'id': self.id, 'key': self.key, 'hostip': hostip}, opts={'rowlock': True}) session_data = query.executeOne(strict=False) @@ -146,7 +147,7 @@ class Session(object): try: callnum = int(callnum) except (ValueError, TypeError): - raise koji.AuthError("Invalid callnum: %r" % callnum) + raise koji.AuthError(f"Invalid callnum: {callnum!r}") lastcall = session_data['callnum'] if lastcall is not None: if lastcall > callnum: @@ -285,7 +286,7 @@ class Session(object): if result['status'] != koji.USER_STATUS['NORMAL']: raise koji.AuthError('logins by %s are not allowed' % result['name']) - def login(self, user, password, opts=None, session_key=None): + def login(self, user, password, opts=None, renew=False, exclusive=False): """create a login session""" if opts is None: opts = {} @@ -307,7 +308,9 @@ class Session(object): # create session and return sinfo = self.createSession(user_id, hostip, koji.AUTHTYPES['NORMAL'], - session_key=session_key) + renew=renew) + if sinfo and exclusive and not self.exclusive: + self.makeExclusive() context.cnx.commit() return sinfo @@ -332,7 +335,7 @@ class Session(object): return (local_ip, local_port, remote_ip, remote_port) - def sslLogin(self, proxyuser=None, proxyauthtype=None, renew=False): + def sslLogin(self, proxyuser=None, proxyauthtype=None, renew=False, exclusive=None): """Login into brew via SSL. proxyuser name can be specified and if it is allowed in the configuration file then connection is allowed to login as @@ -411,6 +414,8 @@ class Session(object): hostip = self.get_remote_ip() sinfo = self.createSession(user_id, hostip, authtype, renew=renew) + if sinfo and exclusive and not self.exclusive: + self.makeExclusive() return sinfo def makeExclusive(self, force=False):