Create the /private hierarchy

This commit is contained in:
Jean-Paul Calderone 2019-03-21 15:00:57 -04:00
parent 2877c9b3c1
commit 5f4f8d9dbb
3 changed files with 36 additions and 4 deletions

View File

@ -12,6 +12,9 @@ import eliot
from allmydata.util.hashutil import timing_safe_compare from allmydata.util.hashutil import timing_safe_compare
from .common import humanize_failure from .common import humanize_failure
from twisted.web.resource import (
Resource,
)
class TokenAuthenticatedWebSocketServerProtocol(WebSocketServerProtocol): class TokenAuthenticatedWebSocketServerProtocol(WebSocketServerProtocol):
@ -81,3 +84,9 @@ def create_log_streaming_resource(client):
factory.tahoe_client = client factory.tahoe_client = client
factory.protocol = TokenAuthenticatedWebSocketServerProtocol factory.protocol = TokenAuthenticatedWebSocketServerProtocol
return WebSocketResource(factory) return WebSocketResource(factory)
def create_log_resources(client):
logs = Resource()
logs.putChild(b"v1", create_log_streaming_resource(client))
return logs

View File

@ -0,0 +1,20 @@
from __future__ import (
print_function,
unicode_literals,
absolute_import,
division,
)
from twisted.web.resource import (
Resource,
)
from .logs import (
create_log_resources,
)
def create_private_tree(client):
private = Resource()
private.putChild(b"logs", create_log_resources(client))
return private

View File

@ -25,8 +25,9 @@ from allmydata.web.common import (
render_time, render_time,
render_time_attr, render_time_attr,
) )
from allmydata.web.logs import create_log_streaming_resource from allmydata.web.private import (
create_private_tree,
)
class URIHandler(RenderMixin, rend.Page): class URIHandler(RenderMixin, rend.Page):
# I live at /uri . There are several operations defined on /uri itself, # I live at /uri . There are several operations defined on /uri itself,
@ -169,8 +170,10 @@ class Root(MultiFormatPage):
# handler for "/magic_folder" URIs # handler for "/magic_folder" URIs
self.child_magic_folder = magic_folder.MagicFolderWebApi(client) self.child_magic_folder = magic_folder.MagicFolderWebApi(client)
# handler for "/logs_v1" URIs # Handler for everything beneath "/private", an area of the resource
self.child_logs_v1 = create_log_streaming_resource(client) # hierarchy which is only accessible with the private per-node API
# auth token.
self.child_private = create_private_tree(client)
self.child_file = FileHandler(client) self.child_file = FileHandler(client)
self.child_named = FileHandler(client) self.child_named = FileHandler(client)