Esempio n. 1
0
 def secure_render_recursive(item):
     try:
         return IHttpRestView(item).render_recursive(request, depth - 1)
     except Unauthorized:
         permissions = effective_perms(get_interaction(item), item)
         if 'view' in permissions:
             return dict(access='denied', permissions=permissions,
                         __type__=type(removeSecurityProxy(item)).__name__)
Esempio n. 2
0
 def secure_render_recursive(item):
     try:
         return IHttpRestView(item).render_recursive(request, depth - 1)
     except Unauthorized:
         permissions = effective_perms(get_interaction(item), item)
         if 'view' in permissions:
             return dict(access='denied',
                         permissions=permissions,
                         __type__=type(
                             removeSecurityProxy(item)).__name__)
Esempio n. 3
0
    def render_PUT(self, request):
        """ Converts arguments into command-line counterparts and executes the omsh command.

        Parameters passed as 'arg' are converted into positional arguments, others are converted into
        named parameters:

            PUT /bin/ls?arg=/some/path&arg=/another/path&-l&--recursive

        thus translates to:

            /bin/ls /some/path /another/path -l --recursive

        Allows blocking (synchronous) and non-blocking operation using the 'asynchronous' parameter (any
        value will trigger it). Synchronous operation requires two threads to function.
        """
        def named_args_filter_and_flatten(nargs):
            for name, vallist in nargs:
                if name not in ('arg', 'asynchronous'):
                    for val in vallist:
                        yield name
                        yield val

        def convert_args(args):
            tokenized_args = args.get('arg', [])
            return tokenized_args + list(
                named_args_filter_and_flatten(args.items()))

        protocol = DetachedProtocol()
        protocol.interaction = get_interaction(
            self.context) or request.interaction

        args = convert_args(request.args)
        args = filter(None, args)
        cmd = self.context.cmd(protocol)
        # Setting write_buffer to a list makes command save the output to the buffer too
        cmd.write_buffer = []
        d0 = defer.Deferred()

        try:
            pid = threads.blockingCallFromThread(
                reactor, cmd.register, d0, args,
                '%s %s' % (request.path, args))
        except ArgumentParsingError, e:
            raise BadRequest(str(e))
Esempio n. 4
0
    def render_PUT(self, request):
        """ Converts arguments into command-line counterparts and executes the omsh command.

        Parameters passed as 'arg' are converted into positional arguments, others are converted into
        named parameters:

            PUT /bin/ls?arg=/some/path&arg=/another/path&-l&--recursive

        thus translates to:

            /bin/ls /some/path /another/path -l --recursive

        Allows blocking (synchronous) and non-blocking operation using the 'asynchronous' parameter (any
        value will trigger it). Synchronous operation requires two threads to function.
        """

        def named_args_filter_and_flatten(nargs):
            for name, vallist in nargs:
                if name not in ('arg', 'asynchronous'):
                    for val in vallist:
                        yield name
                        yield val

        def convert_args(args):
            tokenized_args = args.get('arg', [])
            return tokenized_args + list(named_args_filter_and_flatten(args.items()))

        protocol = DetachedProtocol()
        protocol.interaction = get_interaction(self.context) or request.interaction

        args = convert_args(request.args)
        args = filter(None, args)
        cmd = self.context.cmd(protocol)
        # Setting write_buffer to a list makes command save the output to the buffer too
        cmd.write_buffer = []
        d0 = defer.Deferred()

        try:
            pid = threads.blockingCallFromThread(reactor, cmd.register, d0, args,
                                                 '%s %s' % (request.path, args))
        except ArgumentParsingError, e:
            raise BadRequest(str(e))
Esempio n. 5
0
    def render_GET(self, request):
        if not request.interaction.checkPermission('view', self.context):
            raise NotFound

        data = model_to_dict(self.context)

        data['id'] = self.context.__name__
        data['__type__'] = type(removeSecurityProxy(self.context)).__name__
        try:
            data['url'] = ILocation(self.context).get_url()
        except Unauthorized:
            data['url'] = ''

        interaction = get_interaction(self.context)
        data['permissions'] = effective_perms(interaction, self.context) if interaction else []

        # XXX: simplejson can't serialize sets
        if 'tags' in data:
            data['tags'] = list(data['tags'])

        return data
Esempio n. 6
0
    def render_GET(self, request):
        if not request.interaction.checkPermission('view', self.context):
            raise NotFound

        data = model_to_dict(self.context)

        data['id'] = self.context.__name__
        data['__type__'] = type(removeSecurityProxy(self.context)).__name__
        try:
            data['url'] = ILocation(self.context).get_url()
        except Unauthorized:
            data['url'] = ''

        interaction = get_interaction(self.context)
        data['permissions'] = effective_perms(
            interaction, self.context) if interaction else []

        # XXX: simplejson can't serialize sets
        if 'tags' in data:
            data['tags'] = list(data['tags'])

        return data