|
@@ -0,0 +1,61 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+
|
|
|
+# Given a manifest.yaml file, a pubkeys.yaml file, and (optionally) a
|
|
|
+# list of nodes to include, generate the config.json file to give to
|
|
|
+# each of the nodes. If the list of nodes is missing, include all nodes
|
|
|
+# in the manifest.yaml file. It is an error to include a node that is
|
|
|
+# missing from either the manifest.yaml or the pubkeys.yaml files.
|
|
|
+
|
|
|
+# Usage: mkconfig [-m manifest.yaml] [-p pubkeys.yaml] [node1 node2...]
|
|
|
+
|
|
|
+import argparse
|
|
|
+import json
|
|
|
+import yaml
|
|
|
+
|
|
|
+# The default manifest file
|
|
|
+MANIFEST = "manifest.yaml"
|
|
|
+
|
|
|
+# The default pubkeys file
|
|
|
+PUBKEYS = "pubkeys.yaml"
|
|
|
+
|
|
|
+def create_json(manifestfile, pubkeysfile, nodelist):
|
|
|
+ """Given a manifest.yaml file, a pubkeys.yaml file, and (optionally) a
|
|
|
+ list of nodes to include, generate the config.json file to give to
|
|
|
+ each of the nodes. If the list of nodes is missing, include all nodes
|
|
|
+ in the manifest.yaml file. It is an error to include a node that is
|
|
|
+ missing from either the manifest.yaml or the pubkeys.yaml files."""
|
|
|
+ with open(manifestfile) as mf:
|
|
|
+ manifest = yaml.safe_load(mf)
|
|
|
+ with open(pubkeysfile) as pf:
|
|
|
+ pubkeys = yaml.safe_load(pf)
|
|
|
+ if nodelist is None or len(nodelist) == 0:
|
|
|
+ nodelist = manifest.keys()
|
|
|
+ config = []
|
|
|
+ for node in nodelist:
|
|
|
+ nodeconf = {}
|
|
|
+ m = manifest[node]
|
|
|
+ nodeconf['name'] = node
|
|
|
+ nodeconf['pubkey'] = pubkeys[node]
|
|
|
+ nodeconf['listen'] = m['listen']
|
|
|
+ # Optional fields
|
|
|
+ for f in ['clisten', 'weight']:
|
|
|
+ if f in m:
|
|
|
+ nodeconf[f] = m[f]
|
|
|
+ config.append(nodeconf)
|
|
|
+ return json.dumps(config)
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ aparse = argparse.ArgumentParser(
|
|
|
+ description='Create a TEEMS config.json file from a manifest and a pubkeys file'
|
|
|
+ )
|
|
|
+ aparse.add_argument('-m', default=MANIFEST,
|
|
|
+ help='manifest.yaml file')
|
|
|
+ aparse.add_argument('-p', default=PUBKEYS,
|
|
|
+ help='pubkeys.yaml file')
|
|
|
+ aparse.add_argument('node', nargs='*', help='nodes to include')
|
|
|
+ args = aparse.parse_args()
|
|
|
+
|
|
|
+ json = create_json(args.m, args.p, args.node)
|
|
|
+
|
|
|
+ if json is not None:
|
|
|
+ print(json)
|