Added API access tracking to EVE Proxy and presented via SSO.

This commit is contained in:
2010-05-30 22:16:00 +01:00
parent 981a1843a6
commit 31e324d0a2
7 changed files with 110 additions and 25 deletions

View File

@@ -60,17 +60,17 @@ class CachedDocumentManager(models.Manager):
May also be a string representation of
the query: userID=1&characterID=xxxxxxxx
"""
if type({}) == type(params):
# If 'params' is a dictionary, convert it to a URL string.
params = urllib.urlencode(params)
elif params == None or params.strip() == '':
paramstr = urllib.urlencode(params)
if params == None or paramstr.strip() == '':
# For whatever reason, EVE API freaks out if there are no parameters.
# Add a bogus parameter if none are specified. I'm sure there's a
# better fix for this.
params = 'odd_parm=1'
paramstr = 'odd_parm=1'
# Combine the URL path and the parameters to create the full query.
query_name = '%s?%s' % (url_path, params)
query_name = '%s?%s' % (url_path, paramstr)
if no_cache:
# If no_cache is enabled, don't even attempt a lookup.
@@ -84,14 +84,33 @@ class CachedDocumentManager(models.Manager):
# EVE uses UTC.
current_eve_time = datetime.utcnow()
# If we have a service ID, store and strip it from the query string.
if 'service' in params:
service = params['service']
del params['service']
else:
service = 'auth'
if 'userID' in params:
userid = params['userID']
# Figure out if we need hit EVE API and re-cache, or just pull from
# the local cache (based on cached_until).
if no_cache or created or \
cached_doc.cached_until == None or \
current_eve_time > cached_doc.cached_until:
# Cache from EVE API
dom = self.cache_from_eve_api(cached_doc, url_path, params,
dom = self.cache_from_eve_api(cached_doc, url_path, paramstr,
no_cache=no_cache)
# If its a user related request, log the transaction.
if 'userID' in params:
log = ApiAccessLog()
log.userid = userid
log.service = service
log.time_access = datetime.utcnow()
log.document = url_path
log.save()
else:
# Parse the document here since it was retrieved from the
# database cache instead of queried for.
@@ -100,15 +119,17 @@ class CachedDocumentManager(models.Manager):
# Check for the presence errors. Only check the bare minimum,
# generic stuff that applies to most or all queries. User-level code
# should check for the more specific errors.
error_node = dom.getElementsByTagName('error')
if error_node:
error_code = error_node[0].getAttribute('code')
# User specified an invalid userid and/or auth key.
if error_code == '203':
raise APIAuthException()
elif error_code == '106':
raise APINoUserIDException()
if dom:
error_node = dom.getElementsByTagName('error')
if error_node:
error_code = error_node[0].getAttribute('code')
# User specified an invalid userid and/or auth key.
if error_code == '203':
raise APIAuthException()
elif error_code == '106':
raise APINoUserIDException()
return cached_doc
class CachedDocument(models.Model):
@@ -122,3 +143,12 @@ class CachedDocument(models.Model):
# The custom manager handles the querying.
objects = CachedDocumentManager()
class ApiAccessLog(models.Model):
"""
Provides a list of API accesses made by applications or Auth
"""
userid = models.IntegerField()
service = models.CharField(max_length=255)
time_access = models.DateTimeField()
document = models.CharField(max_length=255)