renew exclusive status as part of login

This commit is contained in:
Tomas Kopecek 2022-11-28 14:32:07 +01:00
parent dcd009e593
commit 906958c814
2 changed files with 23 additions and 11 deletions

View file

@ -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."""

View file

@ -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):