Exemplo n.º 1
0
def create_app(config_filename='config.yaml'):

    app = App(__name__, static_url_path='/static', static_folder=xdg_static_folder())
    app.url_map.converters.update(dict(
        sid=SIDConverter,
        sha1=SHA1Converter,
        label=LabelConverter,
        namespace=NamespaceConverter,
        handler=HandlerConverter
    ))

    load_config(app, config_filename)
    init_db(app)
    init_cache(app)
    init_template(app)
    init_logging(app)

    app.after_request(cors)

    app.register_blueprint(paste)
    app.register_blueprint(namespace)

    # error handlers
    app.register_error_handler(StopIteration, lambda _: StatusResponse("not found", 404))

    app.url_map.update()
    #print('\n'.join(repr(i) for i in app.url_map._rules))

    return app
Exemplo n.º 2
0
def create_app(config_filename='config.yaml'):
    app = App(__name__)
    app.url_map.converters.update(dict(
        sid = SIDConverter,
        sha1 = SHA1Converter,
        label = LabelConverter,
        namespace = NamespaceConverter,
        handler = HandlerConverter
    ))

    load_config(app, config_filename)
    init_db(app)
    init_cache(app)
    init_cdn(app)
    init_logging(app)

    app.after_request(cors)

    app.register_blueprint(paste)
    app.register_blueprint(namespace)

    app.url_map.update()
    #print('\n'.join(repr(i) for i in app.url_map._rules))

    return app
Exemplo n.º 3
0
Arquivo: pb.py Projeto: jstoone/pb
def create_app(config_filename='config.yaml'):
    app = App(__name__)
    app.url_map.converters.update(dict(
        sid = SIDConverter,
        sha1 = SHA1Converter,
        label = LabelConverter,
        namespace = NamespaceConverter
    ))

    load_config(app, config_filename)
    init_db(app)
    init_cache(app)

    app.after_request(cors)

    app.register_blueprint(paste)
    app.register_blueprint(namespace)

    app.url_map.update()
    #print('\n'.join(repr(i) for i in app.url_map._rules))

    return app
Exemplo n.º 4
0
    ~~~~~~~~~~

    run this once to create indexes for paste document fields
    this can create users and butter your toast for you as well

    :copyright: Copyright (C) 2015 by the respective authors; see AUTHORS.
    :license: GPLv3, see LICENSE for details.
"""

from urllib import parse
from pymongo import MongoClient
import pymongo

from pb.config import load_config

config = load_config(None, 'config.yaml')

def add_config_user(db):
    up = parse.urlparse(config['MONGO']['host'])

    auth = [getattr(up, k) for k in ['username', 'password']]

    db.client.admin.add_user(*auth, roles=[{'role': 'readWrite', 'db': config['MONGO_DATABASE']}])

def add_indexes(db):
    db.pastes.create_index('digest', unique=True)
    db.pastes.create_index('date')
    db.pastes.create_index('label', unique=True, sparse=True)
    db.pastes.create_index(
        [('label', pymongo.ASCENDING),
         ('namespace', pymongo.ASCENDING)], unique=True, sparse=True)