Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix synapse.config module "read" command
Browse files Browse the repository at this point in the history
`synapse.config.__main__` has the possibility to read a config item. This can be used to conveniently also validate the config is valid before trying to start Synapse.

 The "read" command broke in #10916 as it now requires passing in "server.server_name" for example.

 Also made the read command optional so one can just call this with just the confirm file reference and get a "Config parses OK" if things are ok.

Signed-off-by: Jason Robinson <[email protected]>
  • Loading branch information
jaywink committed Oct 21, 2021
1 parent ef7fe09 commit 38abbe0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/11145.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix synapse.config module "read" command.
28 changes: 18 additions & 10 deletions synapse/config/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2021 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,18 +19,25 @@

from synapse.config.homeserver import HomeServerConfig

action = sys.argv[1]
action = sys.argv[1] if len(sys.argv) > 1 and sys.argv[1] == "read" else None
load_config_args = sys.argv[3:] if action else sys.argv[1:]

try:
config = HomeServerConfig.load_config("", load_config_args)
except ConfigError as e:
sys.stderr.write("\n" + str(e) + "\n")
sys.exit(1)

print("Config parses OK!")

if action == "read":
key = sys.argv[2]
try:
config = HomeServerConfig.load_config("", sys.argv[3:])
except ConfigError as e:
sys.stderr.write("\n" + str(e) + "\n")
sys.exit(1)
key_parts = key.split(".")

print(getattr(config, key))
value = config
while len(key_parts):
value = getattr(value, key_parts[0])
key_parts.pop(0)

print(f"{key}: {value}")
sys.exit(0)
else:
sys.stderr.write("Unknown command %r\n" % (action,))
sys.exit(1)

0 comments on commit 38abbe0

Please sign in to comment.