Ejemplo n.º 1
0
def app():
    mock_redis = FlaskRedis.from_custom_provider(FakeStrictRedis)
    flask_app = capp.create_app(True, mock_redis)
    database.config_engine('sqlite://', echo=True)
    database.init_db()
    connection = database.engine.connect()

    yield flask_app

    connection.close()
    database.Base.metadata.drop_all(bind=database.engine)
Ejemplo n.º 2
0
def run():
    """Work through job queue"""

    configuration = {
        'debug': False
    }

    configuration_file = pkg_resources.resource_filename(
        pkg_resources.Requirement.parse('commandment'),
        'config/config.json'
    )

    if os.path.exists(configuration_file):
        with open(configuration_file, 'r') as configuration_fh:
            loaded_configuration = json.load(configuration_fh)
        configuration.update(loaded_configuration)

    for key in ('host', 'port', 'pass', 'database'):
        keyu = key.upper()
        if os.environ.get('REDIS_%s' % keyu):
            configuration['redis'][key] = os.environ.get('REDIS_%s' % keyu)

    connection = redis.StrictRedis(
        host=configuration['redis']['host'],
        port=configuration['redis']['port'],
        db=configuration['redis']['database']
    )
    # Default docker image seems not to use password=configuration['redis']['pass']

    from commandment.database import db_session

    if 'database' not in configuration:
        configuration['database'] = {
            'uri': default_settings.DATABASE_URI,
            'echo': default_settings.DATABASE_ECHO
        }

    config_engine(configuration['database']['uri'], configuration['database']['echo'])

    try:
        init_db()
        push_init()

        with Connection(connection):
            worker = Worker('default')
            worker.work()

    finally:
        db_session.remove()
Ejemplo n.º 3
0
import os
import tempfile
import atexit
from commandment.app import create_app
from commandment.database import config_engine, init_db
from commandment.pki.ca import get_or_generate_web_certificate

if __name__ == '__main__':
    app = create_app()

    app.config.from_object('commandment.default_settings')

    if os.environ.get('COMMANDMENT_SETTINGS'):
        app.config.from_envvar('COMMANDMENT_SETTINGS')

    config_engine(app.config['DATABASE_URI'], app.config['DATABASE_ECHO'])

    init_db()

    web_crt_pem, web_key_pem = get_or_generate_web_certificate(app.config['DEV_WEB_CERT_CN'])

    # Werkzeug 0.10 decided to move away from a pyOpenSSL context in favor of
    # a Python 2.7.9+/3.x+ ssl.SSLContext. This sucks because there is no API
    # to provide in-memory certificates and private keys to said context.
    # Which means we must, unfortunately, use the filesystem to store
    # certificates just so we can load them for the development web server
    # while it runs. Also, of course, OS X shipped versions of Python do not
    # have a new enough version to make use of the SSLContext directly.
    # Luckily for us Werkzeug provides it's own emulation of an SSLContext if
    # we supply the cert and pk filenames in a tuple to it's ssl_context
    # parameter.
Ejemplo n.º 4
0
import werkzeug.serving
from commandment.app import create_app
from commandment.database import config_engine, init_db
from commandment.pki.ca import get_or_generate_web_certificate
from commandment.runner import start_runner, stop_runner
from commandment.push import push_init

if __name__ == '__main__':
    app = create_app()

    app.config.from_object('commandment.default_settings')

    if os.environ.get('COMMANDMENT_SETTINGS'):
        app.config.from_envvar('COMMANDMENT_SETTINGS')

    config_engine(app.config['DATABASE_URI'], app.config['DATABASE_ECHO'])

    init_db()

    web_crt_pem, web_key_pem, web_ca_pem = get_or_generate_web_certificate(
        app.config['DEV_WEB_CERT_CN'])

    # Werkzeug 0.10 decided to move away from a pyOpenSSL context in favor of
    # a Python 2.7.9+/3.x+ ssl.SSLContext. This sucks because there is no API
    # to provide in-memory certificates and private keys to said context.
    # Which means we must, unfortunately, use the filesystem to store
    # certificates just so we can load them for the development web server
    # while it runs. Also, of course, OS X shipped versions of Python do not
    # have a new enough version to make use of the SSLContext directly.
    # Luckily for us Werkzeug provides it's own emulation of an SSLContext if
    # we supply the cert and pk filenames in a tuple to it's ssl_context
Ejemplo n.º 5
0
            'uri': app.config['DATABASE_URI'],
            'echo': app.config['DATABASE_ECHO']
        }

    if os.environ.get('COMMANDMENT_PORT'):
        configuration['port'] = int(os.environ.get('COMMANDMENT_PORT'))

    if 'port' not in configuration:
        configuration['port'] = app.config.get('PORT')

    app.logger.info(configuration)

    app.config.update(configuration)

    print configuration['database']['uri'], configuration['database']['echo']
    config_engine(configuration['database']['uri'], configuration['database']['echo'])

    init_db()

    web_crt_pem, web_key_pem, web_ca_pem = get_or_generate_web_certificate(app.config['DEV_WEB_CERT_CN'])

    # Werkzeug 0.10 decided to move away from a pyOpenSSL context in favor of
    # a Python 2.7.9+/3.x+ ssl.SSLContext. This sucks because there is no API
    # to provide in-memory certificates and private keys to said context.
    # Which means we must, unfortunately, use the filesystem to store
    # certificates just so we can load them for the development web server
    # while it runs. Also, of course, OS X shipped versions of Python do not
    # have a new enough version to make use of the SSLContext directly.
    # Luckily for us Werkzeug provides it's own emulation of an SSLContext if
    # we supply the cert and pk filenames in a tuple to it's ssl_context
    # parameter. Note this is also done in push.py as the apns library uses
Ejemplo n.º 6
0
            'uri': app.config['DATABASE_URI'],
            'echo': app.config['DATABASE_ECHO']
        }

    if os.environ.get('COMMANDMENT_PORT'):
        configuration['port'] = int(os.environ.get('COMMANDMENT_PORT'))

    if 'port' not in configuration:
        configuration['port'] = app.config.get('PORT')

    app.logger.info(configuration)

    app.config.update(configuration)

    print configuration['database']['uri'], configuration['database']['echo']
    config_engine(configuration['database']['uri'],
                  configuration['database']['echo'])

    init_db()

    web_crt_pem, web_key_pem, web_ca_pem = get_or_generate_web_certificate(
        app.config['DEV_WEB_CERT_CN'])

    # Werkzeug 0.10 decided to move away from a pyOpenSSL context in favor of
    # a Python 2.7.9+/3.x+ ssl.SSLContext. This sucks because there is no API
    # to provide in-memory certificates and private keys to said context.
    # Which means we must, unfortunately, use the filesystem to store
    # certificates just so we can load them for the development web server
    # while it runs. Also, of course, OS X shipped versions of Python do not
    # have a new enough version to make use of the SSLContext directly.
    # Luckily for us Werkzeug provides it's own emulation of an SSLContext if
    # we supply the cert and pk filenames in a tuple to it's ssl_context