Add analytics on push and pull repo events in the backend.
This commit is contained in:
parent
e5d100842d
commit
00b8244661
5 changed files with 32 additions and 35 deletions
10
app.py
10
app.py
|
@ -6,16 +6,24 @@ from flask import Flask
|
|||
from flask.ext.principal import Principal
|
||||
from flask.ext.login import LoginManager
|
||||
from flask.ext.mail import Mail
|
||||
|
||||
from config import ProductionConfig, DebugConfig, LocalHostedConfig
|
||||
from util import analytics
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
stack = os.environ.get('STACK', '').strip().lower()
|
||||
if stack.startswith('prod'):
|
||||
logger.info('Running with production config.')
|
||||
config = ProductionConfig()
|
||||
elif stack.startswith('localhosted'):
|
||||
logger.info('Running with debug config on production data.')
|
||||
config = LocalHostedConfig()
|
||||
else:
|
||||
logger.info('Running with debug config.')
|
||||
config = DebugConfig()
|
||||
|
||||
app.config.from_object(config)
|
||||
|
@ -32,3 +40,5 @@ mail = Mail()
|
|||
mail.init_app(app)
|
||||
|
||||
stripe.api_key = app.config['STRIPE_SECRET_KEY']
|
||||
|
||||
mixpanel = analytics.init_app(app)
|
||||
|
|
14
config.py
14
config.py
|
@ -64,8 +64,16 @@ class StripeLiveConfig(object):
|
|||
STRIPE_PUBLISHABLE_KEY = 'pk_live_P5wLU0vGdHnZGyKnXlFG4oiu'
|
||||
|
||||
|
||||
class MixpanelTestConfig(object):
|
||||
MIXPANEL_KEY = '38014a0f27e7bdc3ff8cc7cc29c869f9'
|
||||
|
||||
|
||||
class MixpanelProdConfig(object):
|
||||
MIXPANEL_KEY = '50ff2b2569faa3a51c8f5724922ffb7e'
|
||||
|
||||
|
||||
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
||||
StripeTestConfig):
|
||||
StripeTestConfig, MixpanelTestConfig):
|
||||
REGISTRY_SERVER = 'localhost:5000'
|
||||
LOGGING_CONFIG = {
|
||||
'level': logging.DEBUG,
|
||||
|
@ -74,7 +82,7 @@ class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
|||
|
||||
|
||||
class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,
|
||||
StripeLiveConfig):
|
||||
StripeLiveConfig, MixpanelTestConfig):
|
||||
REGISTRY_SERVER = 'localhost:5000'
|
||||
LOGGING_CONFIG = {
|
||||
'level': logging.DEBUG,
|
||||
|
@ -83,7 +91,7 @@ class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,
|
|||
|
||||
|
||||
class ProductionConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,
|
||||
StripeLiveConfig):
|
||||
StripeLiveConfig, MixpanelProdConfig):
|
||||
REGISTRY_SERVER = 'quay.io'
|
||||
LOGGING_CONFIG = {
|
||||
'stream': sys.stderr,
|
||||
|
|
|
@ -7,7 +7,7 @@ from flask import request, make_response, jsonify, abort
|
|||
from functools import wraps
|
||||
|
||||
from data import model
|
||||
from app import app
|
||||
from app import app, mixpanel
|
||||
from auth.auth import (process_auth, get_authenticated_user,
|
||||
get_validated_token)
|
||||
from util.names import parse_namespace_repository, parse_repository_name
|
||||
|
@ -132,6 +132,9 @@ def create_repository(namespace, repository):
|
|||
image = model.create_image(image_description['id'], repo)
|
||||
|
||||
response = make_response('Created', 201)
|
||||
|
||||
mixpanel.track(get_authenticated_user().username, 'push_repo')
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
@ -177,6 +180,8 @@ def get_repository_images(namespace, repository):
|
|||
resp = make_response(json.dumps(all_images), 200)
|
||||
resp.mimetype = 'application/json'
|
||||
|
||||
mixpanel.track(get_authenticated_user().username, 'pull_repo')
|
||||
|
||||
return resp
|
||||
|
||||
abort(403)
|
||||
|
|
|
@ -10,3 +10,4 @@ pymysql
|
|||
stripe
|
||||
gunicorn
|
||||
eventlet
|
||||
mixpanel-py
|
|
@ -1,51 +1,24 @@
|
|||
Cheetah==2.4.4
|
||||
Flask==0.10.1
|
||||
Flask-Login==0.2.7
|
||||
Flask-Mail==0.9.0
|
||||
Flask-Principal==0.4.0
|
||||
Jinja2==2.7.1
|
||||
Landscape-Client==12.12
|
||||
M2Crypto==0.21.1
|
||||
MarkupSafe==0.18
|
||||
PAM==0.4.2
|
||||
PyMySQL==0.5
|
||||
PyYAML==3.10
|
||||
Twisted-Core==12.3.0
|
||||
Twisted-Names==12.3.0
|
||||
Twisted-Web==12.3.0
|
||||
Werkzeug==0.9.4
|
||||
apt-xapian-index==0.45
|
||||
argparse==1.2.1
|
||||
blinker==1.3
|
||||
boto==2.3.0
|
||||
chardet==2.0.1
|
||||
cloud-init==0.7.2
|
||||
configobj==4.7.2
|
||||
boto==2.13.3
|
||||
distribute==0.6.34
|
||||
distro-info==0.10
|
||||
euca2ools==2.1.1
|
||||
eventlet==0.14.0
|
||||
greenlet==0.4.1
|
||||
gunicorn==18.0
|
||||
itsdangerous==0.23
|
||||
oauth==1.0.1
|
||||
paramiko==1.7.7.1
|
||||
mixpanel-py==3.0.0
|
||||
peewee==2.1.4
|
||||
prettytable==0.6.1
|
||||
py-bcrypt==0.4
|
||||
pyOpenSSL==0.13
|
||||
pycrypto==2.6
|
||||
pycurl==7.19.0
|
||||
pygobject==3.8.0
|
||||
pyserial==2.6
|
||||
python-apt==0.8.8ubuntu6
|
||||
python-dateutil==2.1
|
||||
python-debian==0.1.21-nmu2ubuntu1
|
||||
requests==1.1.0
|
||||
six==1.2.0
|
||||
ssh-import-id==3.14
|
||||
requests==2.0.0
|
||||
six==1.4.1
|
||||
stripe==1.9.5
|
||||
urllib3==1.5
|
||||
virtualenv==1.9.1
|
||||
wsgiref==0.1.2
|
||||
zope.interface==4.0.5
|
||||
|
|
Reference in a new issue