# Path: locksmith/lightauth/common.py
# def check_key(key, signing_key=SIGNING_KEY, api=API_NAME, endpoint=ENDPOINT):
#     try:
#         apicall(endpoint, signing_key,
#             api=api, key=key
#         )
#         return True
#     except urllib2.HTTPError as e:
#         if e.code == 404:
#             return None
#         else:
#             raise
# 
# Path: locksmith/common.py
# def cache(seconds = 900):
#     def doCache(f):
#         def x(*args, **kwargs):
#                 key = sha1(str(f.__module__) + str(f.__name__) + str(args) + str(kwargs)).hexdigest()
#                 result = _djcache.get(key)
#                 if result is None:
#                     result = f(*args, **kwargs)
#                     _djcache.set(key, result, seconds)
#                 return result
#         return x
#     return doCache


from django.conf import settings
from locksmith.lightauth.common import check_key as _check_key
from locksmith.common import cache

check_key = cache(seconds=86400)(_check_key)

QS_PARAM = getattr(settings, 'LOCKSMITH_QS_PARAM', 'apikey')
HTTP_HEADER = getattr(settings, 'LOCKSMITH_HTTP_HEADER', 'HTTP_X_APIKEY')

class APIKeyMiddleware(object):
    def process_request(self, request):

# Path: locksmith/lightauth/common.py
# def check_key(key, signing_key=SIGNING_KEY, api=API_NAME, endpoint=ENDPOINT):
#     try:
#         apicall(endpoint, signing_key,
#             api=api, key=key
#         )
#         return True
#     except urllib2.HTTPError as e:
#         if e.code == 404:
#             return None
#         else:
#             raise
# 
# Path: locksmith/common.py
# def cache(seconds = 900):
#     def doCache(f):
#         def x(*args, **kwargs):
#                 key = sha1(str(f.__module__) + str(f.__name__) + str(args) + str(kwargs)).hexdigest()
#                 result = _djcache.get(key)
#                 if result is None:
#                     result = f(*args, **kwargs)
#                     _djcache.set(key, result, seconds)
#                 return result
#         return x
#     return doCache


# Path: locksmith/lightauth/middleware.py
from django.conf import settings
from locksmith.lightauth.common import check_key as _check_key
from locksmith.common import cache


check_key = cache(seconds=86400)(_check_key)

QS_PARAM = getattr(settings, 'LOCKSMITH_QS_PARAM', 'apikey')
HTTP_HEADER = getattr(settings, 'LOCKSMITH_HTTP_HEADER', 'HTTP_X_APIKEY')

class APIKeyMiddleware(object):
    def process_request(self, request):

        key = request.GET.get(QS_PARAM, None) or request.META.get(HTTP_HEADER, None)