Пример #1
0
 def processFilter(self, rfilter, provider, marker, encoder):
     '''
     Process the provided filter.
     
     @param rfilter: Filter
         The resource filter to process.
     @param provider: callable|None
         The callable used in solving the authenticated values.
     @param marker: string
         The resource marker to place in the filter path, this marker is used to identify the group in the gateway pattern.
     @param encoder: IEncoderPath
         The encoder path to be used for the gateways resource paths and patterns.
     @return: string|None
         The marked filter path, None if the filter is invalid.
     '''
     assert isinstance(rfilter, Filter), 'Invalid filter %s' % rfilter
     assert isinstance(rfilter.filter, IAclFilter), 'Invalid filter %s of %s' % (rfilter.filter, rfilter)
     typeService = typeFor(rfilter.filter)
     assert isinstance(typeService, TypeService), 'Invalid filter %s, is not a REST service' % rfilter.filter
     assert isinstance(marker, str), 'Invalid marker %s' % marker
     assert isinstance(encoder, IEncoderPath), 'Invalid encoder path %s' % encoder
     
     path = self._cacheFilters.get(typeService)
     if not path:
         nodes = findNodesFor(self.resourcesRoot, typeService, 'isAllowed')
         if not nodes:
             log.error('The filter service %s cannot be located in the resources tree', typeService)
             return
         if len(nodes) > 1:
             log.error('To many nodes for service %s in the resources tree, don\'t know which one to use', typeService)
             return
         
         node = nodes[0]
         assert isinstance(node, Node)
         path = pathForNode(node)
         
         if __debug__:
             # Just checking that the properties are ok
             propertyTypes = propertyTypesOf(path, node.get)
             assert len(propertyTypes) == 2, 'Invalid path %s for filter' % path
             indexAuth = propertyTypes.index(rfilter.authenticated)
             assert indexAuth >= 0, 'Invalid authenticated %s for path %s' % (rfilter.authenticated, path)
             indexRsc = propertyTypes.index(rfilter.resource)
             assert indexRsc >= 0, 'Invalid resource %s for path %s' % (rfilter.resource, path)
             assert indexAuth < indexRsc, 'Invalid path %s, improper order for types' % path
 
     assert isinstance(path, Path), 'Invalid path %s' % path
     if provider:
         assert callable(provider), 'Invalid authenticated provider %s' % provider
         valueAuth = provider(rfilter.authenticated)
     else: valueAuth = None
     if valueAuth is None:
         log.error('The filter service %s has not authenticated value for %s', typeService, rfilter.authenticated)
         return
     
     return encoder.encode(path, invalid=ReplacerWithMarkers().register((valueAuth, marker)), quoted=False)
Пример #2
0
 def _processFilters(self, filters, replacer):
     '''
     Process the filters into path filters.
     
     @param filters: Iterable(Filter)
         The filters to process.
     @param replacer: PatternReplacer
         The replacer to use on the path.
     @return: dictionary{TypeProperty, tuple(string, dictionary{TypeProperty: string}}
         A dictionary containing {resource type, (marked path, {authenticated type: marker}}
     '''
     assert isinstance(filters, Iterable), 'Invalid filters %s' % filter
     assert isinstance(replacer, ReplacerWithMarkers), 'Invalid replacer %s' % replacer
     
     filtersWithPath = {}
     for resourceFilter in filters:
         assert isinstance(resourceFilter, Filter), 'Invalid filter %s' % filter
         assert isinstance(resourceFilter.filter, IAclFilter), \
         'Invalid filter object %s for resource filter %s' % (resourceFilter.filter, resourceFilter)
         typeService = typeFor(resourceFilter.filter)
         assert isinstance(typeService, TypeService), \
         'Invalid filter %s, it needs to be mapped as a REST service' % resourceFilter.filter
         pathAndMarkers = self._cacheFilters.get(typeService)
         if not pathAndMarkers:
             nodes = findNodesFor(self.resourcesRoot, typeService, 'isAllowed')
             if not nodes:
                 log.error('The filter service %s cannot be located in the resources tree', typeService)
                 continue
             if len(nodes) > 1:
                 log.error('To many nodes for service %s in the resources tree, don\'t know which one to use', typeService)
                 continue
             node = nodes[0]
             assert isinstance(node, Node)
             path = pathForNode(node)
             assert isinstance(path, Path)
             
             if __debug__:
                 # Just checking that the properties are ok
                 propertyTypes = propertyTypesOf(path, node.get)
                 assert len(propertyTypes) == 2, 'Invalid path %s for filter' % path
                 indexAuth = propertyTypes.index(resourceFilter.authenticated)
                 assert indexAuth >= 0, 'Invalid authenticated %s for path %s' % (resourceFilter.authenticated, path)
                 indexRsc = propertyTypes.index(resourceFilter.resource)
                 assert indexRsc >= 0, 'Invalid resource %s for path %s' % (resourceFilter.resource, path)
                 assert indexAuth < indexRsc, 'Invalid path %s, improper order for types' % path
             
             markerAuth = markerFor(resourceFilter.authenticated)
             replacer.register((markerAuth, '*'))
             pathMarked = '/'.join(path.toPaths(self.converterPath, replacer))
             pathAndMarkers = self._cacheFilters[typeService] = (pathMarked, {resourceFilter.authenticated: markerAuth})
             
         filtersWithPath[resourceFilter.resource] = pathAndMarkers
     return filtersWithPath
Пример #3
0
    def processFilter(self, rfilter, provider, marker, encoder):
        '''
        Process the provided filter.
        
        @param rfilter: Filter
            The resource filter to process.
        @param provider: callable|None
            The callable used in solving the authenticated values.
        @param marker: string
            The resource marker to place in the filter path, this marker is used to identify the group in the gateway pattern.
        @param encoder: IEncoderPath
            The encoder path to be used for the gateways resource paths and patterns.
        @return: string|None
            The marked filter path, None if the filter is invalid.
        '''
        assert isinstance(rfilter, Filter), 'Invalid filter %s' % rfilter
        assert isinstance(
            rfilter.filter,
            IAclFilter), 'Invalid filter %s of %s' % (rfilter.filter, rfilter)
        typeService = typeFor(rfilter.filter)
        assert isinstance(
            typeService, TypeService
        ), 'Invalid filter %s, is not a REST service' % rfilter.filter
        assert isinstance(marker, str), 'Invalid marker %s' % marker
        assert isinstance(encoder,
                          IEncoderPath), 'Invalid encoder path %s' % encoder

        path = self._cacheFilters.get(typeService)
        if not path:
            nodes = findNodesFor(self.resourcesRoot, typeService, 'isAllowed')
            if not nodes:
                log.error(
                    'The filter service %s cannot be located in the resources tree',
                    typeService)
                return
            if len(nodes) > 1:
                log.error(
                    'To many nodes for service %s in the resources tree, don\'t know which one to use',
                    typeService)
                return

            node = nodes[0]
            assert isinstance(node, Node)
            path = pathForNode(node)

            if __debug__:
                # Just checking that the properties are ok
                propertyTypes = propertyTypesOf(path, node.get)
                assert len(
                    propertyTypes) == 2, 'Invalid path %s for filter' % path
                indexAuth = propertyTypes.index(rfilter.authenticated)
                assert indexAuth >= 0, 'Invalid authenticated %s for path %s' % (
                    rfilter.authenticated, path)
                indexRsc = propertyTypes.index(rfilter.resource)
                assert indexRsc >= 0, 'Invalid resource %s for path %s' % (
                    rfilter.resource, path)
                assert indexAuth < indexRsc, 'Invalid path %s, improper order for types' % path

        assert isinstance(path, Path), 'Invalid path %s' % path
        if provider:
            assert callable(
                provider), 'Invalid authenticated provider %s' % provider
            valueAuth = provider(rfilter.authenticated)
        else:
            valueAuth = None
        if valueAuth is None:
            log.error(
                'The filter service %s has not authenticated value for %s',
                typeService, rfilter.authenticated)
            return

        return encoder.encode(path,
                              invalid=ReplacerWithMarkers().register(
                                  (valueAuth, marker)),
                              quoted=False)