Skip to content

Commit

Permalink
fix(provisioner): allow for mount points as well
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 5, 2020
1 parent 82f6f0d commit 7350220
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/cosmic-swingset/provisioning-server/src/ag_pserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ def errReceived(self, data):
def processEnded(self, reason):
self.deferred.callback((reason.value.exitCode, self.output, self.error))

class RootResource(resource.Resource):
def __init__(self, home):
class StackedResource(resource.Resource):
def __init__(self, stack):
super().__init__()
self.wwwroot = static.File(wwwroot(home))
self.htmldir = static.File(htmldir)
self.stack = stack

def getChildWithDefault(self, *args):
res = super().getChildWithDefault(*args)
if isinstance(res, resource.NoResource):
res = self.wwwroot.getChildWithDefault(*args)
if isinstance(res, resource.NoResource):
res = self.htmldir.getChildWithDefault(*args)
i = 0
while isinstance(res, resource.NoResource) and i < len(self.stack):
res = self.stack[i].getChildWithDefault(*args)
i += 1
return res

def wwwroot(home):
Expand Down Expand Up @@ -352,11 +351,11 @@ def render_GET(self, req):

def run_server(reactor, o):
print("dir is", __file__)
root = RootResource(o['home'])
provroot = static.File(htmldir)
provisioner = Provisioner(reactor, o)
root.putChild(b"", provisioner)
root.putChild(b"index.html", provisioner)
root.putChild(b"request-code", RequestCode(reactor, o))
provroot.putChild(b"", provisioner)
provroot.putChild(b"index.html", provisioner)
provroot.putChild(b"request-code", RequestCode(reactor, o))

# Prefix the mountpoints.
revpaths = o['mountpoint'].split('/')
Expand All @@ -365,8 +364,13 @@ def run_server(reactor, o):
# print('mount root under ' + dir)
if dir != '':
r = resource.Resource()
r.putChild(dir.encode('utf-8'), root)
root = r
r.putChild(dir.encode('utf-8'), provroot)
provroot = r

# Override the paths.
root = StackedResource([static.File(wwwroot(o['home'])), provroot])
if o['mountpoint'] == '/':
root.putChild(b"", provisioner)

# Display the JSON config.
root.putChild(b"network-config", ConfigJSON(o))
Expand Down

0 comments on commit 7350220

Please sign in to comment.