Skip to content

Commit

Permalink
Make job-runner aware of sqlrunner
Browse files Browse the repository at this point in the history
As well as adding sqlrunner's image to the list of allowed images, we
also let job-runner know that sqlrunner's image requires DB access. We
modify `requires_db_access` slightly, because unlike the other images
that require DB access, we don't invoke sqlrunner's image with a
(sub)command.
  • Loading branch information
iaindillingham committed Sep 26, 2022
1 parent b386977 commit 1d5b044
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions jobrunner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion jobrunner/lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/lib/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1d5b044

Please sign in to comment.