Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
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)
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)