mirror of
https://github.com/matrix-org/synapse-s3-storage-provider.git
synced 2024-10-23 07:29:40 +00:00
Allow configuration of where the Synapse homeserver yaml file containing DB settings is loaded from (#111)
This commit is contained in:
parent
9490124b2a
commit
acbcc412cc
1 changed files with 19 additions and 9 deletions
|
@ -395,18 +395,18 @@ def get_sqlite_conn(parser):
|
||||||
|
|
||||||
return sqlite_conn
|
return sqlite_conn
|
||||||
|
|
||||||
def get_homeserver_db_conn(parser):
|
def get_homeserver_db_conn(parser, homeserver_config_path):
|
||||||
"""Attempt to get a connection based on homeserver.yaml to Synapse's
|
"""Attempt to get a connection based on the provided YAML path to Synapse's
|
||||||
database, or exit.
|
database, or exit.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("homeserver.yaml") as f:
|
with open(homeserver_config_path) as f:
|
||||||
homeserver_yaml = yaml.safe_load(f)
|
homeserver_yaml = yaml.safe_load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
parser.error("Could not find homeserver.yaml")
|
parser.error("Could not find %s" % (homeserver_config_path,))
|
||||||
except yaml.YAMLError as e:
|
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:
|
try:
|
||||||
database_name = homeserver_yaml["database"]["name"]
|
database_name = homeserver_yaml["database"]["name"]
|
||||||
|
@ -454,7 +454,7 @@ def get_database_db_conn(parser):
|
||||||
|
|
||||||
return synapse_db_conn
|
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
|
"""Attempt to get a connection based on database.yaml or homeserver.yaml
|
||||||
to Synapse's database, or exit.
|
to Synapse's database, or exit.
|
||||||
"""
|
"""
|
||||||
|
@ -462,7 +462,7 @@ def get_synapse_db_conn(parser):
|
||||||
if os.path.isfile("database.yaml"):
|
if os.path.isfile("database.yaml"):
|
||||||
conn = get_database_db_conn(parser)
|
conn = get_database_db_conn(parser)
|
||||||
else:
|
else:
|
||||||
conn = get_homeserver_db_conn(parser)
|
conn = get_homeserver_db_conn(parser, homeserver_config_path)
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
@ -486,6 +486,11 @@ def main():
|
||||||
" accepts duration of the form of e.g. 1m (one month). Valid suffixes"
|
" 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",
|
" 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(
|
deleted_parser = subparsers.add_parser(
|
||||||
"check-deleted",
|
"check-deleted",
|
||||||
|
@ -510,6 +515,11 @@ def main():
|
||||||
" accepts duration of the form of e.g. 1m (one month). Valid suffixes"
|
" 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",
|
" 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_parser = subparsers.add_parser(
|
||||||
"write",
|
"write",
|
||||||
|
@ -581,7 +591,7 @@ def main():
|
||||||
|
|
||||||
if args.cmd == "update-db":
|
if args.cmd == "update-db":
|
||||||
sqlite_conn = get_sqlite_conn(parser)
|
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_update_db(synapse_db_conn, sqlite_conn, args.duration)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -592,7 +602,7 @@ def main():
|
||||||
|
|
||||||
if args.cmd == "update":
|
if args.cmd == "update":
|
||||||
sqlite_conn = get_sqlite_conn(parser)
|
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_update_db(synapse_db_conn, sqlite_conn, args.duration)
|
||||||
run_check_delete(sqlite_conn, args.base_path)
|
run_check_delete(sqlite_conn, args.base_path)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue