Esempio n. 1
0
# 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 make_response
from cmdb.interface.blueprint import RootBlueprint

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

with current_app.app_context():
    from cmdb.database.managers 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'])
Esempio n. 2
0
import logging
from flask import current_app
from cmdb.interface.route_utils import login_required, insert_request_user, make_response, right_required
from cmdb.interface.blueprint import RootBlueprint
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
Esempio n. 3
0
from cmdb.interface.route_utils import make_response, login_required, insert_request_user, right_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.framework.cmdb_errors import ObjectManagerGetError
from cmdb.manager import ManagerIterationError, ManagerGetError
from cmdb.user_management import UserModel
from cmdb.utils.error import CMDBError

with current_app.app_context():
    object_manager = CmdbObjectManager(current_app.database_manager)
    exportd_manager = ExportdJobManagement(current_app.database_manager,
                                           current_app.event_queue)
    log_manager = ExportdLogManager(current_app.database_manager)

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


# DEFAULT ROUTES
@exportd_blueprint.route('/jobs', methods=['GET', 'HEAD'])
@exportd_blueprint.protect(auth=True, right='base.exportd.job.view')
@exportd_blueprint.parse_collection_parameters()
def get_exportd_jobs(params: CollectionParameters):
    """Iterate route for exportd jobs"""

    job_manager = ExportDJobManager(current_app.database_manager)
    body = request.method == 'HEAD'

    try:
        iteration_result: IterationResult[ExportdJob] = job_manager.iterate(
Esempio n. 4
0
from cmdb.exportd.managers.exportd_log_manager import ExportDLogManager
from cmdb.framework.cmdb_errors import ObjectManagerGetError
from cmdb.framework.managers.log_manager import LogManagerDeleteError
from cmdb.exportd.exportd_logs.exportd_log import ExportdJobLog, LogAction, ExportdMetaLog
from cmdb.framework.results import IterationResult
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.response import GetMultiResponse
from cmdb.interface.rest_api.exportd_routes import exportd_blueprint
from cmdb.interface.route_utils import make_response, insert_request_user, login_required, right_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.manager import ManagerIterationError, ManagerGetError
from cmdb.user_management import UserModel
from cmdb.utils.error import CMDBError

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

with current_app.app_context():
    exportd_manager = ExportdJobManagement(current_app.database_manager, current_app.event_queue)
    log_manager = ExportdLogManager(current_app.database_manager)


@exportd_blueprint.route('/logs', methods=['GET', 'HEAD'])
@exportd_blueprint.protect(auth=True, right='base.exportd.log.view')
@exportd_blueprint.parse_collection_parameters()
def get_exportd_logs(params: CollectionParameters):
    """Iterate route for exportd logs"""

    log_manager = ExportDLogManager(current_app.database_manager)
    body = request.method == 'HEAD'
Esempio n. 5
0
from flask import abort, jsonify, current_app, Response

from cmdb.framework import TypeModel
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.interface.route_utils import login_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.framework.cmdb_errors import TypeNotFoundError
from cmdb.utils import json_encoding
from cmdb.utils.error import CMDBError

with current_app.app_context():
    object_manager = CmdbObjectManager(current_app.database_manager,
                                       current_app.event_queue)

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 = [
            TypeModel.to_json(type) for type in 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)
Esempio n. 6
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
Esempio n. 7
0
# DATAGERRY - OpenSource Enterprise CMDB
# Copyright (C) 2019 - 2021 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/>.

from flask import current_app
from cmdb.interface.blueprint import RootBlueprint

importer_blueprint = RootBlueprint('import_rest',
                                   __name__,
                                   url_prefix='/import')

with current_app.app_context():
    from cmdb.interface.rest_api.importer_routes.importer_object_routes import importer_object_blueprint
    importer_blueprint.register_nested_blueprint(importer_object_blueprint)
    from cmdb.interface.rest_api.importer_routes.importer_type_routes import importer_type_blueprint
    importer_blueprint.register_nested_blueprint(importer_type_blueprint)
Esempio n. 8
0
from cmdb.interface.blueprint import RootBlueprint
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)
Esempio n. 9
0
from cmdb.security.auth import AuthModule, AuthSettingsDAO
from cmdb.security.auth.auth_errors import AuthenticationProviderNotExistsError, \
    AuthenticationProviderNotActivated
from cmdb.security.auth.response import LoginResponse
from cmdb.security.token.generator import TokenGenerator
from cmdb.user_management import UserModel
from cmdb.user_management.managers.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 = UserManager(current_app.database_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')
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, recursive_delete_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_file_list(request_user: User):
    """
    get all objects in database

    Returns:
        list of media_files
Esempio n. 11
0
from flask import current_app

from cmdb.interface.route_utils import make_response, login_required
from cmdb.interface.blueprint import RootBlueprint
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)
Esempio n. 12
0
import logging

from flask import request, abort, current_app

from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.interface.route_utils import make_response, login_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.utils.error import CMDBError

with current_app.app_context():
    object_manager: CmdbObjectManager = CmdbObjectManager(
        current_app.database_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_categories())
        types_total = object_manager.count_types()
        objects_total = object_manager.count_objects()

        if _fetch_only_active_objs():
            result = []
Esempio n. 13
0
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 make_response, login_required, right_required, insert_request_user
from cmdb.interface.blueprint import RootBlueprint
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)
Esempio n. 14
0
from cmdb.security.acl.errors import AccessDeniedError
from cmdb.security.acl.permission import AccessControlPermission
from cmdb.user_management import UserModel, UserManager
from cmdb.utils.error import CMDBError

with current_app.app_context():
    object_manager = CmdbObjectManager(current_app.database_manager,
                                       current_app.event_queue)
    log_manager = CmdbLogManager(current_app.database_manager)
    user_manager = UserManager(current_app.database_manager)

LOGGER = logging.getLogger(__name__)

objects_blueprint = APIBlueprint('objects', __name__)
object_blueprint = RootBlueprint('object_blueprint',
                                 __name__,
                                 url_prefix='/object')


@objects_blueprint.route('/', methods=['GET', 'HEAD'])
@objects_blueprint.protect(auth=True, right='base.framework.object.view')
@objects_blueprint.parse_collection_parameters(view='native')
@insert_request_user
def get_objects(params: CollectionParameters, request_user: UserModel):
    from cmdb.framework.managers.object_manager import ObjectManager
    manager = ObjectManager(database_manager=current_app.database_manager)
    view = params.optional.get('view', 'native')
    if _fetch_only_active_objs():
        if isinstance(params.filter, dict):
            filter_ = params.filter
            params.filter = [{'$match': filter_}]
Esempio n. 15
0
from cmdb.interface.blueprint import RootBlueprint
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):
    """
Esempio n. 16
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 make_response
from cmdb.interface.blueprint import RootBlueprint
from cmdb.database.managers 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)
Esempio n. 17
0
from datetime import datetime

from cmdb.interface.route_utils import make_response, insert_request_user, login_required, right_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.user_management import User
from cmdb.user_management.user_manager import UserManagerInsertError, UserManagerGetError, \
    UserManagerUpdateError, UserManagerDeleteError, UserManager
from cmdb.security.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)
Esempio n. 18
0
import logging

from flask import abort, jsonify, current_app

from cmdb.exportd.exportd_job.exportd_job_manager import ExportdJobManagement
from cmdb.utils.helpers import load_class, get_module_classes
from cmdb.interface.route_utils import make_response, login_required
from cmdb.interface.blueprint import RootBlueprint
from cmdb.utils.error import CMDBError

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

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):
Esempio n. 19
0
from cmdb.framework.cmdb_errors import TypeNotFoundError
from cmdb.file_export.file_exporter import FileExporter, SupportedExportTypes
from cmdb.interface.route_utils import make_response, login_required, insert_request_user
from cmdb.interface.blueprint import RootBlueprint
from cmdb.user_management import UserModel
from cmdb.utils.helpers import load_class

from cmdb.security.acl.permission import AccessControlPermission

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_export_file_types():
    return make_response(SupportedExportTypes().convert_to())


@file_blueprint.route('/object/', methods=['GET'])
@login_required
@insert_request_user
def export_file(request_user: UserModel):
    import json
    try:
        _object_ids = json.loads(request.args.get('ids', []))
Esempio n. 20
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 UserModel

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: UserModel):
    """
    get all objects in database
    Returns:
        list of docapi templates
    """
    try:
Esempio n. 21
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.blueprint 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")