Allow for service names to propagate to the log

This commit is contained in:
2011-05-31 14:10:19 +01:00
parent 0f4bd89e92
commit b28170df3e
3 changed files with 5 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ class APIKeyAuthentication(object):
url = request.path
AuthAPILog(key=keyobj, access_datetime=datetime.utcnow(), url=url).save()
request.user = AnonymousUser()
request.api_key = keyobj
return True
return False

View File

@@ -112,7 +112,7 @@ class EveAPIProxyHandler(BaseHandler):
params['apikey'] = obj.api_key
try:
cached_doc = CachedDocument.objects.api_query(url_path, params)
cached_doc = CachedDocument.objects.api_query(url_path, params, service=request.api_key.description)
except DocumentRetrievalError, exc:
return HttpResponse(exc, status=500)
else:
@@ -130,7 +130,7 @@ class OpTimerHandler(BaseHandler):
error_doc = {'ops': [{'startsIn': -1, 'eventID': 0, 'ownerName': '', 'eventDate': '', 'eventTitle': '<div style="text-align:center">The EVE API calendar is unavailable</div>', 'duration': 0, 'isImportant': 0, 'eventText': 'Fuck CCP tbqh imho srsly', 'endsIn':-1, 'forumLink': ''}]}
try:
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params)
cached_doc = CachedDocument.objects.api_query('/char/UpcomingCalendarEvents.xml.aspx', params, service="Optimer")
except DocumentRetrievalError:
return error_doc
dom = minidom.parseString(cached_doc.body.encode('utf-8'))

View File

@@ -38,7 +38,7 @@ class CachedDocumentManager(models.Manager):
return url
def api_query(self, url_path, params={}, no_cache=False, exceptions=True):
def api_query(self, url_path, params={}, no_cache=False, exceptions=True, service="Auth"):
"""
Transparently handles querying EVE API or retrieving the document from
the cache.
@@ -104,7 +104,7 @@ class CachedDocumentManager(models.Manager):
for k in params:
if not k in ['userid', 'apikey', 'vcode', 'keyid']: fparams[k] = params[k]
ApiAccessLog(userid=v, service='Unknown', time_access=doc.time_retrieved, document=self.construct_url(url_path, fparams)).save()
ApiAccessLog(userid=v, service=service, time_access=doc.time_retrieved, document=self.construct_url(url_path, fparams)).save()
return doc