def includeme(config): """Include the annotator-store API backend. Example INI file: [app:h] consumer_key: primary_consumer consumer_secret: 00000000-0000-0000-0000-000000000000 """ settings = config.get_settings() if not settings.has_key('h.consumer_key'): raise KeyError('h.consumer_key') if not settings.has_key('h.consumer_secret'): raise KeyError('h.consumer_secret') # Create the annotator-store app app = Flask(__name__) app.register_blueprint(store.store) # Set up the models es.init_app(app) with app.test_request_context(): try: Annotation.create_all() except: Annotation.update_settings() Annotation.create_all() # Configure authentication (ours) and authorization (store) authenticator = auth.Authenticator(consumer_fetcher) def before_request(): g.auth = authenticator g.authorize = authz.authorize app.before_request(before_request) # Configure the API views config.add_view(wsgiapp2(app), route_name='api') config.add_view(token, route_name='token', permission='authenticated') config.add_view(users, route_name='users', request_method='GET', permission='authenticated', renderer='json')
def includeme(config): """Include the annotator-store API backend. Example INI file: [app:h] api.key: 00000000-0000-0000-0000-000000000000 """ 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(): try: Annotation.create_all() except: Annotation.update_settings() Annotation.create_all() # Configure authentication (ours) and authorization (store) authenticator = auth.Authenticator(models.Consumer.get_by_key) def before_request(): g.auth = authenticator g.authorize = authz.authorize app.before_request(before_request) # Configure the API view -- version 1 is just an annotator.store proxy config.add_view(wsgiapp2(app), context='h.resources.APIFactory', name='v1') config.add_view(wsgiapp2(app), context='h.resources.APIFactory', name='current') # And pick up the token view config.scan(__name__)
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)
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)