コード例 #1
0
ファイル: main.py プロジェクト: gitter-badger/liftpass
def start():
	global app
	from tornado.wsgi import WSGIContainer
	from tornado.httpserver import HTTPServer
	from tornado.ioloop import IOLoop

	server = HTTPServer(WSGIContainer(app))
	server.listen(config.APIServer['port'], address=config.APIServer['address'])
	debug.log('Starting server at %s:%d'%(config.APIServer['address'], config.APIServer['port']))
	IOLoop.instance().start()
コード例 #2
0
ファイル: models.py プロジェクト: packetlost/liftpass
def flush():
	

	# s = getSession()
	for table in [Application, Currencies, Good, Metrics, ABTest, Prices, Events]:
		try:
			# rows = s.query(table).count()
			rows = 0
			debug.log('Deleting table %s with %d rows'%(table.__name__, rows))
			table.__table__.drop(getEngine())
			# s.commit()
			# s.flush()
		except Exception as e:
			debug.error('%s'%e)
コード例 #3
0
def flush():

    # s = getSession()
    for table in [
            Application, Currencies, Good, Metrics, ABTest, Prices, Events
    ]:
        try:
            # rows = s.query(table).count()
            rows = 0
            debug.log('Deleting table %s with %d rows' %
                      (table.__name__, rows))
            table.__table__.drop(getEngine())
            # s.commit()
            # s.flush()
        except Exception as e:
            debug.error('%s' % e)
コード例 #4
0
ファイル: rest.py プロジェクト: packetlost/liftpass
		def aux(*args, **kwargs):

			monitor.getMonitor().count('ApplicationRequestCount')
			
			debug.log('%s %s %s'%(request.method, request.path, request.environ.get('HTTP_X_REAL_IP')))

			with monitor.getMonitor().time('ApplicationValidateTime'):
				
				# All user input goes to the values field of the request
				message = request.get_data()
				if 'json' in request.args:
					message = base64.b64decode(request.args['json'])
					request.values = json.loads(message.decode('utf-8'))
				elif len(request.json):
					request.values = request.json


				# JSON must include time and user key
				if not all(map(lambda k: k in request.values, ['liftpass-time', 'liftpass-application'])):
					monitor.getMonitor().count('ApplicationRequestMissingHeaderCount')
					return buildResponse({'status': ERROR_UNAUTHORIZED, 'message':'JSON missing liftpass-time and/or liftpass-application keys'}, secret)

				# HTTP header must include hash for all requests
				if 'liftpass-hash' not in request.headers:
					monitor.getMonitor().count('ApplicationRequestMissingHashCount')
					return buildResponse({'status': ERROR_UNAUTHORIZED, 'message':'HTTP request missing liftpass-hash in header'}, secret)

				secret = secretLookup(request.values['liftpass-application'])
				if secret == None:
					monitor.getMonitor().count('ApplicationRequestApplicationNotFoundCount')
					return buildResponse({'status': ERROR_UNAUTHORIZED, 'message':'Application key not valid'}, secret)

				secret = secret.encode('utf-8')	
				digest = hmac.new(secret, message, hashlib.sha256).hexdigest()
				
				if digest != request.headers['liftpass-hash']:
					monitor.getMonitor().count('ApplicationRequestBadHashCount')
					return buildResponse({'status': ERROR_UNAUTHORIZED, 'message':'Failed to authenticate'}, secret)
				
				with monitor.getMonitor().time('ApplicationProcessResponseTime'):
					return buildResponse(f(*args, **kwargs), secret, request.values['liftpass-application'])
コード例 #5
0
        def aux(*args, **kwargs):

            monitor.getMonitor().count('ApplicationRequestCount')

            debug.log('%s %s %s' % (request.method, request.path,
                                    request.environ.get('HTTP_X_REAL_IP')))

            with monitor.getMonitor().time('ApplicationValidateTime'):

                # All user input goes to the values field of the request
                message = request.get_data()
                if 'json' in request.args:
                    message = base64.b64decode(request.args['json'])
                    request.values = json.loads(message.decode('utf-8'))
                elif len(request.json):
                    request.values = request.json

                # JSON must include time and user key
                if not all(
                        map(lambda k: k in request.values,
                            ['liftpass-time', 'liftpass-application'])):
                    monitor.getMonitor().count(
                        'ApplicationRequestMissingHeaderCount')
                    return buildResponse(
                        {
                            'status':
                            ERROR_UNAUTHORIZED,
                            'message':
                            'JSON missing liftpass-time and/or liftpass-application keys'
                        }, secret)

                # HTTP header must include hash for all requests
                if 'liftpass-hash' not in request.headers:
                    monitor.getMonitor().count(
                        'ApplicationRequestMissingHashCount')
                    return buildResponse(
                        {
                            'status':
                            ERROR_UNAUTHORIZED,
                            'message':
                            'HTTP request missing liftpass-hash in header'
                        }, secret)

                secret = secretLookup(request.values['liftpass-application'])
                if secret == None:
                    monitor.getMonitor().count(
                        'ApplicationRequestApplicationNotFoundCount')
                    return buildResponse(
                        {
                            'status': ERROR_UNAUTHORIZED,
                            'message': 'Application key not valid'
                        }, secret)

                secret = secret.encode('utf-8')
                digest = hmac.new(secret, message, hashlib.sha256).hexdigest()

                if digest != request.headers['liftpass-hash']:
                    monitor.getMonitor().count(
                        'ApplicationRequestBadHashCount')
                    return buildResponse(
                        {
                            'status': ERROR_UNAUTHORIZED,
                            'message': 'Failed to authenticate'
                        }, secret)

                with monitor.getMonitor().time(
                        'ApplicationProcessResponseTime'):
                    return buildResponse(
                        f(*args, **kwargs), secret,
                        request.values['liftpass-application'])