Exemplo n.º 1
0
    def delete(self, username, reponame):
        # Check whether the key exists and if maybe the last change already is
        # a delete, else insert a `CSet.DELETE` entry without any blob data.

        key = self.get_query_argument("key")
        update = self.get_query_argument("update", "false") == "true"
        repo = revision_logic.get_repo(username, reponame)
        commit_message = self.get_query_argument("m", None)

        if username != self.current_user.name:
            raise HTTPError(reason="Unauthorized update: third party repo.", status_code=403)
        if not key:
            raise HTTPError(reason="Missing argument 'key'.", status_code=400)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        datestr = self.get_query_argument("datetime", None)
        ts = datestr and date(datestr, QSDATEFMT) or now()

        if update:
            # When update-param is set and the ts is the exact one of an existing cset (ts does not need to be increasing)
            if revision_logic.get_cset_at_ts(repo, key, ts):
                revision_logic.remove_revision(repo, key, ts)
                self.finish()
                return
            else:
                raise HTTPError(reason="No memento exists for given timestamp, when 'update' is set this must apply.", status_code=400)
        else:
            try:
                revision_logic.save_revision_delete(repo, key, ts)
            except LookupError:
                raise HTTPError(reason="Resource does not exist at given time.", status_code=404)
            else:
                if commit_message:
                    revision_logic.add_commit_message(repo, key, ts, commit_message.replace('\n', '. ').replace('\r', '. '))
Exemplo n.º 2
0
    def put(self, username, reponame):
        # Create a new revision of the resource specified by `key`.
        fmt = self.request.headers.get("Content-Type", "application/n-triples")
        key = self.get_query_argument("key", None)
        commit_message = self.get_query_argument("m", None)

        # force = self.get_query_argument("force", None)
        # replace = self.get_query_argument("replace", None)

        if username != self.current_user.name:
            raise HTTPError(reason="Unauthorized update: third party repo.", status_code=403)
        if not key:
            raise HTTPError(reason="Missing argument 'key'.", status_code=400)

        repo = revision_logic.get_repo(username, reponame)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        datestr = self.get_query_argument("datetime", None)
        ts = datestr and date(datestr, QSDATEFMT) or now()


        # Parse and normalize into a set of N-Quad lines
        try:
            stmts = revision_logic.parse(self.request.body, fmt)
        except RedlandError, e:
            # TODO decide about error code. This is actual a client side error (4XX), but also not a bad request as such
            raise HTTPError(reason="Error while parsing payload: " + e.value, status_code=500)
Exemplo n.º 3
0
    def head(self, username, reponame):
    
        timemap = self.get_query_argument("timemap", "false") == "true"
        index = self.get_query_argument("index", "false") == "true"
        key = self.get_query_argument("key", None)
    
        if (index and timemap) or (index and key) or (timemap and not key):
            raise HTTPError(reason="Invalid arguments.", status_code=400)

        if self.get_query_argument("datetime", None):
            datestr = self.get_query_argument("datetime")
            try:
                ts = date(datestr, QSDATEFMT)
            except ValueError:
                raise HTTPError(reason="Invalid format of datetime param.", status_code=400)
        elif "Accept-Datetime" in self.request.headers:
            datestr = self.request.headers.get("Accept-Datetime")
            ts = date(datestr, RFC1123DATEFMT)
        else:
            ts = now()

        #load repo
        repo = revision_logic.get_repo(username, reponame)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)


        if key and not timemap:
            self.__get_revision(repo, key, ts, True)
        elif key and timemap:
            self.__get_timemap(repo, key, True)
        else:
            raise HTTPError(reason="Malformed HEAD request.", status_code=400)
Exemplo n.º 4
0
    def delete(self, username, reponame):
        if username != self.current_user.name:
            raise HTTPError(reason="Unauthorized: Not your Repo", status_code=403)

        key = self.get_query_argument("key")
        update = self.get_query_argument("update", "false") == "true"
        repo = revision_logic.get_repo(username, reponame)

        if not key:
            raise HTTPError(reason="Missing argument 'key'.", status_code=400)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        datestr = self.get_query_argument("datetime", None)
        ts = date(datestr, QSDATEFMT) or now()

        if update:
            # When update-param is set and the ts is the exact one of an existing cset (ts does not need to be increasing)
            if revision_logic.get_cset_at_ts(repo, key, ts):
                revision_logic.remove_revision(repo, key, ts)
                self.finish()
                return
            else:
                raise HTTPError(
                    reason="No memento exists for given timestamp. When 'update' is set this must apply",
                    status_code=400,
                )
Exemplo n.º 5
0
    def get(self, username, reponame):
        timemap = self.get_query_argument("timemap", "false") == "true"
        index = self.get_query_argument("index", "false") == "true"
        key = self.get_query_argument("key", None)
        delta = self.get_query_argument("delta", "false") == "true"
        # if delta is not True but there is a delta param, check if it is a valid ts. 
        if self.get_query_argument("delta", False) and not delta:
            datestr = self.get_query_argument("delta")
            try:
                delta_ts = date(datestr, QSDATEFMT)
            except ValueError:
                raise HTTPError(reason="Invalid format of delta timestamp", status_code=400)
        else:
            delta_ts = None

        if (index and timemap) or (index and key) or (timemap and not key):
            raise HTTPError(reason="Invalid arguments.", status_code=400)

        if self.get_query_argument("datetime", None):
            datestr = self.get_query_argument("datetime")
            try:
                ts = date(datestr, QSDATEFMT)
            except ValueError:
                raise HTTPError(reason="Invalid format of datetime param", status_code=400)
        elif "Accept-Datetime" in self.request.headers:
            datestr = self.request.headers.get("Accept-Datetime")
            try:
                ts = date(datestr, RFC1123DATEFMT)
            except ValueError:
                raise HTTPError(reason="Invalid format of datetime in Header-Field Accept-Datetime ", status_code=400)
        else:
            ts = now()

        #load repo
        repo = revision_logic.get_repo(username, reponame)
        if repo == None:
            raise HTTPError(reason="Repo not found.", status_code=404)

        if key and not timemap and not delta and not delta_ts:
            self.__get_revision(repo, key, ts)
            # # currently no need to query next and prev through api. Link-Field in Header should contain them
            # if self.get_query_argument("next", None) == "true":
            #     self.__get_next_memento(repo,key,ts)
            # elif self.get_query_argument("prev", None) == "true":
            #     self.__get_prev_memento(repo,key,ts)
            # else:
            #     self.__get_revision(repo, key, ts)
        elif key and timemap:
            self.__get_timemap(repo, key)
        elif key and delta:
            self.__get_delta_of_memento(repo, key, ts)
        elif key and delta_ts:
            self.__get_delta_between_mementos(repo, key, ts, delta_ts)
        elif index:
            self.__get_index(repo, ts)
        else:
            raise HTTPError(reason="Missing arguments.", status_code=400)
Exemplo n.º 6
0
 def post(self, username, reponame):
     try:
         repo = revision_logic.get_repo(username, reponame)
         if repo == None:
             raise HTTPError(reason="Repo not found.", status_code=404)
         if username != self.current_user.name:
             raise HTTPError(reason="Unauthorized edit: third party repo.", status_code=403)
         else:
             if self.get_argument("description", None):
                 repo.desc = self.get_argument("description", None)
             repo.private = self.get_argument("private", "false") == "true"
             repo.save()
             self.redirect(self.reverse_url("web:repo", username, reponame))
     except:
         raise HTTPError(reason="Some exception occured.", status_code=404)
Exemplo n.º 7
0
 def post(self, username, reponame):
     verify = self.get_argument("verify", None)
     try:
         repo = revision_logic.get_repo(username, reponame)
         if repo == None:
             raise HTTPError(reason="Repo not found.", status_code=404)
         if username != self.current_user.name:
             raise HTTPError(reason="Unauthorized delete: third party repo.", status_code=403)
         if repo.name == verify:
             revision_logic.remove_repo(repo)
             self.redirect(self.reverse_url("web:user", self.current_user.name))
         else:
             raise HTTPError(501)
     except:
         raise HTTPError(reason="Some exception occured.", status_code=404)
Exemplo n.º 8
0
 def post(self, username, reponame):
     user = self.current_user
     verify = self.get_argument("verify", None)
     logger.info(username)
     logger.info(reponame)
     logger.info(verify)
     try:
         repo = revision_logic.get_repo(username, reponame)
         if repo == None:
             raise HTTPError(reason="Repo not found.", status_code=404)
         logger.info(repo.name)
         if (repo.name == verify):
             revision_logic.remove_repo(repo)
             self.redirect(self.reverse_url("web:user", user.name))
         else:
             raise HTTPError(501)
     except:
       raise HTTPError(reason="Some exception occured.", status_code=404)