2019-06-28 02:19:09 -06:00
|
|
|
#!/usr/bin/env python3
|
2018-12-21 08:04:57 -07:00
|
|
|
|
|
|
|
import argparse
|
2019-03-04 10:14:58 -07:00
|
|
|
import shutil
|
2018-12-21 08:04:57 -07:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from synapse.config.homeserver import HomeServerConfig
|
|
|
|
|
2022-03-02 06:00:16 -07:00
|
|
|
|
Disallow untyped defs in synapse._scripts (#12422)
Of note:
* No untyped defs in `register_new_matrix_user`
This one might be contraversial. `request_registration` has three
dependency-injection arguments used for testing. I'm removing the
injection of the `requests` module and using `unitest.mock.patch` in the
test cases instead.
Doing `reveal_type(requests)` and `reveal_type(requests.get)` before the
change:
```
synapse/_scripts/register_new_matrix_user.py:45: note: Revealed type is "Any"
synapse/_scripts/register_new_matrix_user.py:46: note: Revealed type is "Any"
```
And after:
```
synapse/_scripts/register_new_matrix_user.py:44: note: Revealed type is "types.ModuleType"
synapse/_scripts/register_new_matrix_user.py:45: note: Revealed type is "def (url: Union[builtins.str, builtins.bytes], params: Union[Union[_typeshed.SupportsItems[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]], Tuple[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]], typing.Iterable[Tuple[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]]], builtins.str, builtins.bytes], None] =, data: Union[Any, None] =, headers: Union[Any, None] =, cookies: Union[Any, None] =, files: Union[Any, None] =, auth: Union[Any, None] =, timeout: Union[Any, None] =, allow_redirects: builtins.bool =, proxies: Union[Any, None] =, hooks: Union[Any, None] =, stream: Union[Any, None] =, verify: Union[Any, None] =, cert: Union[Any, None] =, json: Union[Any, None] =) -> requests.models.Response"
```
* Drive-by comment in `synapse.storage.types`
* No untyped defs in `synapse_port_db`
This was by far the most painful. I'm happy to break this up into
smaller pieces for review if it's not managable as-is.
2022-04-11 05:41:55 -06:00
|
|
|
def main() -> None:
|
2018-12-21 08:04:57 -07:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--config-dir",
|
|
|
|
default="CONFDIR",
|
|
|
|
help="The path where the config files are kept. Used to create filenames for "
|
2021-05-14 04:46:35 -06:00
|
|
|
"things like the log config and the signing key. Default: %(default)s",
|
2018-12-21 08:04:57 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--data-dir",
|
|
|
|
default="DATADIR",
|
|
|
|
help="The path where the data files are kept. Used to create filenames for "
|
2021-05-14 04:46:35 -06:00
|
|
|
"things like the database and media store. Default: %(default)s",
|
2018-12-21 08:04:57 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--server-name",
|
|
|
|
default="SERVERNAME",
|
|
|
|
help="The server name. Used to initialise the server_name config param, but also "
|
2021-05-14 04:46:35 -06:00
|
|
|
"used in the names of some of the config files. Default: %(default)s",
|
2018-12-21 08:04:57 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--report-stats",
|
|
|
|
action="store",
|
2022-07-19 06:38:29 -06:00
|
|
|
help="Whether the generated config reports homeserver usage statistics",
|
2018-12-21 08:04:57 -07:00
|
|
|
choices=["yes", "no"],
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--generate-secrets",
|
|
|
|
action="store_true",
|
|
|
|
help="Enable generation of new secrets for things like the macaroon_secret_key."
|
2021-05-14 04:46:35 -06:00
|
|
|
"By default, these parameters will be left unset.",
|
2018-12-21 08:04:57 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
2021-05-14 04:46:35 -06:00
|
|
|
"-o",
|
|
|
|
"--output-file",
|
|
|
|
type=argparse.FileType("w"),
|
2018-12-21 08:04:57 -07:00
|
|
|
default=sys.stdout,
|
|
|
|
help="File to write the configuration to. Default: stdout",
|
|
|
|
)
|
|
|
|
|
2019-03-04 10:14:58 -07:00
|
|
|
parser.add_argument(
|
|
|
|
"--header-file",
|
2021-05-14 04:46:35 -06:00
|
|
|
type=argparse.FileType("r"),
|
2019-03-04 10:14:58 -07:00
|
|
|
help="File from which to read a header, which will be printed before the "
|
2021-05-14 04:46:35 -06:00
|
|
|
"generated config.",
|
2019-03-04 10:14:58 -07:00
|
|
|
)
|
|
|
|
|
2018-12-21 08:04:57 -07:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
report_stats = args.report_stats
|
|
|
|
if report_stats is not None:
|
|
|
|
report_stats = report_stats == "yes"
|
|
|
|
|
|
|
|
conf = HomeServerConfig().generate_config(
|
|
|
|
config_dir_path=args.config_dir,
|
|
|
|
data_dir_path=args.data_dir,
|
|
|
|
server_name=args.server_name,
|
|
|
|
generate_secrets=args.generate_secrets,
|
|
|
|
report_stats=report_stats,
|
|
|
|
)
|
|
|
|
|
2019-03-04 10:14:58 -07:00
|
|
|
if args.header_file:
|
|
|
|
shutil.copyfileobj(args.header_file, args.output_file)
|
|
|
|
|
2018-12-21 08:04:57 -07:00
|
|
|
args.output_file.write(conf)
|
2022-03-02 06:00:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|