2013-10-01 03:54:12 +00:00
|
|
|
import logging
|
2014-01-30 18:32:06 +00:00
|
|
|
import logstash_formatter
|
2014-02-18 23:09:14 +00:00
|
|
|
import requests
|
2014-03-05 19:35:11 +00:00
|
|
|
import os.path
|
2013-10-01 03:54:12 +00:00
|
|
|
|
2013-09-30 23:10:27 +00:00
|
|
|
from peewee import MySQLDatabase, SqliteDatabase
|
2013-11-07 04:21:12 +00:00
|
|
|
from storage.s3 import S3Storage
|
|
|
|
from storage.local import LocalStorage
|
|
|
|
from data.userfiles import UserRequestFiles
|
2014-02-04 00:08:37 +00:00
|
|
|
from data.buildlogs import BuildLogs
|
2014-02-07 01:58:26 +00:00
|
|
|
from data.userevent import UserEventBuilder
|
2013-11-07 04:21:12 +00:00
|
|
|
from util import analytics
|
|
|
|
|
|
|
|
from test.teststorage import FakeStorage, FakeUserfiles
|
|
|
|
from test import analytics as fake_analytics
|
2014-02-11 00:12:43 +00:00
|
|
|
from test.testlogs import TestBuildLogs
|
2013-09-30 23:10:27 +00:00
|
|
|
|
2013-10-01 03:54:12 +00:00
|
|
|
|
2013-09-27 23:29:01 +00:00
|
|
|
class FlaskConfig(object):
|
|
|
|
SECRET_KEY = '1cb18882-6d12-440d-a4cc-b7430fb5f884'
|
2014-02-05 22:05:06 +00:00
|
|
|
JSONIFY_PRETTYPRINT_REGULAR = False
|
2013-09-28 00:03:07 +00:00
|
|
|
|
2014-02-18 23:09:14 +00:00
|
|
|
|
2014-01-27 22:46:21 +00:00
|
|
|
class FlaskProdConfig(FlaskConfig):
|
|
|
|
SESSION_COOKIE_SECURE = True
|
|
|
|
|
|
|
|
|
2013-09-27 23:29:01 +00:00
|
|
|
class MailConfig(object):
|
|
|
|
MAIL_SERVER = 'email-smtp.us-east-1.amazonaws.com'
|
|
|
|
MAIL_USE_TLS = True
|
|
|
|
MAIL_PORT = 587
|
|
|
|
MAIL_USERNAME = 'AKIAIXV5SDGCPVMU3N4Q'
|
|
|
|
MAIL_PASSWORD = 'AhmX/vWE91uQ2RtcEKTkfNrzZehEjPNXOXeOXgQNfLao'
|
2013-10-01 19:48:53 +00:00
|
|
|
DEFAULT_MAIL_SENDER = 'support@quay.io'
|
2013-09-27 23:29:01 +00:00
|
|
|
MAIL_FAIL_SILENTLY = False
|
|
|
|
TESTING = False
|
|
|
|
|
2013-09-28 00:03:07 +00:00
|
|
|
|
2014-02-16 23:59:24 +00:00
|
|
|
class RealTransactions(object):
|
|
|
|
@staticmethod
|
|
|
|
def create_transaction(db):
|
|
|
|
return db.transaction()
|
|
|
|
|
|
|
|
DB_TRANSACTION_FACTORY = create_transaction
|
|
|
|
|
|
|
|
|
|
|
|
class SQLiteDB(RealTransactions):
|
2013-10-18 20:36:11 +00:00
|
|
|
DB_NAME = 'test/data/test.db'
|
2013-09-30 23:10:27 +00:00
|
|
|
DB_CONNECTION_ARGS = {
|
2014-03-06 19:47:02 +00:00
|
|
|
'threadlocals': True,
|
|
|
|
'autorollback': True,
|
2013-09-30 23:10:27 +00:00
|
|
|
}
|
|
|
|
DB_DRIVER = SqliteDatabase
|
|
|
|
|
|
|
|
|
2014-02-16 23:59:24 +00:00
|
|
|
class FakeTransaction(object):
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, value, traceback):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
class EphemeralDB(object):
|
|
|
|
DB_NAME = ':memory:'
|
|
|
|
DB_CONNECTION_ARGS = {}
|
|
|
|
DB_DRIVER = SqliteDatabase
|
|
|
|
|
2014-02-16 23:59:24 +00:00
|
|
|
@staticmethod
|
|
|
|
def create_transaction(db):
|
|
|
|
return FakeTransaction()
|
|
|
|
|
|
|
|
DB_TRANSACTION_FACTORY = create_transaction
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
|
2014-02-16 23:59:24 +00:00
|
|
|
class RDSMySQL(RealTransactions):
|
2013-09-30 23:10:27 +00:00
|
|
|
DB_NAME = 'quay'
|
|
|
|
DB_CONNECTION_ARGS = {
|
|
|
|
'host': 'fluxmonkeylogin.cb0vumcygprn.us-east-1.rds.amazonaws.com',
|
|
|
|
'user': 'fluxmonkey',
|
|
|
|
'passwd': '8eifM#uoZ85xqC^',
|
2013-10-01 03:54:12 +00:00
|
|
|
'threadlocals': True,
|
2014-03-06 19:47:02 +00:00
|
|
|
'autorollback': True,
|
2013-09-30 23:10:27 +00:00
|
|
|
}
|
|
|
|
DB_DRIVER = MySQLDatabase
|
|
|
|
|
|
|
|
|
2013-10-25 05:14:38 +00:00
|
|
|
class AWSCredentials(object):
|
2013-09-30 23:10:27 +00:00
|
|
|
AWS_ACCESS_KEY = 'AKIAJWZWUIS24TWSMWRA'
|
|
|
|
AWS_SECRET_KEY = 'EllGwP+noVvzmsUGQJO1qOMk3vm10Vg+UE6xmmpw'
|
|
|
|
REGISTRY_S3_BUCKET = 'quay-registry'
|
2013-10-25 05:14:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class S3Storage(AWSCredentials):
|
2013-11-07 04:21:12 +00:00
|
|
|
STORAGE = S3Storage('', AWSCredentials.AWS_ACCESS_KEY,
|
|
|
|
AWSCredentials.AWS_SECRET_KEY,
|
|
|
|
AWSCredentials.REGISTRY_S3_BUCKET)
|
2013-09-30 23:10:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LocalStorage(object):
|
2013-11-07 04:21:12 +00:00
|
|
|
STORAGE = LocalStorage('test/data/registry')
|
|
|
|
|
|
|
|
|
|
|
|
class FakeStorage(object):
|
|
|
|
STORAGE = FakeStorage()
|
|
|
|
|
|
|
|
|
|
|
|
class FakeUserfiles(object):
|
|
|
|
USERFILES = FakeUserfiles()
|
|
|
|
|
|
|
|
|
|
|
|
class S3Userfiles(AWSCredentials):
|
|
|
|
USERFILES = UserRequestFiles(AWSCredentials.AWS_ACCESS_KEY,
|
|
|
|
AWSCredentials.AWS_SECRET_KEY,
|
|
|
|
AWSCredentials.REGISTRY_S3_BUCKET)
|
2013-09-30 23:10:27 +00:00
|
|
|
|
|
|
|
|
2014-02-04 00:08:37 +00:00
|
|
|
class RedisBuildLogs(object):
|
|
|
|
BUILDLOGS = BuildLogs('logs.quay.io')
|
|
|
|
|
|
|
|
|
2014-02-07 01:58:26 +00:00
|
|
|
class UserEventConfig(object):
|
|
|
|
USER_EVENTS = UserEventBuilder('logs.quay.io')
|
|
|
|
|
|
|
|
|
2014-02-11 00:12:43 +00:00
|
|
|
class TestBuildLogs(object):
|
2014-02-11 17:09:59 +00:00
|
|
|
BUILDLOGS = TestBuildLogs('logs.quay.io', 'devtable', 'building',
|
|
|
|
'deadbeef-dead-beef-dead-beefdeadbeef')
|
2014-02-11 00:12:43 +00:00
|
|
|
|
|
|
|
|
2013-10-02 04:48:03 +00:00
|
|
|
class StripeTestConfig(object):
|
|
|
|
STRIPE_SECRET_KEY = 'sk_test_PEbmJCYrLXPW0VRLSnWUiZ7Y'
|
|
|
|
STRIPE_PUBLISHABLE_KEY = 'pk_test_uEDHANKm9CHCvVa2DLcipGRh'
|
|
|
|
|
|
|
|
|
|
|
|
class StripeLiveConfig(object):
|
|
|
|
STRIPE_SECRET_KEY = 'sk_live_TRuTHYwTvmrLeU3ib7Z9hpqE'
|
|
|
|
STRIPE_PUBLISHABLE_KEY = 'pk_live_P5wLU0vGdHnZGyKnXlFG4oiu'
|
|
|
|
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
class FakeAnalytics(object):
|
|
|
|
ANALYTICS = fake_analytics
|
|
|
|
|
|
|
|
|
2013-10-03 20:19:01 +00:00
|
|
|
class MixpanelTestConfig(object):
|
2013-11-07 04:21:12 +00:00
|
|
|
ANALYTICS = analytics
|
2013-10-03 20:19:01 +00:00
|
|
|
MIXPANEL_KEY = '38014a0f27e7bdc3ff8cc7cc29c869f9'
|
|
|
|
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
class MixpanelProdConfig(MixpanelTestConfig):
|
2013-10-03 20:19:01 +00:00
|
|
|
MIXPANEL_KEY = '50ff2b2569faa3a51c8f5724922ffb7e'
|
|
|
|
|
|
|
|
|
2013-10-10 03:00:34 +00:00
|
|
|
class GitHubTestConfig(object):
|
|
|
|
GITHUB_CLIENT_ID = 'cfbc4aca88e5c1b40679'
|
|
|
|
GITHUB_CLIENT_SECRET = '7d1cc21e17e10cd8168410e2cd1e4561cb854ff9'
|
|
|
|
GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token'
|
|
|
|
GITHUB_USER_URL = 'https://api.github.com/user'
|
|
|
|
GITHUB_USER_EMAILS = GITHUB_USER_URL + '/emails'
|
|
|
|
|
|
|
|
|
2014-03-05 00:40:29 +00:00
|
|
|
class GitHubStagingConfig(GitHubTestConfig):
|
|
|
|
GITHUB_CLIENT_ID = '4886304accbc444f0471'
|
|
|
|
GITHUB_CLIENT_SECRET = '27d8a5d99af02dda821eb10883bcb2e785e70a62'
|
|
|
|
|
|
|
|
|
2013-10-10 03:00:34 +00:00
|
|
|
class GitHubProdConfig(GitHubTestConfig):
|
|
|
|
GITHUB_CLIENT_ID = '5a8c08b06c48d89d4d1e'
|
|
|
|
GITHUB_CLIENT_SECRET = 'f89d8bb28ea3bd4e1c68808500d185a816be53b1'
|
|
|
|
|
|
|
|
|
2013-10-27 23:06:20 +00:00
|
|
|
class DigitalOceanConfig(object):
|
2013-10-24 20:37:03 +00:00
|
|
|
DO_CLIENT_ID = 'LJ44y2wwYj1MD0BRxS6qHA'
|
|
|
|
DO_CLIENT_SECRET = 'b9357a6f6ff45a33bb03f6dbbad135f9'
|
|
|
|
DO_SSH_KEY_ID = '46986'
|
2013-10-25 05:14:38 +00:00
|
|
|
DO_SSH_PRIVATE_KEY_FILENAME = 'certs/digital_ocean'
|
2013-10-27 23:06:20 +00:00
|
|
|
DO_ALLOWED_REGIONS = {1, 4}
|
2013-12-23 20:07:10 +00:00
|
|
|
DO_DOCKER_IMAGE = 1341147
|
2013-10-27 23:06:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BuildNodeConfig(object):
|
|
|
|
BUILD_NODE_PULL_TOKEN = 'F02O2E86CQLKZUQ0O81J8XDHQ6F0N1V36L9JTOEEK6GKKMT1GI8PTJQT4OU88Y6G'
|
2013-10-24 20:37:03 +00:00
|
|
|
|
|
|
|
|
2014-02-11 00:12:43 +00:00
|
|
|
def logs_init_builder(level=logging.DEBUG,
|
|
|
|
formatter=logstash_formatter.LogstashFormatter()):
|
2014-01-30 18:32:06 +00:00
|
|
|
@staticmethod
|
|
|
|
def init_logs():
|
2014-02-04 20:08:49 +00:00
|
|
|
handler = logging.StreamHandler()
|
2014-01-30 18:32:06 +00:00
|
|
|
root_logger = logging.getLogger('')
|
|
|
|
root_logger.setLevel(level)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
root_logger.addHandler(handler)
|
|
|
|
|
|
|
|
return init_logs
|
|
|
|
|
|
|
|
|
2014-02-18 23:09:14 +00:00
|
|
|
def build_requests_session():
|
|
|
|
sess = requests.Session()
|
|
|
|
adapter = requests.adapters.HTTPAdapter(pool_connections=100,
|
|
|
|
pool_maxsize=100)
|
|
|
|
sess.mount('http://', adapter)
|
|
|
|
sess.mount('https://', adapter)
|
|
|
|
return sess
|
|
|
|
|
|
|
|
|
|
|
|
class LargePoolHttpClient(object):
|
|
|
|
HTTPCLIENT = build_requests_session()
|
|
|
|
|
|
|
|
|
2014-03-05 19:35:11 +00:00
|
|
|
class StatusTagConfig(object):
|
|
|
|
STATUS_TAGS = {}
|
|
|
|
|
|
|
|
for tag_name in ['building', 'failed', 'none', 'ready']:
|
|
|
|
tag_path = os.path.join('buildstatus', tag_name + '.svg')
|
|
|
|
with open(tag_path) as tag_svg:
|
|
|
|
STATUS_TAGS[tag_name] = tag_svg.read()
|
|
|
|
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles,
|
2014-02-07 01:58:26 +00:00
|
|
|
FakeAnalytics, StripeTestConfig, RedisBuildLogs,
|
2014-03-05 19:35:11 +00:00
|
|
|
UserEventConfig, LargePoolHttpClient, StatusTagConfig):
|
2014-01-30 18:32:06 +00:00
|
|
|
LOGGING_CONFIG = logs_init_builder(logging.WARN)
|
2013-11-07 04:21:12 +00:00
|
|
|
POPULATE_DB_TEST_DATA = True
|
2013-11-07 17:54:44 +00:00
|
|
|
TESTING = True
|
2014-02-21 22:09:56 +00:00
|
|
|
URL_SCHEME = 'http'
|
|
|
|
URL_HOST = 'localhost:5000'
|
2013-11-07 04:21:12 +00:00
|
|
|
|
|
|
|
|
2013-10-02 04:48:03 +00:00
|
|
|
class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB,
|
2013-10-24 20:37:03 +00:00
|
|
|
StripeTestConfig, MixpanelTestConfig, GitHubTestConfig,
|
2014-02-04 00:08:37 +00:00
|
|
|
DigitalOceanConfig, BuildNodeConfig, S3Userfiles,
|
2014-03-05 19:35:11 +00:00
|
|
|
UserEventConfig, TestBuildLogs, LargePoolHttpClient,
|
|
|
|
StatusTagConfig):
|
2014-02-11 00:12:43 +00:00
|
|
|
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
2013-10-04 18:44:18 +00:00
|
|
|
SEND_FILE_MAX_AGE_DEFAULT = 0
|
2013-10-10 03:52:28 +00:00
|
|
|
POPULATE_DB_TEST_DATA = True
|
2014-02-21 22:09:56 +00:00
|
|
|
URL_SCHEME = 'http'
|
|
|
|
URL_HOST = 'ci.devtable.com:5000'
|
2013-09-30 23:10:27 +00:00
|
|
|
|
|
|
|
|
2013-10-02 04:48:03 +00:00
|
|
|
class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL,
|
2013-10-10 03:00:34 +00:00
|
|
|
StripeLiveConfig, MixpanelTestConfig,
|
2013-10-27 23:06:20 +00:00
|
|
|
GitHubProdConfig, DigitalOceanConfig,
|
2014-02-07 01:58:26 +00:00
|
|
|
BuildNodeConfig, S3Userfiles, RedisBuildLogs,
|
2014-03-05 19:35:11 +00:00
|
|
|
UserEventConfig, LargePoolHttpClient,
|
|
|
|
StatusTagConfig):
|
2014-03-05 00:40:29 +00:00
|
|
|
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
2013-10-04 18:44:18 +00:00
|
|
|
SEND_FILE_MAX_AGE_DEFAULT = 0
|
2014-02-21 22:09:56 +00:00
|
|
|
URL_SCHEME = 'http'
|
|
|
|
URL_HOST = 'ci.devtable.com:5000'
|
2013-10-01 21:23:29 +00:00
|
|
|
|
|
|
|
|
2014-03-05 00:40:29 +00:00
|
|
|
class StagingConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL,
|
|
|
|
StripeLiveConfig, MixpanelProdConfig,
|
|
|
|
GitHubStagingConfig, DigitalOceanConfig, BuildNodeConfig,
|
|
|
|
S3Userfiles, RedisBuildLogs, UserEventConfig,
|
2014-03-05 19:35:11 +00:00
|
|
|
LargePoolHttpClient, StatusTagConfig):
|
2014-03-05 00:40:29 +00:00
|
|
|
LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter())
|
|
|
|
SEND_FILE_MAX_AGE_DEFAULT = 0
|
|
|
|
URL_SCHEME = 'https'
|
|
|
|
URL_HOST = 'staging.quay.io'
|
|
|
|
|
|
|
|
|
2014-01-27 22:46:21 +00:00
|
|
|
class ProductionConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL,
|
2013-10-10 03:00:34 +00:00
|
|
|
StripeLiveConfig, MixpanelProdConfig,
|
2013-11-07 04:21:12 +00:00
|
|
|
GitHubProdConfig, DigitalOceanConfig, BuildNodeConfig,
|
2014-02-18 23:09:14 +00:00
|
|
|
S3Userfiles, RedisBuildLogs, UserEventConfig,
|
2014-03-05 19:35:11 +00:00
|
|
|
LargePoolHttpClient, StatusTagConfig):
|
2014-02-04 20:08:49 +00:00
|
|
|
LOGGING_CONFIG = logs_init_builder()
|
2013-10-04 18:44:18 +00:00
|
|
|
SEND_FILE_MAX_AGE_DEFAULT = 0
|
2014-02-21 22:09:56 +00:00
|
|
|
URL_SCHEME = 'https'
|
|
|
|
URL_HOST = 'quay.io'
|