Ejemplo n.º 1
0
def includeme(config):
    app = Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.

    # Set up the models
    settings = config.get_settings()
    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    with app.test_request_context():
        Annotation.create_all()
        Document.create_all()

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)

    # Configure the API views -- version 1 is just an annotator.store proxy
    api_v1 = wsgiapp2(app)

    config.add_view(api_v1, route_name='api')

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
Ejemplo n.º 2
0
Archivo: store.py Proyecto: shepazu/h
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """

    app = flask.Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.
    settings = config.get_settings()

    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    try:
        with app.test_request_context():
            Annotation.create_all()
            Document.create_all()
    except socket.error:
        raise Exception(
            "Can not access ElasticSearch at %s! Are you sure it's running?" %
            (app.config["ELASTICSEARCH_HOST"], ))
    except:
        with app.test_request_context():
            Annotation.update_settings()
            Annotation.create_all()
            Document.create_all()

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_config = {'static': True}
    api_endpoint = config.registry.settings.get('api.endpoint', None)
    api_url = config.registry.settings.get('api.url', api_endpoint)

    if api_endpoint is not None:
        api_path = api_endpoint.rstrip('/')
        api_pattern = '/'.join([api_path, '*subpath'])

        # Configure the API views -- version 1 is just an annotator.store proxy
        api_v1 = wsgiapp2(app)

        config.add_route('api_real', api_pattern)
        config.add_view(api_v1, route_name='api_real')
        config.add_view(api_v1, name='api_virtual')

    if api_url is not None:
        api_url = api_url.strip('/')
        if urlparse.urlparse(api_url).scheme:

            def set_app_url(request, elements, kw):
                kw.setdefault('_app_url', api_url)
                return (elements, kw)

            api_config['pregenerator'] = set_app_url
            config.add_route('api', '/*subpath', **api_config)
        else:
            config.add_route('api', api_url + '/*subpath', **api_config)

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
Ejemplo n.º 3
0
Archivo: store.py Proyecto: mrienstra/h
def includeme(config):
    """Include the annotator-store API backend via http or route embedding.

    Example INI file:
    .. code-block:: ini
        [app:h]
        api.key: 00000000-0000-0000-0000-000000000000
        api.endpoint: https://example.com/api

    or use a relative path for the endpoint to embed the annotation store
    directly in the application.
    .. code-block:: ini
        [app:h]
        api.endpoint: /api

    The default is to embed the store as a route bound to "/api".
    """

    app = flask.Flask('annotator')  # Create the annotator-store app
    app.register_blueprint(store.store)  # and register the store api.
    settings = config.get_settings()

    if 'es.host' in settings:
        app.config['ELASTICSEARCH_HOST'] = settings['es.host']
    if 'es.index' in settings:
        app.config['ELASTICSEARCH_INDEX'] = settings['es.index']
    es.init_app(app)
    try:
        with app.test_request_context():
            Annotation.create_all()
            Document.create_all()
    except socket.error:
        raise Exception(
            "Can not access ElasticSearch at %s! Are you sure it's running?" %
            (app.config["ELASTICSEARCH_HOST"],)
        )

    # Configure authentication and authorization
    app.config['AUTHZ_ON'] = True
    app.before_request(before_request)
    app.after_request(after_request)

    # Configure the API routes
    api_config = {'static': True}
    api_endpoint = config.registry.settings.get('api.endpoint', None)
    api_url = config.registry.settings.get('api.url', api_endpoint)

    if api_endpoint is not None:
        api_path = api_endpoint.rstrip('/')
        api_pattern = '/'.join([api_path, '*subpath'])

        # Configure the API views -- version 1 is just an annotator.store proxy
        api_v1 = wsgiapp2(app)

        config.add_route('api_real', api_pattern)
        config.add_view(api_v1, route_name='api_real')
        config.add_view(api_v1, name='api_virtual')

    if api_url is not None:
        api_url = api_url.strip('/')
        if urlparse.urlparse(api_url).scheme:
            def set_app_url(request, elements, kw):
                kw.setdefault('_app_url', api_url)
                return (elements, kw)
            api_config['pregenerator'] = set_app_url
            config.add_route('api', '/*subpath', **api_config)
        else:
            config.add_route('api', api_url + '/*subpath', **api_config)

    if not config.registry.queryUtility(interfaces.IStoreClass):
        config.registry.registerUtility(Store, interfaces.IStoreClass)
Ejemplo n.º 4
0
def create_indices(app):
    from .model import Annotation
    from annotator.document import Document
    with app.test_request_context():
        Annotation.create_all()
        Document.create_all()
Ejemplo n.º 5
0
def create_indices(app):
    from .model import Annotation
    from annotator.document import Document
    with app.test_request_context():
        Annotation.create_all()
        Document.create_all()