From: dliu5 Date: Tue, 22 Nov 2022 09:36:16 +0000 (+0800) Subject: Adjust some debug level to make consistent. X-Git-Tag: 2.0.0-rc2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Ftags%2F2.0.0-rc2;p=pti%2Fo2.git Adjust some debug level to make consistent. Fix bug if user auth_token still not valid or obtained. Signed-off-by: dliu5 Change-Id: I29495cb60be43a0b3ee03c2e580eb5e05d8c46e7 --- diff --git a/o2common/authmw/authmiddleware.py b/o2common/authmw/authmiddleware.py index cd9df4b..3141263 100644 --- a/o2common/authmw/authmiddleware.py +++ b/o2common/authmw/authmiddleware.py @@ -84,8 +84,9 @@ class authmiddleware(): self.app = app def __call__(self, environ, start_response): - logger.info(__name__ + 'authentication middleware') + logger.debug(__name__ + 'authentication middleware') req = Request(environ, populate_request=True, shallow=True) + auth_token = None try: auth_header = req.headers.get('Authorization', None) if auth_header: @@ -95,7 +96,7 @@ class authmiddleware(): # invoke underlying auth mdw to make k8s/keystone api ret = ad.authenticate(auth_token) if ret is True: - logger.info( + logger.debug( "auth success with oauth token: " + auth_token) try: return self.app(environ, start_response) @@ -123,9 +124,16 @@ class authmiddleware(): return _response_wrapper(environ, start_response, ex.dictize(), prb.serialize()) except Exception as ex: - logger.error('Internal exception happended {}'.format( - str(ex)), exc_info=True) - prb = AuthProblemDetails(500, 'Internal error.', req.path) - return \ - _internal_err_response_wrapper(environ, - start_response, prb.serialize()) + if auth_token: + logger.error('Internal exception happended {}'.format( + str(ex)), exc_info=True) + prb = AuthProblemDetails(500, 'Internal error.', req.path) + return \ + _internal_err_response_wrapper( + environ, start_response, prb.serialize()) + else: + logger.debug('Auth token missing or not obtained.') + ex = AuthRequiredExp('Bearer realm="Authentication Required"') + prb = AuthProblemDetails(401, ex.value, req.path) + return _response_wrapper(environ, start_response, + ex.dictize(), prb.serialize()) diff --git a/o2common/authmw/authprov.py b/o2common/authmw/authprov.py index 17c5349..c6f5646 100644 --- a/o2common/authmw/authprov.py +++ b/o2common/authmw/authprov.py @@ -109,7 +109,7 @@ class k8s_auth_provider(auth_definer): response = urllib.request.urlopen(req) data = json.load(response) if data['status']['authenticated'] is True: - logger.info("Authenticated.") + logger.debug("Authenticated.") return True except Exception as ex: strex = str(ex)