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 #5524 from matrix-org/rav/new_cmdline_options
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 14, 2020
2 parents 8ef47a3 + 4ac7ef4 commit ca2c8ea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/5524.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add --data-dir and --open-private-ports options.
2 changes: 1 addition & 1 deletion docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ listeners:
- names: [client, federation]
compress: false

# example additonal_resources:
# example additional_resources:
#
#additional_resources:
# "/_matrix/my/custom/endpoint":
Expand Down
29 changes: 29 additions & 0 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def generate_config(
server_name,
generate_secrets=False,
report_stats=None,
open_private_ports=False,
):
"""Build a default configuration file
Expand All @@ -174,6 +175,9 @@ def generate_config(
report_stats (bool|None): Initial setting for the report_stats setting.
If None, report_stats will be left unset.
open_private_ports (bool): True to leave private ports (such as the non-TLS
HTTP listener) open to the internet.
Returns:
str: the yaml config file
"""
Expand All @@ -186,6 +190,7 @@ def generate_config(
server_name=server_name,
generate_secrets=generate_secrets,
report_stats=report_stats,
open_private_ports=open_private_ports,
)
)

Expand Down Expand Up @@ -291,6 +296,23 @@ def load_or_generate_config(cls, description, argv):
" config file."
),
)
generate_group.add_argument(
"--data-directory",
metavar="DIRECTORY",
help=(
"Specify where data such as the media store and database file should be"
" stored. Defaults to the current working directory."
),
)
generate_group.add_argument(
"--open-private-ports",
action="store_true",
help=(
"Leave private ports (such as the non-TLS HTTP listener) open to the"
" internet. Do not use this unless you know what you are doing."
),
)

config_args, remaining_args = config_parser.parse_known_args(argv)

config_files = find_config_files(search_paths=config_args.config_path)
Expand Down Expand Up @@ -324,6 +346,12 @@ def load_or_generate_config(cls, description, argv):
if not cls.path_exists(config_path):
print("Generating config file %s" % (config_path,))

if config_args.data_directory:
data_dir_path = config_args.data_directory
else:
data_dir_path = os.getcwd()
data_dir_path = os.path.abspath(data_dir_path)

server_name = config_args.server_name
if not server_name:
raise ConfigError(
Expand All @@ -337,6 +365,7 @@ def load_or_generate_config(cls, description, argv):
server_name=server_name,
report_stats=(config_args.report_stats == "yes"),
generate_secrets=True,
open_private_ports=config_args.open_private_ports,
)

if not cls.path_exists(config_dir_path):
Expand Down
17 changes: 12 additions & 5 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,9 @@ def read_config(self, config, **kwargs):
def has_tls_listener(self):
return any(l["tls"] for l in self.listeners)

def generate_config_section(self, server_name, data_dir_path, **kwargs):
def generate_config_section(
self, server_name, data_dir_path, open_private_ports, **kwargs
):
_, bind_port = parse_and_validate_server_name(server_name)
if bind_port is not None:
unsecure_port = bind_port - 400
Expand All @@ -470,6 +472,13 @@ def generate_config_section(self, server_name, data_dir_path, **kwargs):
# Bring DEFAULT_ROOM_VERSION into the local-scope for use in the
# default config string
default_room_version = DEFAULT_ROOM_VERSION

unsecure_http_binding = "port: %i\n tls: false" % (unsecure_port,)
if not open_private_ports:
unsecure_http_binding += (
"\n bind_addresses: ['::1', '127.0.0.1']"
)

return (
"""\
## Server ##
Expand Down Expand Up @@ -672,17 +681,15 @@ def generate_config_section(self, server_name, data_dir_path, **kwargs):
# If you plan to use a reverse proxy, please see
# https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.rst.
#
- port: %(unsecure_port)s
tls: false
bind_addresses: ['::1', '127.0.0.1']
- %(unsecure_http_binding)s
type: http
x_forwarded: true
resources:
- names: [client, federation]
compress: false
# example additonal_resources:
# example additional_resources:
#
#additional_resources:
# "/_matrix/my/custom/endpoint":
Expand Down

0 comments on commit ca2c8ea

Please sign in to comment.