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

Commit

Permalink
Merge pull request #220 from matrix-org/markjh/generate_keys
Browse files Browse the repository at this point in the history
Fix the --generate-keys option.
  • Loading branch information
erikjohnston committed Aug 12, 2015
2 parents 7b49236 + 7bbaab9 commit 4f11a5b
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,58 +149,49 @@ def load_config(cls, description, argv, generate_section=None):
)
config_args, remaining_args = config_parser.parse_known_args(argv)

generate_keys = config_args.generate_keys

if config_args.generate_config:
if not config_args.config_path:
config_parser.error(
"Must supply a config file.\nA config file can be automatically"
" generated using \"--generate-config -H SERVER_NAME"
" -c CONFIG-FILE\""
)

config_dir_path = os.path.dirname(config_args.config_path[0])
config_dir_path = os.path.abspath(config_dir_path)

server_name = config_args.server_name
if not server_name:
print "Must specify a server_name to a generate config for."
sys.exit(1)
(config_path,) = config_args.config_path
if not os.path.exists(config_dir_path):
os.makedirs(config_dir_path)
if os.path.exists(config_path):
print "Config file %r already exists" % (config_path,)
yaml_config = cls.read_config_file(config_path)
yaml_name = yaml_config["server_name"]
if server_name != yaml_name:
print (
"Config file %r has a different server_name: "
" %r != %r" % (config_path, server_name, yaml_name)
)
if not os.path.exists(config_path):
config_dir_path = os.path.dirname(config_path)
config_dir_path = os.path.abspath(config_dir_path)

server_name = config_args.server_name
if not server_name:
print "Must specify a server_name to a generate config for."
sys.exit(1)
config_bytes, config = obj.generate_config(
config_dir_path, server_name
if not os.path.exists(config_dir_path):
os.makedirs(config_dir_path)
with open(config_path, "wb") as config_file:
config_bytes, config = obj.generate_config(
config_dir_path, server_name
)
obj.invoke_all("generate_files", config)
config_file.write(config_bytes)
print (
"A config file has been generated in %r for server name"
" %r with corresponding SSL keys and self-signed"
" certificates. Please review this file and customise it"
" to your needs."
) % (config_path, server_name)
print (
"If this server name is incorrect, you will need to"
" regenerate the SSL certificates"
)
config.update(yaml_config)
print "Generating any missing keys for %r" % (server_name,)
obj.invoke_all("generate_files", config)
sys.exit(0)
with open(config_path, "wb") as config_file:
config_bytes, config = obj.generate_config(
config_dir_path, server_name
)
obj.invoke_all("generate_files", config)
config_file.write(config_bytes)
else:
print (
"A config file has been generated in %s for server name"
" '%s' with corresponding SSL keys and self-signed"
" certificates. Please review this file and customise it to"
" your needs."
) % (config_path, server_name)
print (
"If this server name is incorrect, you will need to regenerate"
" the SSL certificates"
)
sys.exit(0)
"Config file %r already exists. Generating any missing key"
" files."
) % (config_path,)
generate_keys = True

parser = argparse.ArgumentParser(
parents=[config_parser],
Expand All @@ -218,7 +209,7 @@ def load_config(cls, description, argv, generate_section=None):
" -c CONFIG-FILE\""
)

config_dir_path = os.path.dirname(config_args.config_path[0])
config_dir_path = os.path.dirname(config_args.config_path[-1])
config_dir_path = os.path.abspath(config_dir_path)

specified_config = {}
Expand All @@ -231,12 +222,12 @@ def load_config(cls, description, argv, generate_section=None):
config.pop("log_config")
config.update(specified_config)

if generate_keys:
obj.invoke_all("generate_files", config)
sys.exit(0)

obj.invoke_all("read_config", config)

obj.invoke_all("read_arguments", args)

if config_args.generate_keys:
obj.invoke_all("generate_files", config)
sys.exit(0)

return obj

0 comments on commit 4f11a5b

Please sign in to comment.