From 5941a98b66c8496f31802254341a181a256fa7a1 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Fri, 20 Aug 2021 19:37:26 +0000 Subject: [PATCH] Document and add debug arguments for read-only behavior. --- bemani/utils/api.py | 3 +++ bemani/utils/frontend.py | 3 +++ bemani/utils/scheduler.py | 3 +++ bemani/utils/services.py | 3 +++ config/server.yaml | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/bemani/utils/api.py b/bemani/utils/api.py index f7222d9..2d6c523 100644 --- a/bemani/utils/api.py +++ b/bemani/utils/api.py @@ -14,10 +14,13 @@ def main() -> None: parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") parser.add_argument("-r", "--profile", help="Turn on profiling for API, writing CProfile data to the currenct directory", action="store_true") + parser.add_argument("-o", "--read-only", action="store_true", help="Force the database into read-only mode.") args = parser.parse_args() # Set up app load_config(args.config) + if args.read_only: + config['database']['read_only'] = True if args.profile: from werkzeug.contrib.profiler import ProfilerMiddleware diff --git a/bemani/utils/frontend.py b/bemani/utils/frontend.py index 379425b..8cc0a5f 100644 --- a/bemani/utils/frontend.py +++ b/bemani/utils/frontend.py @@ -59,10 +59,13 @@ def main() -> None: parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") parser.add_argument("-r", "--profile", help="Turn on profiling for front end, writing CProfile data to the currenct directory", action="store_true") + parser.add_argument("-o", "--read-only", action="store_true", help="Force the database into read-only mode.") args = parser.parse_args() # Set up app load_config(args.config) + if args.read_only: + config['database']['read_only'] = True # Register all blueprints register_blueprints() diff --git a/bemani/utils/scheduler.py b/bemani/utils/scheduler.py index d1fc0c8..3ed01a5 100644 --- a/bemani/utils/scheduler.py +++ b/bemani/utils/scheduler.py @@ -72,11 +72,14 @@ def run_scheduled_work(config: Config) -> None: if __name__ == '__main__': parser = argparse.ArgumentParser(description="A scheduler for work that needs to be done periodically.") parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") + parser.add_argument("-o", "--read-only", action="store_true", help="Force the database into read-only mode.") args = parser.parse_args() # Set up global configuration config = Config() load_config(args.config, config) + if args.read_only: + config['database']['read_only'] = True # Run out of band work run_scheduled_work(config) diff --git a/bemani/utils/services.py b/bemani/utils/services.py index 2aaf647..da528b4 100644 --- a/bemani/utils/services.py +++ b/bemani/utils/services.py @@ -127,11 +127,14 @@ if __name__ == '__main__': parser.add_argument("-p", "--port", help="Port to listen on. Defaults to 80", type=int, default=80) parser.add_argument("-c", "--config", help="Core configuration. Defaults to server.yaml", type=str, default="server.yaml") parser.add_argument("-r", "--profile", help="Turn on profiling for services, writing CProfile data to the currenct directory", action="store_true") + parser.add_argument("-o", "--read-only", action="store_true", help="Force the database into read-only mode.") args = parser.parse_args() # Set up global configuration, overriding config port for convenience in debugging. load_config(args.config) config['server']['port'] = args.port + if args.read_only: + config['database']['read_only'] = True # Register game handlers register_games() diff --git a/config/server.yaml b/config/server.yaml index fdd6d6d..51ed02a 100644 --- a/config/server.yaml +++ b/config/server.yaml @@ -7,6 +7,10 @@ database: user: "bemani" # Password of said user. password: "bemani" + # Force the network to read-only mode, refusing to write to the DB + # except for creating/destroying frontend sessions to enable login. + # Set this to False or delete this to run in production mode. + read_only: False server: # Advertised server IP or DNS entry games will connect to.