Esempio n. 1
0
def api_user_required(func):
    @wraps(func)
    def decorator(*args, **kwargs):
        dev_key = request.args.get('dev_key', None)
        if not dev_key or len(dev_key) == 0:
            raise api_errors.ApiNotAuthenticatedError("no developer token provided")
        try:
            user = AdsApiUser.from_dev_key(dev_key)
        except Exception, e:
            import traceback
            exc_info = sys.exc_info()
            app.logger.error("User auth failure: %s, %s\n%s" % (exc_info[0], exc_info[1], traceback.format_exc()))
            statsd.incr("api.user.authentication.failed")
            user = None
        if not user:
            statsd.incr("api.user.authentication.unknown")
            raise api_errors.ApiNotAuthenticatedError("unknown dev_key: %s" % dev_key)
        statsd.incr("api.user.authentication.success")
        statsd.set("api.unique_users", dev_key)
        g.api_user = user
        return func(*args, **kwargs)
Esempio n. 2
0
 def count_uniques():
     statsd.set('unique_users', g.user_cookie_id)
     statsd.set('unique_ips', request.remote_addr)