Skip to content

Commit

Permalink
Merge pull request #469 from opensafely-core/iaindillingham/sqlrunner
Browse files Browse the repository at this point in the history
Make job-runner aware of sqlrunner
  • Loading branch information
iaindillingham authored Sep 26, 2022
2 parents b386977 + 1d5b044 commit a3659b8
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 a3659b8

Please sign in to comment.