From: Brian Warner Date: Wed, 4 Feb 2009 02:22:48 +0000 (-0700) Subject: webapi: add verifycap (spelled 'verify_url') to the t=json output on files and direct... X-Git-Tag: allmydata-tahoe-1.3.0~97 X-Git-Url: https://git.rkrishnan.org/specifications//%22%3C?a=commitdiff_plain;h=4e572a5f2491cdf845536f8f5a95404df71051bc;p=tahoe-lafs%2Ftahoe-lafs.git webapi: add verifycap (spelled 'verify_url') to the t=json output on files and directories. Closes #559. --- diff --git a/docs/frontends/webapi.txt b/docs/frontends/webapi.txt index 86da8807..46eaf77f 100644 --- a/docs/frontends/webapi.txt +++ b/docs/frontends/webapi.txt @@ -377,6 +377,7 @@ GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json : [ "filenode", { "ro_uri": file_uri, + "verify_uri": verify_uri, "size": bytes, "mutable": false, "metadata": {"ctime": 1202777696.7564139, @@ -396,6 +397,7 @@ GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json [ "dirnode", { "rw_uri": read_write_uri, "ro_uri": read_only_uri, + "verify_uri": verify_uri, "mutable": true, "children": { "foo.txt": [ "filenode", { "ro_uri": uri, @@ -422,7 +424,9 @@ GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json that is stored on the directory edge). Then the rw_uri field will be present in the information about a directory - if and only if you have read-write access to that directory, + if and only if you have read-write access to that directory. The verify_uri + field will be presend if and only if the object has a verify-cap + (non-distributed LIT files do not have verify-caps). === Attaching an existing File or Directory by its read- or write- cap === diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 5c40ba3e..50ca7a82 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -173,6 +173,8 @@ class FakeMutableFileNode: return self.my_uri.get_readonly() def get_readonly_uri(self): return self.my_uri.get_readonly().to_string() + def get_verify_cap(self): + return self.my_uri.get_verify_cap() def is_readonly(self): return self.my_uri.is_readonly() def is_mutable(self): diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 5967e41d..381441e8 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -146,12 +146,14 @@ class WebMixin(object): self._foo_node = foo self._foo_uri = foo.get_uri() self._foo_readonly_uri = foo.get_readonly_uri() + self._foo_verifycap = foo.get_verify_cap().to_string() # NOTE: we ignore the deferred on all set_uri() calls, because we # know the fake nodes do these synchronously self.public_root.set_uri(u"foo", foo.get_uri()) self.BAR_CONTENTS, n, self._bar_txt_uri = self.makefile(0) foo.set_uri(u"bar.txt", self._bar_txt_uri) + self._bar_txt_verifycap = n.get_verify_cap().to_string() foo.set_uri(u"empty", res[3][1].get_uri()) sub_uri = res[4][1].get_uri() @@ -216,6 +218,7 @@ class WebMixin(object): self.failIf(data[1]["mutable"]) self.failIf("rw_uri" in data[1]) # immutable self.failUnlessEqual(data[1]["ro_uri"], self._bar_txt_uri) + self.failUnlessEqual(data[1]["verify_uri"], self._bar_txt_verifycap) self.failUnlessEqual(data[1]["size"], len(self.BAR_CONTENTS)) def failUnlessIsFooJSON(self, res): @@ -227,6 +230,7 @@ class WebMixin(object): self.failUnless("rw_uri" in data[1]) # mutable self.failUnlessEqual(data[1]["rw_uri"], self._foo_uri) self.failUnlessEqual(data[1]["ro_uri"], self._foo_readonly_uri) + self.failUnlessEqual(data[1]["verify_uri"], self._foo_verifycap) kidnames = sorted([unicode(n) for n in data[1]["children"]]) self.failUnlessEqual(kidnames, @@ -242,6 +246,8 @@ class WebMixin(object): self.failUnlessEqual(kids[u"bar.txt"][0], "filenode") self.failUnlessEqual(kids[u"bar.txt"][1]["size"], len(self.BAR_CONTENTS)) self.failUnlessEqual(kids[u"bar.txt"][1]["ro_uri"], self._bar_txt_uri) + self.failUnlessEqual(kids[u"bar.txt"][1]["verify_uri"], + self._bar_txt_verifycap) self.failUnlessEqual(kids[u"bar.txt"][1]["metadata"]["ctime"], self._bar_txt_metadata["ctime"]) self.failUnlessEqual(kids[u"n\u00fc.txt"][1]["ro_uri"], diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index a4c401f6..2f00f088 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -671,6 +671,9 @@ def DirectoryJSONMetadata(ctx, dirnode): kiddata[1]["ro_uri"] = ro_uri if rw_uri: kiddata[1]["rw_uri"] = rw_uri + verifycap = childnode.get_verify_cap() + if verifycap: + kiddata[1]['verify_uri'] = verifycap.to_string() kiddata[1]['mutable'] = childnode.is_mutable() kids[name] = kiddata if dirnode.is_readonly(): @@ -684,6 +687,9 @@ def DirectoryJSONMetadata(ctx, dirnode): contents['ro_uri'] = dro_uri if drw_uri: contents['rw_uri'] = drw_uri + verifycap = dirnode.get_verify_cap() + if verifycap: + contents['verify_uri'] = verifycap.to_string() contents['mutable'] = dirnode.is_mutable() data = ("dirnode", contents) return simplejson.dumps(data, indent=1) + "\n" diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index 36f89221..a5a6976d 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -432,6 +432,9 @@ def FileJSONMetadata(ctx, filenode): data[1]['ro_uri'] = ro_uri if rw_uri: data[1]['rw_uri'] = rw_uri + verifycap = filenode.get_verify_cap() + if verifycap: + data[1]['verify_uri'] = verifycap.to_string() data[1]['mutable'] = filenode.is_mutable() return text_plain(simplejson.dumps(data, indent=1) + "\n", ctx)