Log reauth

Log a debug message when SDK logic triggers a reauth.

Reauth is a significant event that dev and ops may want logged.

Change-Id: I111db62dc7320e6c9429040e36ceb14da2e2bf9d
This commit is contained in:
Everett Toews
2015-06-30 11:10:22 -05:00
parent 9fb0681721
commit 58572ac666
2 changed files with 15 additions and 1 deletions

View File

@@ -15,12 +15,15 @@
# limitations under the License.
import datetime
import logging
from oslo_utils import timeutils
from openstack.auth import service_catalog as catalog
logger = logging.getLogger(__name__)
# Do not use token before expiration
BEST_BEFORE_SECONDS = 30
@@ -70,7 +73,12 @@ class AccessInfo(object):
"""
norm_expires = timeutils.normalize_time(self.expires)
soon = (timeutils.utcnow() + datetime.timedelta(seconds=best_before))
return norm_expires < soon
expiring = norm_expires < soon
if expiring:
logger.debug("Token expiring at %s", norm_expires)
return expiring
@classmethod
def is_valid(cls, body, **kwargs):

View File

@@ -15,6 +15,8 @@ The base identity plugin. Identity plugins must define the authorize method.
For examples of this class, see the v2 and v3 authentication plugins.
"""
import logging
import abc
import six
@@ -22,6 +24,9 @@ import six
from openstack.auth import base
logger = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class BaseIdentityPlugin(base.BaseAuthPlugin):
@@ -106,6 +111,7 @@ class BaseIdentityPlugin(base.BaseAuthPlugin):
:returns AccessInfo: Valid AccessInfo
"""
if self._needs_reauthenticate():
logger.debug("Re-authentication required")
self.access_info = self.authorize(transport)
return self.access_info