Esempio n. 1
0
    def traces(self, request, *args, **kwargs):
        obj = self.get_object()
        if obj.handler['type'] == ScheduleEventHandlerDependency.socket_type:
            viewname = 'schedule-trace-list'
        else:
            viewname = 'trigger-trace-list'

        return run_api_view(viewname,
                            (request.instance.name, obj.handler['object_pk']),
                            request, **kwargs)
Esempio n. 2
0
    def run_channel_view(self, request, endpoint, channel, viewname='channel-subscribe', **kwargs):
        request._request.GET = request.query_params.copy()

        try:
            room = SocketEndpoint.create_channel_room_name(channel, request)
        except KeyError:
            if '{user}' in channel:
                raise PermissionDenied()
            raise ChannelFormatKeyError()

        if len(room) > settings.CHANNEL_MAX_ROOM_LENGTH:
            raise ChannelTooLong(settings.CHANNEL_MAX_ROOM_LENGTH)

        request.query_params['room'] = room
        return run_api_view(viewname, (request.instance.name, Channel.DEFAULT_NAME),
                            request, **kwargs)
Esempio n. 3
0
    def process(self, request, *args, **kwargs):
        path = escape_uri_path(request.path)

        try:
            hosting = Cached(Hosting,
                             kwargs=self.get_hosting_search_kwargs(
                                 domain=kwargs.get('domain'))).get()
        except Hosting.DoesNotExist:
            return self.create_404_response()

        if hosting.auth and not self.check_auth(request, hosting):
            # Either they did not provide an authorization header or
            # something in the authorization attempt failed. Send a 401
            # back to them to ask them to authenticate.
            response = HttpResponse(status=status.HTTP_401_UNAUTHORIZED)
            response['WWW-Authenticate'] = 'Basic realm="Restricted"'
            return response

        for pattern, socket in hosting.config.get('sockets_mapping', []):
            if glob(pattern, path):
                request.version = 'v2'
                return run_api_view('socket-endpoint-endpoint',
                                    (request.instance.name, socket), request)

        if request.method != 'GET':
            self.http_method_not_allowed(request)

        # Strip '/' prefix for further processing.
        if path.endswith(
                '/'
        ):  # jekyll like: '/about/' we should find path '/about/index.html' in such case;
            path = '{}{}'.format(path, self.DEFAULT_FILE)
        path = path.lstrip('/')
        query = iri_to_uri(request.META.get('QUERY_STRING', ''))

        try:
            hosting_file = HostingFile.get_file(hosting=hosting, path=path)
            return self.get_accel_response(
                request,
                Hosting.get_storage().internal_url(
                    hosting_file.file_object.name), self.EMPTY_404_KEY, query)
        except HostingFile.DoesNotExist:
            return self.handle_missing_file(request, hosting, query, path)
Esempio n. 4
0
 def run_user_api_view(self, request, **kwargs):
     return run_api_view('user-list', (request.instance.name, ), request,
                         **kwargs)
Esempio n. 5
0
 def run_data_api_view(self, request, **kwargs):
     return run_api_view('dataobject-list',
                         (request.instance.name, self.object.klass.name),
                         request, **kwargs)