Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of where the Synapse homeserver yaml file containing DB settings is loaded from #111

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions scripts/s3_media_upload
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,18 @@ def get_sqlite_conn(parser):

return sqlite_conn

def get_homeserver_db_conn(parser):
"""Attempt to get a connection based on homeserver.yaml to Synapse's
def get_homeserver_db_conn(parser, homeserver_config_path):
"""Attempt to get a connection based on the provided YAML path to Synapse's
database, or exit.
"""

try:
with open("homeserver.yaml") as f:
with open(homeserver_config_path) as f:
homeserver_yaml = yaml.safe_load(f)
except FileNotFoundError:
parser.error("Could not find homeserver.yaml")
parser.error("Could not find %s" % (homeserver_config_path,))
except yaml.YAMLError as e:
parser.error("homeserver.yaml is not valid yaml: %s" % (e,))
parser.error("%s is not valid yaml: %s" % (homeserver_config_path, e,))

try:
database_name = homeserver_yaml["database"]["name"]
Expand Down Expand Up @@ -453,15 +453,15 @@ def get_database_db_conn(parser):

return synapse_db_conn

def get_synapse_db_conn(parser):
def get_synapse_db_conn(parser, homeserver_config_path):
"""Attempt to get a connection based on database.yaml or homeserver.yaml
to Synapse's database, or exit.
"""

if os.path.isfile("database.yaml"):
conn = get_database_db_conn(parser)
else:
conn = get_homeserver_db_conn(parser)
conn = get_homeserver_db_conn(parser, homeserver_config_path)

return conn

Expand All @@ -485,6 +485,11 @@ def main():
" accepts duration of the form of e.g. 1m (one month). Valid suffixes"
" are d, m or y. NOTE: Currently does not remove entries from the cache",
)
update_db_parser.add_argument(
"--homeserver-config-path",
help="Path to the yaml file containing Synapse's DB settings",
default="homeserver.yaml"
)

deleted_parser = subparsers.add_parser(
"check-deleted",
Expand All @@ -509,6 +514,11 @@ def main():
" accepts duration of the form of e.g. 1m (one month). Valid suffixes"
" are d, m or y. NOTE: Currently does not remove entries from the cache",
)
update_parser.add_argument(
"--homeserver-config-path",
help="Path to the yaml file containing Synapse's DB settings",
default="homeserver.yaml"
)

write_parser = subparsers.add_parser(
"write",
Expand Down Expand Up @@ -578,7 +588,7 @@ def main():

if args.cmd == "update-db":
sqlite_conn = get_sqlite_conn(parser)
synapse_db_conn = get_synapse_db_conn(parser)
synapse_db_conn = get_synapse_db_conn(parser, args.homeserver_config_path)
run_update_db(synapse_db_conn, sqlite_conn, args.duration)
return

Expand All @@ -589,7 +599,7 @@ def main():

if args.cmd == "update":
sqlite_conn = get_sqlite_conn(parser)
synapse_db_conn = get_synapse_db_conn(parser)
synapse_db_conn = get_synapse_db_conn(parser, args.homeserver_config_path)
run_update_db(synapse_db_conn, sqlite_conn, args.duration)
run_check_delete(sqlite_conn, args.base_path)
return
Expand Down
Loading