예제 #1
0
from werkzeug.exceptions import abort
from flask import current_app

from cmdb.framework.cmdb_errors import ObjectManagerGetError
from cmdb.framework.cmdb_log import CmdbObjectLog, LogAction
from cmdb.framework.cmdb_log_manager import LogManagerGetError, LogManagerDeleteError
from cmdb.interface.route_utils import RootBlueprint, make_response, login_required, right_required, insert_request_user
from cmdb.user_management import User

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
log_blueprint = RootBlueprint('log_rest', __name__, url_prefix='/log')

with current_app.app_context():
    object_manager = current_app.object_manager
    log_manager = current_app.log_manager


# CRUD routes
@log_blueprint.route('/<int:public_id>/', methods=['GET'])
@log_blueprint.route('/<int:public_id>', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.log.view')
def get_log(public_id: int, request_user: User):
    try:
        selected_log = log_manager.get_log(public_id=public_id)
예제 #2
0
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import logging

from flask import current_app

from cmdb.interface.route_utils import RootBlueprint, make_response
from cmdb.data_storage.database_manager import DatabaseManagerMongo

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

connection_routes = RootBlueprint('connection_routes', __name__)
LOGGER = logging.getLogger(__name__)

with current_app.app_context():
    database_manager: DatabaseManagerMongo = current_app.database_manager


@connection_routes.route('/')
def connection_response():
    from cmdb import __title__, __version__
    resp = {
        'title': __title__,
        'version': __version__,
        'connected': database_manager.status()
    }
    return make_response(resp)
예제 #3
0
from flask import current_app

from cmdb.interface.route_utils import make_response, RootBlueprint, login_required
from cmdb.user_management import UserManager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

with current_app.app_context():
    user_manager: UserManager = current_app.user_manager

LOGGER = logging.getLogger(__name__)
right_blueprint = RootBlueprint('right_rest', __name__, url_prefix='/right')


@right_blueprint.route('/', methods=['GET'])
@login_required
def get_all_rights():
    right_list = user_manager.get_all_rights()
    resp = make_response(right_list)
    return resp


@right_blueprint.route('/tree', methods=['GET'])
@login_required
def get_right_tree():
    right_tree = user_manager.get_right_tree()
    resp = make_response(right_tree)
예제 #4
0
    right_required
from cmdb.user_management import User
from cmdb.user_management.user_group import UserGroup
from cmdb.user_management.user_manager import UserManager, UserManagerInsertError, UserManagerGetError, \
    UserManagerUpdateError, UserManagerDeleteError

with current_app.app_context():
    user_manager: UserManager = current_app.user_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
group_blueprint = RootBlueprint('group_rest', __name__, url_prefix='/group')


@group_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.user-management.group.view')
def get_all_groups(request_user: User):
    try:
        group_list = user_manager.get_groups()
    except UserManagerGetError as err:
        LOGGER.error(err)
        return abort(404)
    if len(group_list) < 1:
        return make_response(group_list, 204)
    return make_response(group_list)
예제 #5
0
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.search.query.query_builder import QueryBuilder
from cmdb.user_management import User
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required, insert_request_user, right_required
from cmdb.framework.cmdb_errors import TypeNotFoundError, TypeInsertError, ObjectDeleteError, ObjectManagerGetError, \
    ObjectManagerInitError
from cmdb.framework.cmdb_type import CmdbType

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
type_blueprint = RootBlueprint('type_blueprint', __name__, url_prefix='/type')

with current_app.app_context():
    object_manager: CmdbObjectManager = current_app.object_manager


@type_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.type.view')
def get_types(request_user: User):
    """Get all types as a list"""
    try:
        type_list = object_manager.get_all_types()
    except (ObjectManagerInitError, ObjectManagerGetError) as err:
        return abort(500, err.message)
예제 #6
0
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import logging
from flask import current_app
from cmdb.interface.route_utils import RootBlueprint, login_required, insert_request_user, make_response, right_required
from cmdb.user_management import User
from cmdb.utils.system_reader import SystemSettingsReader

LOGGER = logging.getLogger(__name__)
try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

settings_blueprint = RootBlueprint('settings_rest',
                                   __name__,
                                   url_prefix='/settings')

with current_app.app_context():
    from cmdb.interface.rest_api.settings_routes.system_routes import system_blueprint

    settings_blueprint.register_nested_blueprint(system_blueprint)

    system_settings_reader = SystemSettingsReader(
        database_manager=current_app.database_manager)


@settings_blueprint.route('/<string:section>/', methods=['GET'])
@settings_blueprint.route('/<string:section>', methods=['GET'])
@login_required
@insert_request_user
예제 #7
0
import logging

from flask import abort, jsonify
from cmdb.framework.cmdb_errors import TypeNotFoundError
from cmdb.file_export.file_exporter import FileExporter
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required
from cmdb.utils.helpers import load_class

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
file_blueprint = RootBlueprint('file_rest', __name__, url_prefix='/file')


@file_blueprint.route('/', methods=['GET'])
@login_required
def get_filetypes():
    filetypes = FileExporter.get_filetypes()
    filetype_list = []
    for filetype in filetypes:
        filetype_class = load_class('cmdb.file_export.export_types.' + filetype)
        filetype_properties = {
                'id': filetype,
                'label': filetype_class.LABEL,
                'icon': filetype_class.ICON,
                'multiTypeSupport': filetype_class.MULTITYPE_SUPPORT,
                'helperText': filetype_class.DESCRIPTION,
예제 #8
0
from flask import abort, request, current_app
from datetime import datetime

from cmdb.interface.route_utils import RootBlueprint, make_response, insert_request_user, login_required, right_required
from cmdb.user_management import User
from cmdb.user_management.user_manager import UserManagerInsertError, UserManagerGetError, \
    UserManagerUpdateError, UserManagerDeleteError, UserManager
from cmdb.utils.security import SecurityManager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
user_blueprint = RootBlueprint('user_rest', __name__, url_prefix='/user')

with current_app.app_context():
    user_manager: UserManager = current_app.user_manager
    security_manager: SecurityManager = current_app.security_manager


@user_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.user-management.user.*')
def get_users(request_user: User):
    try:
        users: List[User] = user_manager.get_users()
    except CMDBError:
        return abort(404)
예제 #9
0
from bson import json_util

from cmdb.framework.cmdb_errors import ObjectManagerGetError, ObjectManagerInsertError, ObjectManagerUpdateError
from cmdb.framework.cmdb_status import CmdbStatus
from cmdb.interface.route_utils import RootBlueprint, make_response

with current_app.app_context():
    object_manager = current_app.object_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
status_blueprint = RootBlueprint('status_rest', __name__, url_prefix='/status')


@status_blueprint.route('/', methods=['GET'])
def get_statuses():
    try:
        status = object_manager.get_statuses()
    except ObjectManagerGetError:
        return abort(404)
    if len(status) < 1:
        return make_response(status, 204)
    return make_response(status)


@status_blueprint.route('/<int:public_id>/', methods=['GET'])
@status_blueprint.route('/<int:public_id>', methods=['GET'])
예제 #10
0
from cmdb.user_management import User
from cmdb.interface.rest_api.media_library_routes.media_file_route_utils import get_element_from_data_request, \
    get_file_in_request, generate_metadata_filter


with current_app.app_context():
    media_file_manager = current_app.media_file_manager
    log_manager = current_app.exportd_log_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
media_file_blueprint = RootBlueprint('media_file_blueprint', __name__, url_prefix='/media_file')

# DEFAULT ROUTES


@media_file_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.object.view')
def get_object_list(request_user: User):
    """
    get all objects in database

    Returns:
        list of media_files
    """
예제 #11
0
from cmdb.exportd.exportd_job.exportd_job import ExportdJob, ExecuteState
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required, insert_request_user, right_required
from cmdb.framework.cmdb_errors import ObjectManagerGetError
from cmdb.user_management import User

with current_app.app_context():
    exportd_manager = current_app.exportd_manager
    log_manager = current_app.exportd_log_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
exportd_job_blueprint = RootBlueprint('exportd_job_blueprint', __name__, url_prefix='/exportdjob')


# DEFAULT ROUTES
@exportd_job_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.exportd.job.view')
def get_exportd_job_list(request_user: User):
    """
    get all objects in database
    Returns:
        list of exportd jobs
    """
    try:
        job_list = exportd_manager.get_all_jobs()
예제 #12
0
from cmdb.search.query import Query, Pipeline
from cmdb.search.query.pipe_builder import PipelineBuilder
from cmdb.search.query.query_builder import QueryBuilder
from cmdb.search.searchers import SearcherFramework
from cmdb.user_management.user import User

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

with current_app.app_context():
    object_manager: CmdbObjectManager = current_app.object_manager

LOGGER = logging.getLogger(__name__)
search_blueprint = RootBlueprint('search_rest', __name__, url_prefix='/search')


@search_blueprint.route('/quick/count', methods=['GET'])
@search_blueprint.route('/quick/count/', methods=['GET'])
@login_required
@insert_request_user
def quick_search_result_counter(request_user: User):
    regex = request.args.get('searchValue', Search.DEFAULT_REGEX, str)
    plb = PipelineBuilder()
    regex = plb.regex_('fields.value', f'{regex}', 'ims')
    pipe_match = plb.match_(regex)
    plb.add_pipe(pipe_match)
    pipe_count = plb.count_('count')
    plb.add_pipe(pipe_count)
    pipeline = plb.pipeline
예제 #13
0
from flask import abort, jsonify, current_app, Response
from cmdb.interface.route_utils import RootBlueprint, login_required
from cmdb.framework.cmdb_errors import TypeNotFoundError
from cmdb.utils import json_encoding

with current_app.app_context():
    object_manager = current_app.object_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
type_export_blueprint = RootBlueprint('type_export_rest',
                                      __name__,
                                      url_prefix='/export/type')


@type_export_blueprint.route('/', methods=['POST'])
# @login_required
def export_type():
    try:
        type_list = object_manager.get_all_types()
        resp = json.dumps(type_list, default=json_encoding.default, indent=2)
    except TypeNotFoundError as e:
        return abort(400, e.message)
    except ModuleNotFoundError as e:
        return abort(400, e)
    except CMDBError as e:
        return abort(404, jsonify(message='Not Found', error=e.message))
예제 #14
0
from flask import abort, jsonify, current_app
from cmdb.utils.helpers import load_class, get_module_classes
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required

with current_app.app_context():
    exportd_manager = current_app.exportd_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
external_system = RootBlueprint('external_system',
                                __name__,
                                url_prefix='/externalsystem')


# DEFAULT ROUTES
@external_system.route('/', methods=['GET'])
@login_required
def get_external_system_list():
    return make_response(
        get_module_classes('cmdb.exportd.externals.external_systems'))


@external_system.route('/parameters/<string:class_external_system>',
                       methods=['GET'])
# @login_required
def get_external_system_params(class_external_system):
예제 #15
0
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.interface.route_utils import RootBlueprint, make_response, NestedBlueprint, login_required, \
    insert_request_user, right_required
from cmdb.user_management import User

with current_app.app_context():
    object_manager: CmdbObjectManager = current_app.object_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
collection_blueprint = RootBlueprint('collection_rest',
                                     __name__,
                                     url_prefix='/collection')
collection_template_routes = NestedBlueprint(collection_blueprint,
                                             url_prefix='/template')
collection_blueprint.register_nested_blueprint(collection_template_routes)


@collection_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.collection.view')
def get_collections(request_user: User):
    """Get all collections
    Returns:
        list of all collections
    """
예제 #16
0
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required, insert_request_user, right_required
from cmdb.security.auth import AuthModule, AuthSettingsDAO
from cmdb.security.auth.auth_errors import AuthenticationProviderNotExistsError, \
    AuthenticationProviderNotActivated
from cmdb.security.token.generator import TokenGenerator
from cmdb.user_management import User
from cmdb.user_management.user_manager import UserManager
from cmdb.utils.system_reader import SystemSettingsReader
from cmdb.utils.system_writer import SystemSettingsWriter

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

auth_blueprint = RootBlueprint('auth_rest', __name__, url_prefix='/auth')
LOGGER = logging.getLogger(__name__)

with current_app.app_context():
    user_manager: UserManager = current_app.user_manager
    system_settings_reader: SystemSettingsReader = SystemSettingsReader(
        current_app.database_manager)
    system_setting_writer: SystemSettingsWriter = SystemSettingsWriter(
        current_app.database_manager)


@auth_blueprint.route('/settings/', methods=['GET'])
@auth_blueprint.route('/settings', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.system.view')
예제 #17
0
from cmdb.framework.cmdb_render import CmdbRender, RenderList, RenderError
from cmdb.interface.route_utils import make_response, RootBlueprint, insert_request_user, login_required, right_required
from cmdb.user_management import User

with current_app.app_context():
    object_manager = current_app.object_manager
    log_manager = current_app.log_manager
    user_manager = current_app.user_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
object_blueprint = RootBlueprint('object_blueprint', __name__, url_prefix='/object')
with current_app.app_context():
    from cmdb.interface.rest_api.framework_routes.object_link_routes import link_rest

    object_blueprint.register_nested_blueprint(link_rest)


# DEFAULT ROUTES

@object_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.object.view')
def get_object_list(request_user: User):
    """
    get all objects in database
예제 #18
0
# DATAGERRY - OpenSource Enterprise CMDB
# Copyright (C) 2019 NETHINKS GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
"""
Blueprint for documentation routes
"""

from cmdb.interface.route_utils import RootBlueprint

doc_pages = RootBlueprint("doc_pages",
                          __name__,
                          static_folder="static",
                          static_url_path="")


@doc_pages.route("/")
def default_page():
    return doc_pages.send_static_file("index.html")
예제 #19
0
from cmdb.docapi.docapi_template.docapi_template import DocapiTemplate, DocapiTemplateType
from cmdb.docapi.docapi_template.docapi_template_manager import DocapiTemplateManagerGetError, \
    DocapiTemplateManagerInsertError, DocapiTemplateManagerUpdateError, DocapiTemplateManagerDeleteError
from cmdb.user_management import User

with current_app.app_context():
    docapi_tpl_manager = current_app.docapi_tpl_manager
    object_manager = current_app.object_manager

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
docapi_blueprint = RootBlueprint('docapi', __name__, url_prefix='/docapi')


# DEFAULT ROUTES
@docapi_blueprint.route('/template', methods=['GET'])
@docapi_blueprint.route('/template/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.docapi.template.view')
def get_template_list(request_user: User):
    """
    get all objects in database
    Returns:
        list of docapi templates
    """
    try:
예제 #20
0
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.interface.route_utils import make_response, RootBlueprint, login_required

from flask import request, abort, current_app

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

with current_app.app_context():
    object_manager: CmdbObjectManager = current_app.object_manager

LOGGER = logging.getLogger(__name__)
special_blueprint = RootBlueprint('special_rest',
                                  __name__,
                                  url_prefix='/special')


@special_blueprint.route('intro', methods=['GET'])
@special_blueprint.route('/intro', methods=['GET'])
@login_required
def get_intro_starter():
    try:
        steps = []
        categories_total = len(object_manager.get_all_categories())
        types_total = object_manager.count_types()
        objects_total = object_manager.count_objects()

        if _fetch_only_active_objs():
            result = []
예제 #21
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import logging

from flask import current_app
from werkzeug.exceptions import abort

from cmdb.interface.route_utils import RootBlueprint, make_response

debug_blueprint = RootBlueprint('debug_rest', __name__, url_prefix='/debug')
LOGGER = logging.getLogger(__name__)

with current_app.app_context():
    from cmdb.data_storage.database_manager import DatabaseManagerMongo
    database_manager: DatabaseManagerMongo = current_app.database_manager


@debug_blueprint.route('/indexes/<string:collection>/', methods=['GET'])
@debug_blueprint.route('/indexes/<string:collection>', methods=['GET'])
def get_index(collection: str):
    return make_response(database_manager.get_index_info(collection))


@debug_blueprint.route('/error/<int:status_code>/', methods=['GET', 'POST'])
@debug_blueprint.route('/error/<int:status_code>', methods=['GET', 'POST'])
예제 #22
0
from bson import json_util

from cmdb.search.query.query_builder import QueryBuilder
from cmdb.user_management import User

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

with current_app.app_context():
    object_manager: CmdbObjectManager = current_app.object_manager

LOGGER = logging.getLogger(__name__)
categories_blueprint = RootBlueprint('categories_rest',
                                     __name__,
                                     url_prefix='/category')


@categories_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.framework.category.view')
def get_categories(request_user: User):
    categories_list: List[CmdbCategory] = object_manager.get_all_categories()
    if len(categories_list) == 0:
        return make_response(categories_list, 204)
    return make_response(categories_list)


@categories_blueprint.route('/by/<string:regex>/', methods=['GET'])
예제 #23
0
from cmdb.framework.cmdb_errors import ObjectManagerGetError
from cmdb.framework.cmdb_log_manager import LogManagerDeleteError
from cmdb.exportd.exportd_logs.exportd_log import ExportdJobLog, LogAction


from flask import abort, current_app, jsonify
from cmdb.interface.route_utils import make_response, RootBlueprint, insert_request_user, login_required, right_required
from cmdb.user_management import User

try:
    from cmdb.utils.error import CMDBError
except ImportError:
    CMDBError = Exception

LOGGER = logging.getLogger(__name__)
exportd_log_blueprint = RootBlueprint('exportd_log_rest', __name__, url_prefix='/exportdlog')

with current_app.app_context():
    exportd_manager = current_app.exportd_manager
    log_manager = current_app.exportd_log_manager


# DEFAULT ROUTES
@exportd_log_blueprint.route('/', methods=['GET'])
@login_required
@insert_request_user
@right_required('base.exportd.log.view')
def get_log_list(request_user: User):
    """
    get all exportd logs in database
    Returns: