Skip to content

Commit

Permalink
Merge pull request #11 from indigo-dc/fix-caching-problem
Browse files Browse the repository at this point in the history
add logging and fix "broken cache" problem
  • Loading branch information
marcvs committed Feb 12, 2020
2 parents 35e19d6 + daef813 commit ca270bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 9 additions & 6 deletions flaat/__init__.py
Expand Up @@ -196,10 +196,9 @@ def get_info_from_userinfo_endpoints(self, access_token):

# get all possible issuer configs
issuer_configs = self._find_issuer_config_everywhere(access_token)
if issuer_configs is None:
if self.verbose:
print('No issuer config found')
return tokentools.merge_tokens(None)
if issuer_configs is None or len(issuer_configs) == 0 :
logger.warning('No issuer config found')
return None

# get userinfo
param_q = Queue(self.num_request_workers*2)
Expand All @@ -221,6 +220,7 @@ def thread_worker_get_userinfo():
t.daemon = True
t.start()

logger.debug (F"len of issuer_configs: {len(issuer_configs)}")
for issuer_config in issuer_configs:
# user_info = issuertools.get_user_info(access_token, issuer_config)
params = {}
Expand All @@ -235,10 +235,10 @@ def thread_worker_get_userinfo():
if user_info is not None:
return (user_info)
except Empty:
print ("EMPTY")
logger.info("EMPTY result in thead join")
# pass
except Exception as e:
print ("Error: Uncaught Exception: {}".format(str(e)))
logger.info("Error: Uncaught Exception: {}".format(str(e)))

return(user_info)
def get_info_from_introspection_endpoints(self, access_token):
Expand Down Expand Up @@ -296,6 +296,7 @@ def _get_all_info_from_request(self, param_request):
'''gather all info about the user that we can find.
Returns a "supertoken" json structure.'''
access_token = tokentools.get_access_token_from_request(param_request)
# logger.info (F"access_token: {access_token}")
return self.get_all_info_by_at(access_token)
def login_required(self, on_failure=None):
'''Decorator to enforce a valid login.
Expand All @@ -310,7 +311,9 @@ def decorated(*args, **kwargs):
except KeyError: # i.e. the environment variable was not set
pass
request_object = self._find_request_based_on_web_framework(request, args)
logger.info (F"request_object: {request_object}")
all_info = self._get_all_info_from_request(request_object)
# logger.info (F"all info: {all_info}")

if all_info is not None:
if self.verbose>1:
Expand Down
15 changes: 12 additions & 3 deletions flaat/issuertools.py
Expand Up @@ -23,6 +23,10 @@

from . import tokentools

import logging

logger = logging.getLogger(__name__)

# default values:
requests_cache.install_cache(include_get_headers=True, expire_after=300)

Expand Down Expand Up @@ -70,8 +74,8 @@ def thread_worker_issuerconfig():
if item is None:
break
result = get_iss_config_from_endpoint(item)
param_q.task_done()
result_q.put(result)
param_q.task_done()
result_q.task_done()

def find_issuer_config_in_list(op_list, op_hint = None, exclude_list = []):
Expand Down Expand Up @@ -103,9 +107,14 @@ def find_issuer_config_in_list(op_list, op_hint = None, exclude_list = []):
param_q.join()
result_q.join()
try:
for entry in iter(result_q.get_nowait, None):
iss_config.append(entry)
while not result_q.empty():
entry = result_q.get(block=False, timeout=2)
if entry is not None:
iss_config.append(entry)
# for entry in iter(result_q.get_nowait, None):
# iss_config.append(entry)
except Empty:
logger.info("exception: Empty value")
pass

return iss_config
Expand Down

0 comments on commit ca270bb

Please sign in to comment.