From a676eb0b839806ec90df94681713a62c31ba9733 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 7 Oct 2021 15:54:53 -0400 Subject: [PATCH] Syncfile option passing to client Provide a mechanism for a syncfiles to indicate options to the client. This will be used for owner=, group=, and permissions= options. --- confluent_server/confluent/selfservice.py | 3 ++- confluent_server/confluent/syncfiles.py | 31 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index 14e6ae5e..2ed02656 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -343,7 +343,8 @@ def handle_request(env, start_response): return if 'GET' == operation: status, output = syncfiles.get_syncresult(nodename) - start_response(status, ()) + output = json.dumps(output) + start_response(status, (('Content-Type', 'application/json'))) yield output return elif env['PATH_INFO'].startswith('/self/remoteconfig/status'): diff --git a/confluent_server/confluent/syncfiles.py b/confluent_server/confluent/syncfiles.py index 53298c20..b279ff3c 100644 --- a/confluent_server/confluent/syncfiles.py +++ b/confluent_server/confluent/syncfiles.py @@ -36,6 +36,7 @@ class SyncList(object): self.replacemap = {} self.appendmap = {} self.mergemap = {} + self.optmap = {} with open(filename, 'r') as slfile: slist = slfile.read() entries = slist.split('\n') @@ -71,10 +72,32 @@ class SyncList(object): break else: continue + optparts = v.split() + v = optparts[0] + optparts = optparts[1:] else: - k = ent + kparts = [] + optparts = [] + currparts = kparts + for part in ent.split(): + if part[0] == '(': + currparts = optparts + currparts.append(part) + k = ' '.join(kparts) v = None + entopts = {} + if optparts: + if optparts[0][0] != '(' or optparts[-1][-1] != ')': + raise Exception("Unsupported syntax in syncfile: " + ent) + opts = ','.join(optparts) + opts = [1:-1] + for opt in opts.split(','): + optname, optval = opt.split('=') + entopts[optname] = optval currmap[k] = v + targ = v if v else k + for f in targ.split(): + self.optmap[f] = entopts def sync_list_to_node(sl, node, suffixes): @@ -119,7 +142,11 @@ def sync_list_to_node(sl, node, suffixes): raise finally: shutil.rmtree(targdir) - return output + retval = { + 'options': sl.optmap, + 'output': output, + } + return output # need dictionary with output and options def stage_ent(currmap, ent, targdir, appendexist=False): dst = currmap[ent]