Esempio n. 1
0
from cmdb.interface.blueprint import RootBlueprint, APIBlueprint
from cmdb.manager import ManagerIterationError, ManagerGetError, ManagerUpdateError
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):
Esempio n. 2
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 cmdb.interface.blueprint import APIBlueprint

exportd_blueprint = APIBlueprint('exportd', __name__)
Esempio n. 3
0
# 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 typing import List

from flask import current_app, abort, request

from cmdb.interface.blueprint import APIBlueprint
from cmdb.interface.response import GetListResponse, GetSingleResponse, InsertSingleResponse, DeleteSingleResponse, \
    UpdateSingleResponse
from cmdb.manager import ManagerGetError, ManagerInsertError, ManagerDeleteError, ManagerUpdateError
from cmdb.user_management import UserSettingModel
from cmdb.user_management.managers.setting_manager import UserSettingsManager

user_settings_blueprint = APIBlueprint('user_settings', __name__)


@user_settings_blueprint.route('/', methods=['GET', 'HEAD'])
def get_user_settings(user_id: int):
    """
    HTTP `GET`/`HEAD` route for getting a complete collection of resources.

    Args:
        user_id (int): PublicID of the current user.

    Returns:
        GetListResponse: Which includes all of the `UserSettingModel`.

    Notes:
        Calling the route over HTTP HEAD method will result in an empty body.
Esempio n. 4
0
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.interface.route_utils import make_response, insert_request_user, login_required
from cmdb.search import Search
from cmdb.search.params import SearchParam
from cmdb.search.query import Pipeline
from cmdb.search.searchers import SearcherFramework, SearchPipelineBuilder, QuickSearchPipelineBuilder
from cmdb.user_management.models.user import UserModel
from cmdb.interface.blueprint import APIBlueprint
from cmdb.security.acl.permission import AccessControlPermission

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

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


@search_blueprint.route('/quick/count', methods=['GET'])
@search_blueprint.route('/quick/count/', methods=['GET'])
@search_blueprint.protect(auth=True)
@insert_request_user
def quick_search_result_counter(request_user: UserModel):
    search_term = request.args.get('searchValue', Search.DEFAULT_REGEX, str)
    builder = QuickSearchPipelineBuilder()
    only_active = _fetch_only_active_objs()
    pipeline: Pipeline = builder.build(search_term=search_term, user=request_user,
                                       permission=AccessControlPermission.READ,
                                       active_flag=only_active)
    try:
        result = list(object_manager.aggregate(collection='framework.objects', pipeline=pipeline))
Esempio n. 5
0
from flask import abort, request, current_app

from cmdb.framework.models.link import ObjectLinkModel
from cmdb.framework.managers.object_link_manager import ObjectLinkManager
from cmdb.framework.results import IterationResult
from cmdb.framework.utils import PublicID
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.response import GetSingleResponse, DeleteSingleResponse, InsertSingleResponse, GetMultiResponse
from cmdb.interface.route_utils import insert_request_user
from cmdb.interface.blueprint import APIBlueprint
from cmdb.manager.errors import ManagerGetError, ManagerDeleteError, ManagerInsertError, ManagerIterationError
from cmdb.security.acl.errors import AccessDeniedError
from cmdb.security.acl.permission import AccessControlPermission
from cmdb.user_management import UserModel

links_blueprint = APIBlueprint('links', __name__)


@links_blueprint.route('/', methods=['GET', 'HEAD'])
@links_blueprint.protect(auth=True, right='base.framework.object.view')
@links_blueprint.parse_collection_parameters()
@insert_request_user
def get_links(params: CollectionParameters, request_user: UserModel):
    link_manager = ObjectLinkManager(
        database_manager=current_app.database_manager)
    body = request.method == 'HEAD'

    try:
        iteration_result: IterationResult[
            ObjectLinkModel] = link_manager.iterate(
                filter=params.filter,
Esempio n. 6
0
from cmdb.interface.response import GetMultiResponse, InsertSingleResponse
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.blueprint import APIBlueprint

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 = APIBlueprint('media_file_blueprint', __name__, url_prefix='/media_file')


@media_file_blueprint.route('/', methods=['GET', 'HEAD'])
@media_file_blueprint.protect(auth=True, right='base.framework.object.view')
@media_file_blueprint.parse_collection_parameters()
def get_file_list(params: CollectionParameters):
    """
    Get all objects in database

    Args:
        params (CollectionParameters): Passed parameters over the http query string + optional `view` parameter.

    Raises:
        MediaFileManagerGetError: If the files could not be found.
from flask import abort, current_app, request

from cmdb.framework.models.category import CategoryModel, CategoryTree
from cmdb.framework.managers import ManagerGetError, ManagerInsertError, ManagerDeleteError, ManagerUpdateError
from cmdb.framework.managers.category_manager import CategoryManager
from cmdb.framework.managers.error.framework_errors import FrameworkIterationError
from cmdb.framework.results.iteration import IterationResult
from cmdb.framework.utils import PublicID
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.response import GetSingleResponse, GetMultiResponse, InsertSingleResponse, DeleteSingleResponse, \
    UpdateSingleResponse
from cmdb.interface.blueprint import APIBlueprint

LOGGER = logging.getLogger(__name__)
categories_blueprint = APIBlueprint('categories', __name__)


@categories_blueprint.route('/', methods=['GET', 'HEAD'])
@categories_blueprint.protect(auth=True, right='base.framework.category.view')
@categories_blueprint.parse_collection_parameters(view='list')
def get_categories(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string + optional `view` parameter.

    Returns:
        GetMultiResponse: Which includes a IterationResult of the CategoryModel.
        If the view parameter with tree was set the route returns a GetMultiResponse<CategoryTree>.
Esempio n. 8
0
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from flask import request, abort

from cmdb.framework.utils import Model
from cmdb.manager.errors import ManagerGetError, ManagerIterationError
from cmdb.framework.results import IterationResult
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.blueprint import APIBlueprint
from cmdb.interface.response import GetMultiResponse, GetSingleResponse
from cmdb.user_management.managers.right_manager import RightManager
from cmdb.user_management.models.right import BaseRight
from cmdb.user_management.rights import __all__ as right_tree
from cmdb.user_management.models.right import _nameToLevel

rights_blueprint = APIBlueprint('rights', __name__)


@rights_blueprint.route('/', methods=['GET', 'HEAD'])
@rights_blueprint.protect(auth=False, right=None)
@rights_blueprint.parse_collection_parameters(sort='name', view='list')
def get_rights(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string

    Returns:
        GetMultiResponse: Which includes a IterationResult of the BaseRight.
Esempio n. 9
0
from cmdb.framework.results import IterationResult
from cmdb.framework.utils import PublicID
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.response import GetMultiResponse, GetSingleResponse, InsertSingleResponse, UpdateSingleResponse, \
    DeleteSingleResponse
from cmdb.interface.route_utils import abort
from cmdb.interface.blueprint import APIBlueprint
from cmdb.search import Query
from cmdb.user_management import UserModel
from cmdb.user_management.managers.group_manager import GroupManager
from cmdb.user_management.managers.right_manager import RightManager
from cmdb.user_management.managers.user_manager import UserManager
from cmdb.user_management.models.group import UserGroupModel
from cmdb.user_management.rights import __all__ as rights

groups_blueprint = APIBlueprint('groups', __name__)


@groups_blueprint.route('/', methods=['GET', 'HEAD'])
@groups_blueprint.protect(auth=True, right='base.user-management.group.view')
@groups_blueprint.parse_collection_parameters()
def get_groups(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string

    Returns:
        GetMultiResponse: Which includes a IterationResult of the UserGroupModel.
Esempio n. 10
0
from flask import abort, request, current_app

from cmdb.framework.models.type import TypeModel
from cmdb.framework.managers import ManagerGetError, ManagerInsertError, ManagerUpdateError, ManagerDeleteError
from cmdb.framework.managers.error.framework_errors import FrameworkIterationError
from cmdb.framework.results.iteration import IterationResult
from cmdb.framework.managers.type_manager import TypeManager
from cmdb.framework.utils import PublicID
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.blueprint import APIBlueprint
from cmdb.interface.response import GetMultiResponse, GetSingleResponse, InsertSingleResponse, UpdateSingleResponse, \
    DeleteSingleResponse

LOGGER = logging.getLogger(__name__)
types_blueprint = APIBlueprint('types', __name__)


@types_blueprint.route('/', methods=['GET', 'HEAD'])
@types_blueprint.protect(auth=True, right='base.framework.type.view')
@types_blueprint.parse_collection_parameters()
def get_types(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string

    Returns:
        GetMultiResponse: Which includes a IterationResult of the TypeModel.
Esempio n. 11
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 request, current_app, abort

from cmdb.interface.route_utils import make_response
from cmdb.interface.blueprint import APIBlueprint

from cmdb.settings.date.date_settings import DateSettingsDAO
from cmdb.utils.system_reader import SystemSettingsReader
from cmdb.utils.system_writer import SystemSettingsWriter

date_blueprint = APIBlueprint('date', __name__)
LOGGER = logging.getLogger(__name__)

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


@date_blueprint.route('/', methods=['GET'])
def get_date_settings():
    date_settings = system_settings_reader.get_all_values_from_section('date',
                                                                       default=DateSettingsDAO.__DEFAULT_SETTINGS__)
    date_settings = DateSettingsDAO(**date_settings)
    return make_response(date_settings)

Esempio n. 12
0
from cmdb.interface.route_utils import make_response, insert_request_user
from cmdb.interface.blueprint import APIBlueprint
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.security import SecurityManager
from cmdb.security.token.generator import TokenGenerator
from cmdb.user_management import UserModel, RightManager
from cmdb.user_management.managers.group_manager import GroupManager
from cmdb.user_management.managers.user_manager import UserManager
from cmdb.utils.system_reader import SystemSettingsReader
from cmdb.utils.system_writer import SystemSettingsWriter
from cmdb.user_management.rights import __all__ as rights

auth_blueprint = APIBlueprint('auth', __name__)
LOGGER = logging.getLogger(__name__)

with current_app.app_context():
    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.protect(auth=True, right='base.system.view')
def get_auth_settings():
    auth_settings = system_settings_reader.get_all_values_from_section(
        'auth', default=AuthModule.__DEFAULT_SETTINGS__)
    auth_module = AuthModule(auth_settings)
Esempio n. 13
0
from flask import abort, request, current_app

from cmdb.framework.utils import PublicID
from cmdb.manager.errors import ManagerGetError, ManagerInsertError, ManagerUpdateError, ManagerDeleteError, \
    ManagerIterationError
from cmdb.framework.results import IterationResult
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.blueprint import APIBlueprint
from cmdb.interface.response import GetMultiResponse, GetSingleResponse, InsertSingleResponse, UpdateSingleResponse, \
    DeleteSingleResponse
from cmdb.security.security import SecurityManager
from cmdb.user_management import UserModel
from cmdb.user_management.managers.user_manager import UserManager

users_blueprint = APIBlueprint('users', __name__)


@users_blueprint.route('/', methods=['GET', 'HEAD'])
@users_blueprint.protect(auth=True, right='base.user-management.user.view')
@users_blueprint.parse_collection_parameters()
def get_users(params: CollectionParameters):
    """
    HTTP `GET`/`HEAD` route for getting a iterable collection of resources.

    Args:
        params (CollectionParameters): Passed parameters over the http query string

    Returns:
        GetMultiResponse: Which includes a IterationResult of the UserModel.
Esempio n. 14
0
from cmdb.framework.cmdb_object_manager import CmdbObjectManager
from cmdb.framework.managers.object_manager import ObjectManager
from cmdb.framework.models.log import CmdbObjectLog, CmdbMetaLog, LogAction
from cmdb.framework.managers.log_manager import CmdbLogManager
from cmdb.manager.errors import ManagerIterationError, ManagerGetError, ManagerDeleteError
from cmdb.interface.route_utils import make_response, insert_request_user

from cmdb.interface.api_parameters import CollectionParameters
from cmdb.interface.blueprint import APIBlueprint
from cmdb.interface.response import GetMultiResponse
from cmdb.security.acl.errors import AccessDeniedError
from cmdb.security.acl.permission import AccessControlPermission
from cmdb.user_management import UserModel

LOGGER = logging.getLogger(__name__)
log_blueprint = APIBlueprint('log', __name__)

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


# CRUD routes
@log_blueprint.route('/<int:public_id>', methods=['GET'])
@log_blueprint.protect(auth=True, right='base.framework.log.view')
@insert_request_user
def get_log(public_id: int, request_user: UserModel):
    manager = CmdbLogManager(database_manager=database_manager)
    try:
Esempio n. 15
0
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from flask import abort, jsonify, current_app

from cmdb.framework.cmdb_errors import TypeNotFoundError
from cmdb.exporter.config.config_type import ExporterConfig
from cmdb.exporter.writer.writer_base import SupportedExporterExtension, BaseExportWriter
from cmdb.interface.route_utils import make_response, login_required, insert_request_user
from cmdb.interface.blueprint import APIBlueprint
from cmdb.user_management import UserModel
from cmdb.utils.helpers import load_class
from cmdb.interface.api_parameters import CollectionParameters
from cmdb.security.acl.permission import AccessControlPermission
from cmdb.utils.error import CMDBError

exporter_blueprint = APIBlueprint('exporter', __name__)


@exporter_blueprint.route('/extensions', methods=['GET'])
@login_required
def get_export_file_types():
    return make_response(SupportedExporterExtension().convert_to())


@exporter_blueprint.route('/', methods=['GET'])
@exporter_blueprint.protect(auth=True, right='base.framework.object.view')
@exporter_blueprint.parse_collection_parameters(view='native')
@insert_request_user
@insert_request_user
def export_objects(params: CollectionParameters, request_user: UserModel):
    try:
Esempio n. 16
0
from cmdb.docapi.docapi_template.docapi_template import DocapiTemplate
from cmdb.docapi.docapi_template.docapi_template_manager import DocapiTemplateManagerGetError, \
    DocapiTemplateManagerInsertError, DocapiTemplateManagerUpdateError, DocapiTemplateManagerDeleteError, \
    DocapiTemplateManager
from cmdb.user_management import UserModel

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

LOGGER = logging.getLogger(__name__)

docapi_blueprint = RootBlueprint('docapi', __name__, url_prefix='/docapi')
docs_blueprint = APIBlueprint('docs', __name__)


# DEFAULT ROUTES
@docs_blueprint.route('/template', methods=['GET', 'HEAD'])
@docs_blueprint.protect(auth=True, right='base.docapi.template.view')
@docs_blueprint.parse_collection_parameters()
def get_template_list(params: CollectionParameters):
    template_manager = DocapiTemplateManager(
        database_manager=current_app.database_manager)
    body = request.method == 'HEAD'

    try:
        iteration_result: IterationResult[
            DocapiTemplate] = template_manager.get_templates(
                filter=params.filter,