-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
47 lines (41 loc) · 1.37 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
The API launch script.
:copyright: (c) 2014 by Nicola Iarocci and CIR2000.
:license: BSD, see LICENSE for more details.
"""
from eve import Eve
from eve.auth import TokenAuth
import os
class Auth(TokenAuth):
""" This class implements Token Based Authentication for our API
endpoints. Since the API itself is going to be on SSL, we're fine with this
variation of Basic Authentication.
For details on Eve authentication handling see:
http://python-eve.org/authentication.html
"""
def check_auth(self, token, allowed_roles, resource, method):
accounts = app.data.driver.db['accounts']
lookup = {'t': token}
if allowed_roles:
# only retrieve a user if his roles match ``allowed_roles``
lookup['r'] = {'$in': allowed_roles}
account = accounts.find_one(lookup)
if account:
self.request_auth_value = account['_id']
return account is not None
# Heroku defines a $PORT environment variable that we use to determine
# if we're running locally or not.
port = os.environ.get('PORT')
if port:
# app = Eve(auth=Auth)
# let's run it as an open service for the time being
app = Eve()
host = '0.0.0.0'
port = int(port)
else:
app = Eve()
host = '127.0.0.1'
port = 5000
if __name__ == '__main__':
app.run(host=host, port=port)