Esempio n. 1
0
    def deferred_render_GET(self, request):
        usage = registry.findUsage(httpObjectCategoryName, 'GET',
                                   ObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        showAbout = util.getBooleanArg(request, showAboutArg,
                                       usage.arguments[showAboutArg].default)

        objectInfo = yield self.facadeClient.getObject(self.session,
                                                       self.objectId,
                                                       showAbout)

        responseDict = {
            tagPathsArg: objectInfo.tagPaths,
        }
        if showAbout:
            if objectInfo.about:
                responseDict[aboutArg] = objectInfo.about.decode('utf-8')
            else:
                responseDict[aboutArg] = None

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 2
0
    def deferred_render_GET(self, request):
        """
        Return information about the object whose about value is given in the
        URI.

        @param request: The HTTP request.
        @return: A C{Deferred} that fires with the body of the response.
        """
        usage = registry.findUsage(httpAboutCategoryName, 'GET',
                                   AboutObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        # Note: we need to escape any double quotes in the about value so
        # that the query parser doesn't raise a syntax error.  See
        # https://bugs.edge.launchpad.net/fluiddb/+bug/802783
        query = '%s = "%s"' % (_aboutPath, self.about.replace('"', r'\"'))
        objectIds = yield self.facadeClient.resolveQuery(self.session, query)
        if objectIds:
            objectId = objectIds.pop()
        else:
            raise error.NoSuchObject()
        objectInfo = yield self.facadeClient.getObject(self.session,
                                                       objectId,
                                                       showAbout=False)
        responseDict = {
            _tagPathsArg: objectInfo.tagPaths,
            'id': objectId,
        }
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 3
0
    def deferred_render_GET(self, request):
        usage = registry.findUsage(httpObjectCategoryName, 'GET',
                                   ObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        showAbout = util.getBooleanArg(
            request, showAboutArg,
            usage.arguments[showAboutArg].default)

        objectInfo = yield self.facadeClient.getObject(
            self.session, self.objectId, showAbout)

        responseDict = {
            tagPathsArg: objectInfo.tagPaths,
        }
        if showAbout:
            if objectInfo.about:
                responseDict[aboutArg] = objectInfo.about.decode('utf-8')
            else:
                responseDict[aboutArg] = None

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 4
0
    def deferred_render_POST(self, request):
        usage = registry.findUsage(httpObjectCategoryName, 'POST',
                                   ObjectsResource)
        dictionary = registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
        about = dictionary.get(aboutArg, '')

        objectId = yield self.facadeClient.createObject(
            session=self.session, about=about.encode('utf-8'))

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        # Return the location of the new object by its id.
        location = '%s://%s/%s/%s' % (
            proto, hostname, httpObjectCategoryName,
            # This is probably overkill
            urllib.quote(objectId.encode('utf-8')))

        responseDict = {'id': objectId, 'URI': location}
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 5
0
    def deferred_render_GET(self, request):
        # TODO: usages should be cached locally; lookup is expensive.
        usage = registry.findUsage(httpTagCategoryName, 'GET', TagsResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
        args = {
            returnDescriptionArg: util.getBooleanArg(
                request, returnDescriptionArg,
                usage.arguments[returnDescriptionArg].default),
        }

        ttag = yield self.facadeClient.getTag(
            self.session,
            sep.join(request.postpath),
            returnDescription=args[returnDescriptionArg])

        responseDict = {
            'id': ttag.objectId,
            'indexed': ttag.indexed,
        }
        if args[returnDescriptionArg]:
            responseDict['description'] = ttag.description

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 6
0
 def success(responseDict):
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     return body
Esempio n. 7
0
    def deferred_render_GET(self, request):
        # TODO: usages should be cached locally; lookup is expensive.
        usage = registry.findUsage(httpTagCategoryName, 'GET', TagsResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
        args = {
            returnDescriptionArg:
            util.getBooleanArg(request, returnDescriptionArg,
                               usage.arguments[returnDescriptionArg].default),
        }

        ttag = yield self.facadeClient.getTag(
            self.session,
            sep.join(request.postpath),
            returnDescription=args[returnDescriptionArg])

        responseDict = {
            'id': ttag.objectId,
            'indexed': ttag.indexed,
        }
        if args[returnDescriptionArg]:
            responseDict['description'] = ttag.description

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 8
0
    def deferred_render_POST(self, request):
        usage = registry.findUsage(httpObjectCategoryName, 'POST',
                                   ObjectsResource)
        dictionary = registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
        about = dictionary.get(aboutArg, '')

        objectId = yield self.facadeClient.createObject(
            session=self.session, about=about.encode('utf-8'))

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        # Return the location of the new object by its id.
        location = '%s://%s/%s/%s' % (
            proto,
            hostname,
            httpObjectCategoryName,
            # This is probably overkill
            urllib.quote(objectId.encode('utf-8')))

        responseDict = {'id': objectId, 'URI': location}
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 9
0
    def deferred_render_GET(self, request):
        """
        Return information about the object whose about value is given in the
        URI.

        @param request: The HTTP request.
        @return: A C{Deferred} that fires with the body of the response.
        """
        usage = registry.findUsage(httpAboutCategoryName, 'GET',
                                   AboutObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        # Note: we need to escape any double quotes in the about value so
        # that the query parser doesn't raise a syntax error.  See
        # https://bugs.edge.launchpad.net/fluiddb/+bug/802783
        query = '%s = "%s"' % (_aboutPath, self.about.replace('"', r'\"'))
        objectIds = yield self.facadeClient.resolveQuery(self.session, query)
        if objectIds:
            objectId = objectIds.pop()
        else:
            raise error.NoSuchObject()
        objectInfo = yield self.facadeClient.getObject(
            self.session, objectId, showAbout=False)
        responseDict = {
            _tagPathsArg: objectInfo.tagPaths,
            'id': objectId,
        }
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 10
0
 def deferred_render_GET(self, request):
     usage = registry.findUsage(httpObjectCategoryName, 'GET',
                                ObjectsResource)
     registry.checkRequest(usage, request)
     responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
     query = request.args['query'][0]
     results = yield self.facadeClient.resolveQuery(self.session, query)
     responseDict = {'ids': list(results)}
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     defer.returnValue(body)
Esempio n. 11
0
 def deferred_render_GET(self, request):
     usage = registry.findUsage(httpObjectCategoryName, 'GET',
                                ObjectsResource)
     registry.checkRequest(usage, request)
     responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
     query = request.args['query'][0]
     results = yield self.facadeClient.resolveQuery(self.session, query)
     responseDict = {'ids': list(results)}
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     defer.returnValue(body)
Esempio n. 12
0
    def deferred_render_GET(self, request):
        """Render a response to a C{GET} request to C{recent/users}

        @param request: A C{twisted.web.server.Request} specifying
            meta-information about the request.
        @return: A C{deferred} which fires with a JSON payload with the
            information about recent activity for the given user.
        """
        recentActivity = yield self.facadeClient.getRecentUserActivity(
            self.session, self.username)

        body = buildPayload('application/json', recentActivity)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', 'application/json')
        request.setResponseCode(http.OK)
        returnValue(body)
Esempio n. 13
0
    def deferred_render_GET(self, request):
        """Render a response to a C{GET} request to C{recent/users}

        @param request: A C{twisted.web.server.Request} specifying
            meta-information about the request.
        @return: A C{deferred} which fires with a JSON payload with the
            information about recent activity for the given user.
        """
        recentActivity = yield self.facadeClient.getRecentUserActivity(
            self.session, self.username)

        body = buildPayload('application/json', recentActivity)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', 'application/json')
        request.setResponseCode(http.OK)
        returnValue(body)
Esempio n. 14
0
 def deferred_render_GET(self, request):
     # TODO: usages should be cached locally; lookup is expensive.
     usage = registry.findUsage(httpUserCategoryName, 'GET',
                                ConcreteUserResource)
     registry.checkRequest(usage, request)
     responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
     tuser = yield self.facadeClient.getUser(self.session, self.username)
     responseDict = {
         'name': tuser.name,
         'role': tuser.role,
         'id': tuser.objectId,
     }
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     defer.returnValue(body)
Esempio n. 15
0
    def deferred_render_POST(self, request):
        usage = registry.findUsage(httpTagCategoryName, 'POST', TagsResource)
        dictionary = registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        parentNamespace = sep.join(request.postpath)
        name = dictionary['name']
        description = dictionary['description'] or ''
        indexed = dictionary['indexed']

        path = sep.join([parentNamespace, name.encode('utf-8')])

        objectId = yield self.facadeClient.createTag(
            session=self.session,
            parentNamespace=parentNamespace,
            name=name.encode('utf-8'),
            description=description.encode('utf-8'),
            indexed=indexed,
            # Always request a normal range. We don't let apps do anything
            # else yet.
            rangeType=TagRangeType.NORMAL_TYPE)

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        location = '%s://%s/%s/%s' % (
            proto, hostname, httpTagCategoryName,
            urllib.quote(path))

        responseDict = {
            'id': objectId,
            'URI': location,
        }
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 16
0
 def deferred_render_GET(self, request):
     # TODO: usages should be cached locally; lookup is expensive.
     usage = registry.findUsage(httpPermissionCategoryName, 'GET',
                                self.__class__)
     registry.checkRequest(usage, request)
     responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
     action = request.args[actionArg][0].lower()
     result = yield self.facadeClient.getPermission(
         self.session, self.category, action, sep.join(request.postpath))
     responseDict = {
         'policy': result.policy,
         'exceptions': list(result.exceptions),
     }
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     defer.returnValue(body)
Esempio n. 17
0
 def deferred_render_GET(self, request):
     # TODO: usages should be cached locally; lookup is expensive.
     usage = registry.findUsage(httpPermissionCategoryName, 'GET',
                                self.__class__)
     registry.checkRequest(usage, request)
     responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)
     action = request.args[actionArg][0].lower()
     result = yield self.facadeClient.getPermission(
         self.session, self.category, action, sep.join(request.postpath))
     responseDict = {
         'policy': result.policy,
         'exceptions': list(result.exceptions),
     }
     registry.checkResponse(responseType, responseDict, usage, request)
     body = payloads.buildPayload(responseType, responseDict)
     request.setHeader('Content-length', str(len(body)))
     request.setHeader('Content-type', responseType)
     request.setResponseCode(usage.successCode)
     defer.returnValue(body)
Esempio n. 18
0
    def deferred_render_POST(self, request):
        usage = registry.findUsage(httpTagCategoryName, 'POST', TagsResource)
        dictionary = registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        parentNamespace = sep.join(request.postpath)
        name = dictionary['name']
        description = dictionary['description'] or ''
        indexed = dictionary['indexed']

        path = sep.join([parentNamespace, name.encode('utf-8')])

        objectId = yield self.facadeClient.createTag(
            session=self.session,
            parentNamespace=parentNamespace,
            name=name.encode('utf-8'),
            description=description.encode('utf-8'),
            indexed=indexed,
            # Always request a normal range. We don't let apps do anything
            # else yet.
            rangeType=TagRangeType.NORMAL_TYPE)

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        location = '%s://%s/%s/%s' % (proto, hostname, httpTagCategoryName,
                                      urllib.quote(path))

        responseDict = {
            'id': objectId,
            'URI': location,
        }
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 19
0
    def deferred_render_GET(self, request):
        """Render a response to a C{GET} request to C{recent/objects}

        @param request: a C{twisted.web.server.Request} specifying
            meta-information about the request.
        @return: A C{deferred} which fires with a JSON payload with the
            information about recent activity for the given object.
        """
        usage = registry.findUsage('recent', 'GET',
                                   RecentObjectActivityResource)
        registry.checkRequest(usage, request)

        recentActivity = yield self.facadeClient.getRecentObjectActivity(
            self.session, self.objectID)

        body = buildPayload('application/json', recentActivity)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', 'application/json')
        request.setResponseCode(http.OK)
        returnValue(body)
Esempio n. 20
0
    def deferred_render_GET(self, request):
        """Render a response to a C{GET} request to C{recent/objects}

        @param request: a C{twisted.web.server.Request} specifying
            meta-information about the request.
        @return: A C{deferred} which fires with a JSON payload with the
            information about recent activity for the given object.
        """
        usage = registry.findUsage('recent', 'GET',
                                   RecentObjectActivityResource)
        registry.checkRequest(usage, request)

        recentActivity = yield self.facadeClient.getRecentObjectActivity(
            self.session, self.objectID)

        body = buildPayload('application/json', recentActivity)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', 'application/json')
        request.setResponseCode(http.OK)
        returnValue(body)
Esempio n. 21
0
    def deferred_render_POST(self, request):
        """
        Create an object whose about value is the one given in the URI
        and return information about its object id and location.

        @param request: The HTTP request.

        @return: A C{Deferred} that fires with the body of the response.
        """
        usage = registry.findUsage(httpAboutCategoryName, 'POST',
                                   AboutObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        objectId = yield self.facadeClient.createObject(
            session=self.session, about=self.about)

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        # Return the location of the new object by its id.
        location = '%s://%s/%s/%s' % (
            proto, hostname, httpObjectCategoryName,
            urllib.quote(objectId.encode('utf-8')))

        responseDict = {
            'id': objectId,
            'URI': location,
        }

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 22
0
    def deferred_render_POST(self, request):
        """
        Create an object whose about value is the one given in the URI
        and return information about its object id and location.

        @param request: The HTTP request.

        @return: A C{Deferred} that fires with the body of the response.
        """
        usage = registry.findUsage(httpAboutCategoryName, 'POST',
                                   AboutObjectResource)
        registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        objectId = yield self.facadeClient.createObject(session=self.session,
                                                        about=self.about)

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        # Return the location of the new object by its id.
        location = '%s://%s/%s/%s' % (proto, hostname, httpObjectCategoryName,
                                      urllib.quote(objectId.encode('utf-8')))

        responseDict = {
            'id': objectId,
            'URI': location,
        }

        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)
Esempio n. 23
0
    def deferred_render_POST(self, request):
        usage = registry.findUsage(httpUserCategoryName, 'POST', UsersResource)
        dictionary = registry.checkRequest(usage, request)
        responseType = usage.getResponsePayloadTypeFromAcceptHeader(request)

        username = dictionary['username']
        name = dictionary.get('name', username)
        password = dictionary['password']
        email = dictionary['email']

        objectId = yield self.facadeClient.createUserWithPassword(
            session=self.session,
            username=username.encode('utf-8'),
            password=password.encode('utf-8'),
            name=name.encode('utf-8'),
            email=email.encode('utf-8'))

        if request.isSecure():
            proto = "https"
        else:
            proto = "http"
        hostname = request.getRequestHostname()

        location = '%s://%s/%s/%s' % (
            proto, hostname, httpUserCategoryName,
            urllib.quote(username.encode('utf-8')))

        responseDict = {
            'id': objectId,
            'URI': location,
        }
        registry.checkResponse(responseType, responseDict, usage, request)
        body = payloads.buildPayload(responseType, responseDict)
        request.setHeader('Content-length', str(len(body)))
        request.setHeader('Content-type', responseType)
        request.setHeader('Location', location)
        request.setResponseCode(usage.successCode)
        defer.returnValue(body)