diff --git a/jobrunner/config.py b/jobrunner/config.py index efc03a97..bacefbab 100644 --- a/jobrunner/config.py +++ b/jobrunner/config.py @@ -52,6 +52,7 @@ def _is_valid_backend_name(name): "r", "jupyter", "python", + "sqlrunner", } DOCKER_REGISTRY = os.environ.get("DOCKER_REGISTRY", "ghcr.io/opensafely-core") diff --git a/jobrunner/lib/commands.py b/jobrunner/lib/commands.py index ef175f60..dc75be4d 100644 --- a/jobrunner/lib/commands.py +++ b/jobrunner/lib/commands.py @@ -5,10 +5,14 @@ def requires_db_access(args): valid_commands = { "cohortextractor": ("generate_cohort", "generate_codelist_report"), "databuilder": ("generate-dataset",), + "sqlrunner": None, # all commands are valid } if len(args) <= 1: return False image, command = args[0], args[1] image = image.split(":")[0] - return command in valid_commands.get(image, []) + if image in valid_commands: + if valid_commands[image] is None or command in valid_commands[image]: + return True + return False diff --git a/tests/lib/test_commands.py b/tests/lib/test_commands.py index 1e47309b..4c5cde95 100644 --- a/tests/lib/test_commands.py +++ b/tests/lib/test_commands.py @@ -11,6 +11,8 @@ ["cohortextractor:latest", "generate_codelist_report"], # Third and subsequent arguments are ignored: ["cohortextractor:latest", "generate_cohort", "could-be-anything-here"], + # sqlrunner has an image but doesn't have a command + ["sqlrunner:latest", "input.sql"], ], ) def test_requires_db_access_privileged_commands_can_access_db(args):