From fe57fa18d163c87dbf02f2652085218ea14d10a9 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Feb 01 2023 14:01:15 +0000 Subject: Add decorator for renew expired session --- diff --git a/koji/__init__.py b/koji/__init__.py index 9014661..fd3c0e8 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2688,6 +2688,7 @@ class ClientSession(object): sinfo = None finally: self.opts = old_opts + if not sinfo: err = 'unable to obtain a session' if e_str: @@ -2894,6 +2895,7 @@ class ClientSession(object): return result def _renew_session(self): + """Renew expirated session or subsession.""" if not hasattr(self, 'auth_method'): raise GenericError("Missing info for reauthentication") # will be deleted by setSession @@ -2906,9 +2908,19 @@ class ClientSession(object): if self.exclusive: self.exclusiveSession() + def renew_expired_session(func): + """Decorator to renew expirated session or subsession.""" + def _renew_expired_session(*args, **kwargs): + try: + return func(*args, **kwargs) + except AuthExpired: + args[0]._renew_session() + return func(*args, **kwargs) + return _renew_expired_session + + @renew_expired_session def _callMethod(self, name, args, kwargs=None, retry=True): """Make a call to the hub with retries and other niceties""" - if self.multicall: if kwargs is None: kwargs = {} @@ -2944,13 +2956,6 @@ class ClientSession(object): # server correctly reporting an outage tries = 0 continue - elif isinstance(err, AuthExpired): - if self.logged_in: - self._renew_session() - return self._callMethod(name, args, kwargs, retry) - else: - raise AuthError("Session ID %s is unlogged and expired." % - self.sinfo['session-id']) else: raise err