예제 #1
0
def create_rest_api(database_manager, event_queue):
    app = BaseCmdbApp(__name__,
                      database_manager=database_manager,
                      event_queue=event_queue)
    app.url_map.strict_slashes = True

    # Import App Extensions
    CORS(app, expose_headers=['X-API-Version', 'X-Total-Count'])

    import cmdb
    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        config.APPLICATION_ROOT = '/rest/'
        app.config.from_object(config)
    elif cmdb.__MODE__ == 'TESTING':
        config = app_config['testing']
        config.APPLICATION_ROOT = '/rest/'
        app.config.from_object(config)
    else:
        config = app_config['production']
        config.APPLICATION_ROOT = '/rest/'
        app.config.from_object(config)

    with app.app_context():
        register_converters(app)
        register_error_pages(app)
        register_blueprints(app)

    return app
예제 #2
0
def create_docs_server():
    app = BaseCmdbApp(__name__)

    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        config.APPLICATION_ROOT = '/docs/'
        app.config.from_object(config)
    else:
        config = app_config['production']
        config.APPLICATION_ROOT = '/docs/'
        app.config.from_object(config)

    app.register_blueprint(doc_pages, url_prefix="/")

    return app
예제 #3
0
def create_docs_server(event_queue):
    # Create managers
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database')
    )

    app = BaseCmdbApp(__name__, app_database)

    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        config.APPLICATION_ROOT = '/docs/'
        app.config.from_object(config)
    else:
        config = app_config['production']
        config.APPLICATION_ROOT = '/docs/'
        app.config.from_object(config)

    app.register_blueprint(doc_pages, url_prefix="/")

    return app
예제 #4
0
def create_docs_server(event_queue):
    # Create manager
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database')
    )

    app = BaseCmdbApp(__name__, app_database)

    if cmdb.__MODE__ == 'DEBUG':
        app.config.from_object(app_config['rest_development'])
        LOGGER.info('Docs starting with config mode {}'.format(app.config.get("ENV")))
    elif cmdb.__MODE__ == 'TESTING':
        app.config.from_object(app_config['testing'])
    else:
        app.config.from_object(app_config['rest'])
        LOGGER.info('Docs starting with config mode {}'.format(app.config.get("ENV")))

    app.register_blueprint(doc_pages, url_prefix="/")

    return app
예제 #5
0
def create_app():
    app = BaseCmdbApp(__name__)
    CORS(app)

    import cmdb

    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        app.config.from_object(config)
    else:
        config = app_config['production']
        app.config.from_object(config)

    # add static routes
    app.register_blueprint(app_pages, url_prefix='/')
    app.register_error_handler(404, redirect_index)

    @app.route('/favicon.ico')
    def favicon():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'favicon.ico')

    @app.route('/browserconfig.xml')
    def browser_config():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'browserconfig.xml')

    return app
예제 #6
0
def create_app(event_queue):
    # Create manager
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database'))

    app = BaseCmdbApp(__name__, app_database)
    CORS(app)
    import cmdb
    from cmdb.interface.net_app.app_routes import app_pages, redirect_index

    if cmdb.__MODE__ == 'DEBUG':
        app.config.from_object(app_config['rest_development'])
        LOGGER.info('NetAPP starting with config mode {}'.format(
            app.config.get("ENV")))
    elif cmdb.__MODE__ == 'TESTING':
        app.config.from_object(app_config['testing'])
    else:
        app.config.from_object(app_config['rest'])
        LOGGER.info('NetAPP starting with config mode {}'.format(
            app.config.get("ENV")))

    # add static routes
    app.register_blueprint(app_pages, url_prefix='/')
    app.register_error_handler(404, redirect_index)

    @app.route('/favicon.ico')
    def favicon():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'favicon.ico')

    @app.route('/browserconfig.xml')
    def browser_config():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'browserconfig.xml')

    return app
예제 #7
0
def create_app(event_queue):
    # Create managers
    from cmdb.database.managers import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database'))

    app = BaseCmdbApp(__name__, app_database)
    CORS(app)
    import cmdb
    from cmdb.interface.net_app.app_routes import app_pages, redirect_index

    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        app.config.from_object(config)
    else:
        config = app_config['production']
        app.config.from_object(config)

    # add static routes
    app.register_blueprint(app_pages, url_prefix='/')
    app.register_error_handler(404, redirect_index)

    @app.route('/favicon.ico')
    def favicon():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'favicon.ico')

    @app.route('/browserconfig.xml')
    def browser_config():
        from os import path
        from flask import send_from_directory
        return send_from_directory(path.join(app.root_path, '_static'),
                                   'browserconfig.xml')

    return app
예제 #8
0
def create_rest_api(event_queue):
    from cmdb.interface.config import app_config
    from cmdb.utils.system_config import SystemConfigReader
    system_config_reader = SystemConfigReader()

    # Create managers
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database'))
    object_manager = CmdbObjectManager(database_manager=app_database,
                                       event_queue=event_queue)

    log_manager = CmdbLogManager(database_manager=app_database)

    security_manager = SecurityManager(database_manager=app_database)

    user_manager = UserManager(database_manager=app_database)

    exportd_job_manager = ExportdJobManagement(database_manager=app_database,
                                               event_queue=event_queue)

    exportd_log_manager = ExportdLogManager(database_manager=app_database)

    media_file_manager = MediaFileManagement(database_manager=app_database)

    docapi_tpl_manager = DocapiTemplateManager(database_manager=app_database)

    # Create APP
    from cmdb.interface.cmdb_app import BaseCmdbApp

    app = BaseCmdbApp(__name__,
                      database_manager=app_database,
                      docapi_tpl_manager=docapi_tpl_manager,
                      media_file_manager=media_file_manager,
                      exportd_manager=exportd_job_manager,
                      exportd_log_manager=exportd_log_manager,
                      object_manager=object_manager,
                      log_manager=log_manager,
                      user_manager=user_manager,
                      security_manager=security_manager)

    app.url_map.strict_slashes = True

    # Import App Extensions
    from flask_cors import CORS
    CORS(app, expose_headers=['X-API-Version', 'X-Total-Count'])

    import cmdb
    if cmdb.__MODE__ == 'DEBUG':
        config = app_config['development']
        config.APPLICATION_ROOT = '/rest/'
        app.config.from_object(config)
    else:
        config = app_config['production']
        config.APPLICATION_ROOT = '/rest/'
        app.config.from_object(config)

    with app.app_context():
        register_converters(app)
        register_error_pages(app)
        register_blueprints(app)

    return app
예제 #9
0
def create_rest_api(event_queue):
    from cmdb.interface.config import app_config
    from cmdb.utils.system_config import SystemConfigReader
    system_config_reader = SystemConfigReader()

    try:
        cache_config = {
            'DEBUG':
            True,
            'CACHE_TYPE':
            system_config_reader.get_value('name', 'Cache'),
            'CACHE_REDIS_HOST':
            system_config_reader.get_value('host', 'Cache'),
            'CACHE_REDIS_PORT':
            system_config_reader.get_value('port', 'Cache'),
            'CACHE_REDIS_PASSWORD':
            system_config_reader.get_value('password', 'Cache'),
        }
    except (ImportError, CMDBError) as e:
        LOGGER.debug(e.message)
        cache_config = {'CACHE_TYPE': 'simple'}
    from flask_caching import Cache

    cache = Cache(config=cache_config)

    # Create manager
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    app_database = DatabaseManagerMongo(
        **system_config_reader.get_all_values_from_section('Database'))
    object_manager = CmdbObjectManager(database_manager=app_database,
                                       event_queue=event_queue)

    log_manager = CmdbLogManager(database_manager=app_database)

    security_manager = SecurityManager(database_manager=app_database)

    user_manager = UserManager(database_manager=app_database)

    exportd_job_manager = ExportdJobManagement(database_manager=app_database,
                                               event_queue=event_queue)

    exportd_log_manager = ExportdLogManager(database_manager=app_database)

    media_file_manager = MediaFileManagement(database_manager=app_database)

    docapi_tpl_manager = DocapiTemplateManager(database_manager=app_database)

    # Create APP
    from cmdb.interface.cmdb_app import BaseCmdbApp

    app = BaseCmdbApp(__name__,
                      database_manager=app_database,
                      docapi_tpl_manager=docapi_tpl_manager,
                      media_file_manager=media_file_manager,
                      exportd_manager=exportd_job_manager,
                      exportd_log_manager=exportd_log_manager,
                      object_manager=object_manager,
                      log_manager=log_manager,
                      user_manager=user_manager,
                      security_manager=security_manager)

    # Import App Extensions
    from flask_cors import CORS
    CORS(app)
    import cmdb
    cache.init_app(app)
    cache.clear()
    app.cache = cache

    if cmdb.__MODE__ == 'DEBUG':
        app.config.from_object(app_config['rest_development'])
        LOGGER.info('RestAPI starting with config mode {}'.format(
            app.config.get("ENV")))
    elif cmdb.__MODE__ == 'TESTING':
        app.config.from_object(app_config['testing'])
    else:
        app.config.from_object(app_config['rest'])
        LOGGER.info('RestAPI starting with config mode {}'.format(
            app.config.get("ENV")))

    with app.app_context():
        register_converters(app)
        register_error_pages(app)
        register_blueprints(app)

    return app