示例#1
0
def create_app():
    """
    Create the application and return it to the user

    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    # Load config and logging
    Consul(app)  # load_config expects consul to be registered
    load_config(app)
    logging.config.dictConfig(
        app.config['SAMPLE_APPLICATION_LOGGING']
    )

    # Register extensions
    api = Api(app)
    Discoverer(app)
    db.init_app(app)

    api.add_resource(UnixTime, '/time')
    api.add_resource(PrintArg, '/print/<string:arg>')
    api.add_resource(ExampleApiUsage, '/search')

    return app
示例#2
0
文件: app.py 项目: ehenneken/test_app
def create_app():
    """
    Create the application and return it to the user
    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    Consul(app)

    load_config(app)

    logging.config.dictConfig(
        app.config['OBJECTS_LOGGING']
    )

    app.cache = Cache(app) 

    api = Api(app)
    api.add_resource(ObjectSearch, '/', '/<string:objects>', '/<string:objects>/<string:source>')
    api.add_resource(PositionSearch, '/pos/<string:pstring>')
    api.add_resource(QuerySearch, '/query')

    discoverer = Discoverer(app)

    return app
    def create_app(self):
        
        class DefaultView(MethodView):
            '''Default route docstring'''
            def put(self):
                return "put on default route"
            def post(self):
                return "post on default route"
        
        class ScopedView(MethodView):
            '''Scoped route docstring'''
            scopes = ['default']
            decorators = [advertise('scopes')]
            def get(self):
                return "scoped route"

        app = Flask(__name__,static_folder=None)
        app.add_url_rule('/default',view_func=DefaultView.as_view('default'))
        app.add_url_rule('/scoped',view_func=ScopedView.as_view('scoped'))
        discoverer = Discoverer(app)

        self.expected_resources = {
            '/scoped': {
                'scopes':['default'],
                'description': 'Scoped route docstring',
                'methods': ['HEAD','OPTIONS','GET'],
            },
            '/default': {
                'description': 'Default route docstring',
                'methods': ['PUT','POST','OPTIONS'],
            },
        }
        return app
示例#4
0
def create_app(**config):

    app = ADSFlask(__name__, static_folder=None, local_config=config or {})

    app.url_map.strict_slashes = False
    
    ## pysqlite driver breaks transactions, we have to apply some hacks as per
    ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable
    if 'sqlite' in app.config.get('SQLALCHEMY_DATABASE_URI', None):
        from sqlalchemy import event
        engine = app.db.engine
        
        @event.listens_for(engine, "connect")
        def do_connect(dbapi_connection, connection_record):
            # disable pysqlite's emitting of the BEGIN statement entirely.
            # also stops it from emitting COMMIT before any DDL.
            dbapi_connection.isolation_level = None

        @event.listens_for(engine, "begin")
        def do_begin(conn):
            # emit our own BEGIN
            conn.execute("BEGIN")
    
    app.register_blueprint(bp)

    discoverer = Discoverer(app)

    return app
    def create_app(self):
        app = Flask(__name__,static_folder=None)
        
        @app.route('/default',methods=['POST','PUT'])
        def default():
            '''Default route docstring'''
            return "default route"

        @advertise(scopes=['default'])
        @app.route('/scoped')
        def scoped():
            '''Scoped route docstring'''
            return "scoped route"

        self.expected_resources = {
            '/scoped': {
                'scopes':['default'],
                'description': 'Scoped route docstring',
                'methods': ['HEAD','OPTIONS','GET'],
            },
            '/default': {
                'description': 'Default route docstring',
                'methods': ['PUT','POST','OPTIONS'],
            },
        }
        discoverer = Discoverer(app)
        return app
    def create_app(self):
        from flask.ext.restful import Resource, Api 
        app = Flask(__name__,static_folder=None)
        
        class DefaultView(Resource):
            '''Default route docstring'''
            def put(self):
                return "put on default route"
            def post(self):
                return "post on default route"
        
        class ScopedView(Resource):
            '''Scoped route docstring'''
            scopes = ['default']
            decorators = [advertise('scopes')]
            def get(self):
                return "scoped route"
        
        self.expected_resources = {
            '/scoped': {
                'scopes':['default'],
                'description': 'Scoped route docstring',
                'methods': ['HEAD','OPTIONS','GET'],
            },
            '/default': {
                'description': 'Default route docstring',
                'methods': ['PUT','POST','OPTIONS'],
            },
        }

        api = Api(app)
        api.add_resource(DefaultView,'/default')
        api.add_resource(ScopedView,'/scoped')
        discoverer = Discoverer(app)
        return app
示例#7
0
def create_app():
    """
    Create the application and return it to the user
    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    Consul(app)

    load_config(app)

    logging.config.dictConfig(
        app.config['GRAPHICS_LOGGING']
    )

    api = Api(app)
    api.add_resource(Graphics, '/<string:bibcode>')

    db.init_app(app)

    Discoverer(app)

    return app
 def test_resource_publish_endpoint1(self):
     discoverer = Discoverer(
         self.app, DISCOVERER_PUBLISH_ENDPOINT='/non-default-resources')
     self.assertEqual(self.app.config['DISCOVERER_PUBLISH_ENDPOINT'],
                      '/non-default-resources')
     r = self.client.get('/resources')
     self.assertStatus(r, 404)
     r = self.client.get('/non-default-resources')
     self.assertStatus(r, 200)
     self.assertIn('/foo', r.json)
示例#9
0
def create_app(config_type='PRODUCTION'):
    """
    Create the application and return it to the user
    :param config_type: specifies which configuration file to load. Options are
    TEST, LOCAL, and PRODUCTION.

    :return: application
    """

    app = Flask(__name__, static_folder=None)

    app.url_map.strict_slashes = False

    config_dictionary = dict(
        TEST='test_config.py',
        LOCAL='local_config.py',
        PRODUCTION='config.py'
    )

    app.config.from_pyfile(config_dictionary['PRODUCTION'])

    if config_type in config_dictionary.keys():
        try:
            app.config.from_pyfile(config_dictionary[config_type])
        except IOError:
            app.logger.warning('Could not find specified config file: {0}'
                               .format(config_dictionary[config_type]))
            raise

    # Initiate the blueprint
    api = Api(app)

    # Add the end resource end points
    api.add_resource(UserView,
                     '/users/<int:user>/libraries/',
                     methods=['GET', 'POST'])

    api.add_resource(LibraryView,
                     '/users/<int:user>/libraries/<int:library>',
                     methods=['GET', 'POST', 'DELETE'])

    # Initiate the database from the SQL Alchemy model
    db.init_app(app)

    # Add logging
    handler = setup_logging_handler(level='DEBUG')
    app.logger.addHandler(handler)

    discoverer = Discoverer(app)
    return app
示例#10
0
def create_app():
    """
    Create the application and return it to the user
    :return: application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    # Load config and logging
    Consul(app)  # load_config expects consul to be registered
    load_config(app)
    logging.config.dictConfig(
        app.config['HARBOUR_LOGGING']
    )

    load_s3(app)

    # Register extensions
    watchman = Watchman(app, version=dict(scopes=['']))
    api = Api(app)
    Discoverer(app)
    db.init_app(app)

    # Add the end resource end points
    api.add_resource(AuthenticateUserClassic, '/auth/classic', methods=['POST'])
    api.add_resource(AuthenticateUserTwoPointOh, '/auth/twopointoh', methods=['POST'])

    api.add_resource(
        ClassicLibraries,
        '/libraries/classic/<int:uid>',
        methods=['GET']
    )
    api.add_resource(
        TwoPointOhLibraries,
        '/libraries/twopointoh/<int:uid>',
        methods=['GET']
    )

    api.add_resource(
        ExportTwoPointOhLibraries,
        '/export/twopointoh/<export>',
        methods=['GET']
    )

    api.add_resource(ClassicUser, '/user', methods=['GET'])
    api.add_resource(AllowedMirrors, '/mirrors', methods=['GET'])

    return app
示例#11
0
def create_app():
    """Application factory"""

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    Consul(app)  # load_config expects consul to be registered
    load_config(app)

    Discoverer(app)
    api = Api(app)
    api.add_resource(WordCloud, '/word-cloud')
    api.add_resource(AuthorNetwork, '/author-network')
    api.add_resource(PaperNetwork, '/paper-network')
    return app
示例#12
0
def create_app():
    """
    Create the application and return it to the user
    :return: application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    # Load config and logging
    Consul(app)  # load_config expects consul to be registered
    load_config(app)
    logging.config.dictConfig(app.config['BIBLIB_LOGGING'])

    # Register extensions
    api = Api(app)
    Discoverer(app)
    db.init_app(app)

    # Add the end resource end points
    api.add_resource(UserView, '/libraries', methods=['GET', 'POST'])

    api.add_resource(LibraryView,
                     '/libraries/<string:library>',
                     methods=['GET'])

    api.add_resource(DocumentView,
                     '/documents/<string:library>',
                     methods=['POST', 'DELETE', 'PUT'])

    api.add_resource(PermissionView,
                     '/permissions/<string:library>',
                     methods=['GET', 'POST'])

    api.add_resource(TransferView,
                     '/transfer/<string:library>',
                     methods=['POST'])

    api.add_resource(ClassicView, '/classic', methods=['GET'])

    api.add_resource(TwoPointOhView, '/twopointoh', methods=['GET'])

    return app
示例#13
0
def create_app():
    """
    Application factory
    :return configured flask.Flask application instance
    """
    app = Flask(__name__, static_folder=None)

    app.url_map.strict_slashes = False
    Consul(app)  # load_config expects consul to be registered
    load_config(app)
    logging.config.dictConfig(app.config['SOLR_SERVICE_LOGGING'])

    api = Api(app)

    @api.representation('application/json')
    def json(data, code, headers):
        """
        Since we force SOLR to always return JSON, it is faster to
        return JSON as text string directly, without parsing and serializing
        it multiple times
        """
        if not isinstance(data, basestring):
            resp = jsonify(data)
            resp.status_code = code
        else:
            resp = make_response(data, code)
        resp.headers['Content-Type'] = 'application/json'
        resp.headers['Server'] = 'Solr Microservice {v}'.format(
            v=app.config.get('SOLR_SERVICE_VERSION'))
        if code == 200:
            resp.headers['Cache-Control'] = app.config.get(
                'SOLR_CACHE_CONTROL', "public, max-age=600")
        return resp

    api.add_resource(StatusView, '/status')
    api.add_resource(Tvrh, '/tvrh')
    api.add_resource(Search, '/query')
    api.add_resource(Qtree, '/qtree')
    api.add_resource(BigQuery, '/bigquery')

    Discoverer(app)
    return app
示例#14
0
def create_app():
    """
    Create the application and return it to the user
    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    load_config(app)

    logging.config.dictConfig(app.config['INSTITUTE_LOGGING'])

    api = Api(app)

    db.init_app(app)

    discoverer = Discoverer(app)

    return app
示例#15
0
def create_app():
    """
    Create the application and return it to the user
    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    Consul(app)

    load_config(app)

    api = Api(app)
    api.add_resource(Metrics, '/')
    api.add_resource(PubMetrics, '/<string:bibcode>')

    db.init_app(app)

    discoverer = Discoverer(app)

    return app
示例#16
0
def create_app(config=None):
    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    Discoverer(app)
    Consul(app)  # load_config expects consul to be registered
    load_config(app, config)
    db.init_app(app)
    logging.config.dictConfig(
        app.config['ORCID_LOGGING']
    )
    
    ## pysqlite driver breaks transactions, we have to apply some hacks as per
    ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable
    
    if 'sqlite' in (app.config.get('SQLALCHEMY_BINDS') or {'orcid':''})['orcid']:
        from sqlalchemy import event
        
        binds = app.config.get('SQLALCHEMY_BINDS')
        if binds and 'orcid' in binds:
            engine = db.get_engine(app, bind=(app.config.get('SQLALCHEMY_BINDS') and 'orcid'))
        else:
            engine = db.get_engine(app)
        
        @event.listens_for(engine, "connect")
        def do_connect(dbapi_connection, connection_record):
            # disable pysqlite's emitting of the BEGIN statement entirely.
            # also stops it from emitting COMMIT before any DDL.
            dbapi_connection.isolation_level = None

        @event.listens_for(engine, "begin")
        def do_begin(conn):
            # emit our own BEGIN
            conn.execute("BEGIN")
    
    app.register_blueprint(bp)
    return app
示例#17
0
def create_app():
    """
    Create the application and return it to the user

    :return: flask.Flask application
    """

    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False

    # Load config and logging
    Consul(app)  # load_config expects consul to be registered
    load_config(app)
    logging.config.dictConfig(app.config['EXPORT_SERVICE_LOGGING'])

    # Register extensions
    api = Api(app)
    Discoverer(app)

    api.add_resource(Aastex, '/aastex')
    api.add_resource(Bibtex, '/bibtex')
    api.add_resource(Endnote, '/endnote')

    return app
示例#18
0
文件: app.py 项目: romanchyla/myads
def create_app(**config):
    
    opath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if opath not in sys.path:
        sys.path.insert(0, opath)
    
    app = Flask(__name__, static_folder=None)
    app.url_map.strict_slashes = False
    
    
    app.config.from_pyfile('config.py')
    
    # Load config from Consul
    Consul(app)  # load_config expects consul to be registered
    try:
        app.extensions['consul'].apply_remote_config()
    except ConsulConnectionError as error:
        app.logger.warning('Could not apply config from consul: {}'
                           .format(error))
    
    # and finally from the local_config.py
    try:
      app.config.from_pyfile('local_config.py')
    except IOError:
      pass
  
    if config:
        app.config.update(config)
    
    db.init_app(app)
    
    ## pysqlite driver breaks transactions, we have to apply some hacks as per
    ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable
    
    if 'sqlite' in (app.config.get('SQLALCHEMY_BINDS') or {'myads':''})['myads']:
        from sqlalchemy import event
        
        binds = app.config.get('SQLALCHEMY_BINDS')
        if binds and 'myads' in binds:
            engine = db.get_engine(app, bind=(app.config.get('SQLALCHEMY_BINDS') and 'myads'))
        else:
            engine = db.get_engine(app)
        
        @event.listens_for(engine, "connect")
        def do_connect(dbapi_connection, connection_record):
            # disable pysqlite's emitting of the BEGIN statement entirely.
            # also stops it from emitting COMMIT before any DDL.
            dbapi_connection.isolation_level = None

        @event.listens_for(engine, "begin")
        def do_begin(conn):
            # emit our own BEGIN
            conn.execute("BEGIN")
        
    
    # Note about imports being here rather than at the top level
    # I want to enclose the import into the scope of the create_app()
    # and not advertise any of the views
    from myads_service import views
    for o in inspect.getmembers(views, predicate=lambda x: inspect.ismodule(x)):
        for blueprint in inspect.getmembers(o[1], predicate=lambda x: isinstance(x, Blueprint)):
            app.register_blueprint(blueprint[1])

    discoverer = Discoverer(app)        
    return app
示例#19
0
def create_app(**config):
    """
    Application factory
    :return configured flask.Flask application instance
    """
    if config:
        app = ADSFlask(__name__, static_folder=None, local_config=config)
    else:
        app = ADSFlask(__name__, static_folder=None)

    app.url_map.strict_slashes = False

    ## pysqlite driver breaks transactions, we have to apply some hacks as per
    ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable

    if 'sqlite' in app.config.get('SQLALCHEMY_DATABASE_URI', None):
        from sqlalchemy import event
        engine = app.db.engine

        @event.listens_for(engine, "connect")
        def do_connect(dbapi_connection, connection_record):
            # disable pysqlite's emitting of the BEGIN statement entirely.
            # also stops it from emitting COMMIT before any DDL.
            dbapi_connection.isolation_level = None

        @event.listens_for(engine, "begin")
        def do_begin(conn):
            # emit our own BEGIN
            conn.execute("BEGIN")

    api = Api(app)

    @api.representation('application/json')
    def json(data, code, headers):
        """
        Since we force SOLR to always return JSON, it is faster to
        return JSON as text string directly, without parsing and serializing
        it multiple times
        """
        if not isinstance(data, basestring):
            resp = jsonify(data)
            resp.status_code = code
        else:
            resp = make_response(data, code)
        resp.headers['Content-Type'] = 'application/json'
        resp.headers['Server'] = 'Solr Microservice {v}'.format(
            v=app.config.get('SOLR_SERVICE_VERSION'))
        if code == 200:
            resp.headers['Cache-Control'] = app.config.get(
                'SOLR_CACHE_CONTROL', "public, max-age=600")
        if 'Set-Cookie' in headers:
            resp.headers['Set-Cookie'] = headers['Set-Cookie']
        return resp

    api.add_resource(StatusView, '/status')
    api.add_resource(Tvrh, '/tvrh')
    api.add_resource(Search, '/query')
    api.add_resource(Qtree, '/qtree')
    api.add_resource(BigQuery, '/bigquery')

    Discoverer(app)
    return app
 def test_selfpublish_false(self):
     discoverer = Discoverer(self.app, DISCOVERER_SELF_PUBLISH=False)
     r = self.client.get(self.app.config['DISCOVERER_PUBLISH_ENDPOINT'])
     self.assertStatus(r, 200)
     self.assertNotIn(self.app.config['DISCOVERER_PUBLISH_ENDPOINT'],
                      r.json)