当前位置: 首页>>代码示例>>Python>>正文


Python auth.has_perm函数代码示例

本文整理汇总了Python中networkapi.auth.has_perm函数的典型用法代码示例。如果您正苦于以下问题:Python has_perm函数的具体用法?Python has_perm怎么用?Python has_perm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了has_perm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        '''Trata as requisições de GET para listar Roteiros.

        URLs: roteiro/$
              roteiro/tiporoteiro/<id_tipo_roteiro>/
              roteiro/equipamento/<id_equip>/
        '''

        try:
            map_list = []

            equipment_id = kwargs.get('id_equip')
            if equipment_id is None:
                if not has_perm(user, AdminPermission.SCRIPT_MANAGEMENT, AdminPermission.READ_OPERATION):
                    return self.not_authorized()

                scripts = Roteiro.search(kwargs.get('id_tipo_roteiro'))
                for script in scripts:
                    script_map = dict()
                    script_map['id'] = script.id
                    script_map['nome'] = script.roteiro
                    script_map['descricao'] = script.descricao
                    script_map['id_tipo_roteiro'] = script.tipo_roteiro_id

                    map_list.append(script_map)

            else:
                if not has_perm(user,
                                AdminPermission.EQUIPMENT_MANAGEMENT,
                                AdminPermission.READ_OPERATION,
                                None,
                                equipment_id,
                                AdminPermission.EQUIP_READ_OPERATION):
                    return self.not_authorized()

                equipment_scripts = EquipamentoRoteiro.search(
                    None, equipment_id)
                for equipment_script in equipment_scripts:
                    script_map = dict()
                    script_map['id'] = equipment_script.roteiro.id
                    script_map['nome'] = equipment_script.roteiro.roteiro
                    script_map[
                        'descricao'] = equipment_script.roteiro.descricao
                    script_map[
                        'id_tipo_roteiro'] = equipment_script.roteiro.tipo_roteiro.id
                    script_map[
                        'nome_tipo_roteiro'] = equipment_script.roteiro.tipo_roteiro.tipo
                    script_map[
                        'descricao_tipo_roteiro'] = equipment_script.roteiro.tipo_roteiro.descricao

                    map_list.append(script_map)

            return self.response(dumps_networkapi({'roteiro': map_list}))

        except EquipamentoNotFoundError:
            return self.response_error(117, equipment_id)
        except (RoteiroError, GrupoError, EquipamentoError):
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:58,代码来源:RoteiroResource.py

示例2: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all Environments.

        URL: /ambiente/equip/id_equip
        """

        try:

            # Commons Validations

            # User permission

            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                return self.not_authorized()
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                return self.not_authorized()

            id_equip = kwargs.get('id_equip')

            if not is_valid_int_greater_zero_param(id_equip):
                raise InvalidValueError(None, 'id_equip', id_equip)

            # Business Rules
            equip = Equipamento.get_by_pk(id_equip)
            environments_list = EquipamentoAmbiente.get_by_equipment(equip.id)

            # Get all environments in DB
            lists_aux = []
            for environment in environments_list:
                env = Ambiente.get_by_pk(environment.ambiente.id)
                env_map = model_to_dict(env)
                env_map['grupo_l3_name'] = env.grupo_l3.nome
                env_map['ambiente_logico_name'] = env.ambiente_logico.nome
                env_map['divisao_dc_name'] = env.divisao_dc.nome
                env_map['is_router'] = environment.is_router

                try:
                    env_map['range'] = str(
                        env.min_num_vlan_1) + ' - ' + str(env.max_num_vlan_1)
                    if env.min_num_vlan_1 != env.min_num_vlan_2:
                        env_map['range'] = env_map[
                            'range'] + '; ' + str(env.min_num_vlan_2) + ' - ' + str(env.max_num_vlan_2)
                except:
                    env_map['range'] = 'Nao definido'

                if env.filter is not None:
                    env_map['filter_name'] = env.filter.name

                lists_aux.append(env_map)
            # Return XML
            environment_list = dict()
            environment_list['ambiente'] = lists_aux
            return self.response(dumps_networkapi(environment_list))

        except InvalidValueError, e:
            self.log.error(
                u'Parameter %s is invalid. Value: %s.', e.param, e.value)
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:58,代码来源:EnvironmentGetByEquipResource.py

示例3: create_vlan

    def create_vlan(self, user, vlan_id):

        if not has_perm(user, AdminPermission.VLAN_MANAGEMENT, AdminPermission.WRITE_OPERATION):
            return self.not_authorized()

        vlan = Vlan().get_by_pk(vlan_id)

        # Check permission group equipments
        equips_from_ipv4 = Equipamento.objects.filter(
            ipequipamento__ip__networkipv4__vlan=vlan_id, equipamentoambiente__is_router=1)
        equips_from_ipv6 = Equipamento.objects.filter(
            ipv6equipament__ip__networkipv6__vlan=vlan_id, equipamentoambiente__is_router=1)
        for equip in equips_from_ipv4:
            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION, None, equip.id, AdminPermission.EQUIP_WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()
        for equip in equips_from_ipv6:
            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.WRITE_OPERATION, None, equip.id, AdminPermission.EQUIP_WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

        if vlan.ativada:
            return self.response_error(122)

        command = settings.VLAN_CREATE % (vlan.id)

        code, stdout, stderr = exec_script(command)
        if code == 0:
            vlan.activate(user)

            success_map = dict()
            success_map['codigo'] = '%04d' % code
            success_map['descricao'] = {'stdout': stdout, 'stderr': stderr}

            map = dict()
            map['sucesso'] = success_map

            # Send to Queue
            queue_manager = QueueManager()

            serializer = VlanSerializer(vlan)
            data_to_queue = serializer.data
            data_to_queue.update({'description': queue_keys.VLAN_CREATE})
            queue_manager.append({'action': queue_keys.VLAN_CREATE,'kind': queue_keys.VLAN_KEY,'data': data_to_queue})

            queue_manager.send()

            return self.response(dumps_networkapi(map))
        else:
            return self.response_error(2, stdout + stderr)
开发者ID:itnihao,项目名称:GloboNetworkAPI,代码行数:54,代码来源:VlanResource.py

示例4: handle_delete

    def handle_delete(self, request, user, *args, **kwargs):
        """Treat DELETE requests to remove Group User.

        URL: ugroup/<id_ugroup>/
        """
        try:

            self.log.info('Remove Group User')

            # User permission
            if not has_perm(user, AdminPermission.USER_ADMINISTRATION, AdminPermission.WRITE_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            id_ugroup = kwargs.get('id_ugroup')

            # Valid Group User ID
            if not is_valid_int_greater_zero_param(id_ugroup):
                self.log.error(
                    u'The id_ugroup parameter is not a valid value: %s.', id_ugroup)
                raise InvalidValueError(None, 'id_ugroup', id_ugroup)

            # Find Group User by ID to check if it exist
            ugroup = UGrupo.get_by_pk(id_ugroup)

            with distributedlock(LOCK_GROUP_USER % id_ugroup):

                ugroup.delete()
                return self.response(dumps_networkapi({}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:33,代码来源:GroupUserAlterRemoveResource.py

示例5: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to list all Equipment Type.

        URL: equipmenttype/all
        """
        try:

            self.log.info("GET to list all Equipment Type")

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            map_list = []
            for equipment_type in TipoEquipamento.objects.all():
                eq_tp = {
                    'id': equipment_type.id, 'nome': equipment_type.tipo_equipamento}
                map_list.append(eq_tp)

            return self.response(dumps_networkapi({'equipment_type': map_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except EquipamentoError:
            return self.response_error(1)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:28,代码来源:EquipmentTypeGetAllResource.py

示例6: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Trata as requisições GET para consulta de HealthCheckExpects por id.

        Lista as informações de um HealthCheckExpect por id.

        URL:  /healthcheckexpect/get/<id_healthcheck_expect>/
        """
        try:
            if not has_perm(user,
                            AdminPermission.HEALTH_CHECK_EXPECT,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            id_healthcheck = kwargs.get('id_healthcheck')

            if not is_valid_int_greater_zero_param(id_healthcheck):
                self.log.error(
                    u'The id_healthcheck parameter is not a valid value: %s.', id_healthcheck)
                raise InvalidValueError(None, 'id_healthcheck', id_healthcheck)

            heal = HealthcheckExpect.get_by_pk(id_healthcheck)

            healthcheckexpect_map = model_to_dict(heal)

            return self.response(dumps_networkapi({'healthcheck_expect': healthcheckexpect_map}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:28,代码来源:HealthcheckExpectGetResource.py

示例7: handle_post

    def handle_post(self, request, user, *args, **kwargs):
        """Treat requests POST to create the configuration file.

        URL: rack/gerar-arq-config/id_rack
        """
        try:
            self.log.info("CONFIG")

            # User permission
            if not has_perm(user, AdminPermission.SCRIPT_MANAGEMENT, AdminPermission.WRITE_OPERATION):
                self.log.error(u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            rack_id = kwargs.get('id_rack')
            rack = Rack()
            rack = rack.get_by_pk(rack_id)
            var = False

            #Chama o script para gerar os arquivos de configuracao
            var = gera_config(rack)

            rack.__dict__.update(id=rack_id, config=var)
            rack.save()

            success_map = dict()
            success_map['rack_conf'] = var
            map = dict()
            map['sucesso'] = success_map
                        
            return self.response(dumps_networkapi(map))


        except RackConfigError, e:
            return self.response_error(382, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:34,代码来源:RackConfigResource.py

示例8: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks
        URLs: /rack/find/
        """

        self.log.info('List all Racks')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION):
                self.log.error( u'User does not have permission to perform the operation.')

                return self.not_authorized()

            rack_list = []
            for rack in Rack.objects.all():
                rack_list.append(model_to_dict(rack))

            return self.response(dumps_networkapi({'rack': rack_list}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(379)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:26,代码来源:RackListAllResource.py

示例9: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat requests GET to get User by the identifier.

        URL: user/get/<id_user>/
        """
        try:

            self.log.info("Get User by the identifier")

            # User permission
            if not has_perm(user, AdminPermission.USER_ADMINISTRATION, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                raise UserNotAuthorizedError(None)

            id_user = kwargs.get('id_user')

            # Valid User ID
            if not is_valid_int_greater_zero_param(id_user):
                self.log.error(
                    u'The id_user parameter is not a valid value: %s.', id_user)
                raise InvalidValueError(None, 'id_user', id_user)

            # Find User by ID to check if it exist
            usr = Usuario.get_by_pk(id_user)

            user_map = dict()
            user_map['usuario'] = model_to_dict(usr)
            user_map['usuario']['grupos'] = user_map['usuario']['grupos'] if user_map['usuario'][
                'grupos'] is not None and len(user_map['usuario']['grupos']) > 0 else [None]

            return self.response(dumps_networkapi(user_map))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:35,代码来源:UserGetByIdResource.py

示例10: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests list all Filters.

        URL: filter/all/
        """

        try:

            self.log.info("List all Filters")
            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Business Rules
            filters = Filter.objects.all()

            filter_list = []
            for filter_ in filters:
                filter_dict = model_to_dict(filter_)
                filter_dict['equip_types'] = list()

                for fil_equip_type in filter_.filterequiptype_set.all():
                    filter_dict['equip_types'].append(
                        model_to_dict(fil_equip_type.equiptype))

                filter_list.append(filter_dict)

            return self.response(dumps_networkapi({'filter': filter_list}))

        except BaseException, e:
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:35,代码来源:FilterListAllResource.py

示例11: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """
        Handles GET requests to list all the VIPs.

        URL: vip/all/
        """

        try:
            if not has_perm(user,
                            AdminPermission.VIPS_REQUEST,
                            AdminPermission.READ_OPERATION):
                return self.not_authorized()

            request_vips = RequisicaoVips.get_all()
            vips = {}

            for vip in request_vips:
                request_vip_map = vip.variables_to_map()
                request_vip_map['id'] = vip.id
                request_vip_map['validado'] = vip.validado
                request_vip_map['vip_criado'] = vip.vip_criado
                request_vip_map['id_ip'] = vip.ip_id
                request_vip_map['id_ipv6'] = vip.ipv6_id
                request_vip_map[
                    'id_healthcheck_expect'] = vip.healthcheck_expect_id
                vips['vip_%s' % (vip.id)] = request_vip_map

            return self.response(dumps_networkapi(vips))

        except (RequisicaoVipsNotFoundError):
            return self.response_error(152)
        except (RequisicaoVipsError, GrupoError):
            return self.response_error(1)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:33,代码来源:RequestAllVipsResource.py

示例12: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Treat GET requests to get a Filter by id.

        URL: filter/get/<id_filter>/
        """

        try:

            self.log.info("Get Filter by id")
            # Commons Validations

            # User permission
            if not has_perm(user, AdminPermission.ENVIRONMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(u"User does not have permission to perform the operation.")
                return self.not_authorized()

            if not is_valid_int_greater_zero_param(kwargs["id_filter"]):
                self.log.error(u"Parameter id_filter is invalid. Value: %s.", kwargs["id_filter"])
                raise InvalidValueError(None, "id_filter", kwargs["id_filter"])
            else:
                # Check existence
                fil = Filter().get_by_pk(kwargs["id_filter"])

            filter_dict = model_to_dict(fil)
            filter_dict["equip_types"] = list()
            for fil_equip_type in fil.filterequiptype_set.all():
                filter_dict["equip_types"].append(model_to_dict(fil_equip_type.equiptype))

            return self.response(dumps_networkapi({"filter": filter_dict}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:andrewsmedina,项目名称:GloboNetworkAPI,代码行数:32,代码来源:FilterGetByIdResource.py

示例13: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find EnvironmentInterface.

        URLs: int/get-env-by-interface/<id_interface>
        """
        self.log.info('buscando os ambientes associados a uma interface')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            # Get XML data
            interface = kwargs.get('id_interface')

            int_ambiente = EnvironmentInterface.get_by_interface(int(interface))

            ambiente_map = []

            for ids in int_ambiente:
                ambiente_map.append(self.get_environment_map(ids.ambiente))

            return self.response(dumps_networkapi({'ambiente': ambiente_map}))

        except InvalidValueError, e:
            return self.response_error(269, e.param, e.value)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:29,代码来源:InterfaceEnvironmentResource.py

示例14: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to list all equipment.

        URLs: equipament/list/
        """

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT, AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            equip_list = Equipamento.objects.all()

            map_dicts = []
            for equip in equip_list:
                map_dicts.append(model_to_dict(equip))

            equip_map = dict()
            equip_map['equipamentos'] = map_dicts

            # Return XML
            return self.response(dumps_networkapi(equip_map))

        except (EquipamentoError, GrupoError):
            return self.response_error(1)
        except XMLError, x:
            self.log.error(u'Error reading the XML request.')
            return self.response_error(3, x)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:31,代码来源:EquipmentGetAllResource.py

示例15: handle_get

    def handle_get(self, request, user, *args, **kwargs):
        """Handles GET requests to find all Racks

        URLs: /rack/find/
        """

        self.log.info('Find all Racks')

        try:

            # User permission
            if not has_perm(user, AdminPermission.EQUIPMENT_MANAGEMENT , AdminPermission.READ_OPERATION):
                self.log.error(
                    u'User does not have permission to perform the operation.')
                return self.not_authorized()

            nome = kwargs.get('rack_name')
            rack = Rack()
            rack = rack.get_by_name(nome)
            rack = model_to_dict(rack)

            return self.response(dumps_networkapi({'rack': rack}))

        except UserNotAuthorizedError:
            return self.not_authorized()

        except RackError:
            return self.response_error(379)
开发者ID:marcelometal,项目名称:GloboNetworkAPI,代码行数:28,代码来源:RackFindResource.py


注:本文中的networkapi.auth.has_perm函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。