summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-04-24 11:26:19 +0100
committerMark Haines <mark.haines@matrix.org>2015-04-24 11:26:19 +0100
commitb1e68add1992d0072aa37f3bdf07dc226200fe5d (patch)
tree13e7f781892d10206c521978fce43bc4b3e6c0fc /synapse
parentCopyright notice (diff)
downloadsynapse-b1e68add1992d0072aa37f3bdf07dc226200fe5d.tar.xz
Add a config file for perspective servers
Diffstat (limited to 'synapse')
-rw-r--r--synapse/config/_base.py11
-rw-r--r--synapse/config/key.py19
2 files changed, 30 insertions, 0 deletions
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index 87cdbf1d30..f07ea4cc46 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -77,6 +77,17 @@ class Config(object):
         with open(file_path) as file_stream:
             return file_stream.read()
 
+    @classmethod
+    def read_yaml_file(cls, file_path, config_name):
+        cls.check_file(file_path, config_name)
+        with open(file_path) as file_stream:
+            try:
+                return yaml.load(file_stream)
+            except Exception as e:
+                raise ConfigError(
+                    "Error parsing yaml in file %r: " % (file_path,), e
+                )
+
     @staticmethod
     def default_path(name):
         return os.path.abspath(os.path.join(os.path.curdir, name))
diff --git a/synapse/config/key.py b/synapse/config/key.py
index 327105732a..de4e33a7f3 100644
--- a/synapse/config/key.py
+++ b/synapse/config/key.py
@@ -27,6 +27,9 @@ class KeyConfig(Config):
             args.old_signing_key_path
         )
         self.key_refresh_interval = args.key_refresh_interval
+        self.perspectives = self.read_perspectives(
+            args.perspectives_config_path
+        )
 
     @classmethod
     def add_arguments(cls, parser):
@@ -45,6 +48,15 @@ class KeyConfig(Config):
                                     " Used to set the exipiry in /key/v2/."
                                     " Controls how frequently servers will"
                                     " query what keys are still valid")
+        key_group.add_argument("--perspectives-config-path",
+                               help="The trusted servers to download signing"
+                                    " keys from")
+
+    def read_perspectives(self, perspectives_config_path):
+        servers = self.read_yaml_file(
+            perspectives_config_path, "perspectives_config_path"
+        )
+        return servers
 
     def read_signing_key(self, signing_key_path):
         signing_keys = self.read_file(signing_key_path, "signing_key")
@@ -108,3 +120,10 @@ class KeyConfig(Config):
         if not os.path.exists(args.old_signing_key_path):
             with open(args.old_signing_key_path, "w"):
                 pass
+
+        if not args.perspectives_config_path:
+            args.perspectives_config_path = base_key_name + ".perspectives"
+
+        if not os.path.exists(args.perspectives_config_path):
+            with open(args.perspectives_config_path, "w") as perspectives_file:
+                perspectives_file.write("@@@")