Skip to content

Commit

Permalink
Managing re-authentication with a certificate for cookie expiration.
Browse files Browse the repository at this point in the history
  • Loading branch information
JkhatriInfobox committed Nov 15, 2024
1 parent ad1e56b commit 90c81c4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions infoblox_client/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ def wrapper(self, *args, **kwargs):

LOG.warning("Clearing cookies and re-authenticating.")
self.session.cookies.clear()
self.session.auth = (self.username, self.password)
LOG.warning("Re-executing the request.")
if hasattr(self, 'username') and hasattr(self, 'password'):
LOG.warning("Re-authenticating with username and password.")
self.session.auth = (self.username, self.password)
elif hasattr(self, 'cert') and hasattr(self, 'key'):
LOG.warning("Re-authenticating with client certificate.")
self.session.cert = (self.cert, self.key)
else:
LOG.warning("No valid credentials found to re-authenticate.")
raise ib_ex.InfobloxConfigException(
msg="No valid credentials found to re-authenticate.")
return func(self, *args, **kwargs)
return wrapper

Expand Down Expand Up @@ -313,7 +321,16 @@ def _validate_cookie(self):
LOG.info("Cookie expired. \
Clearing cookies and re-authenticating on the next request.")
self.session.cookies.clear()
self.session.auth = (self.username, self.password)
if hasattr(self, 'username') and hasattr(self, 'password'):
LOG.info("Re-authenticating with username and password.")
self.session.auth = (self.username, self.password)
elif hasattr(self, 'cert') and hasattr(self, 'key'):
LOG.info("Re-authenticating with client certificate.")
self.session.cert = (self.cert, self.key)
else:
LOG.warning("No valid credentials found to re-authenticate.")
raise ib_ex.InfobloxConfigException(
msg="No valid credentials found to re-authenticate.")
else:
LOG.info("Using existing cookie for authentication")
self.session.auth = None # Do not re-authenticate
Expand Down

0 comments on commit 90c81c4

Please sign in to comment.