reanahub / reana-client

REANA command-line client
http://reana-client.readthedocs.io/
MIT License
10 stars 45 forks source link

snakemake: dangerous operation validation #544

Closed mvidalgarcia closed 2 years ago

mvidalgarcia commented 2 years ago

Current behavior

Currently we support dangerous operations validation on the client-side via reana-client validate. To get more familiar with this feature read this blog post section, where the purpose of it is very well explained with some practical examples.

This feature is supported in Serial, Yadage and CWL workflows.

Expected behavior

The user should be able to run the very same command with Snakemake workflows, e.g. reana-client validate -f reana-snakemake.yaml

All the dangerous operations validation logic resides in this module (look for _validate_dangerous_operations and _display_operations_warnings functions) as part of the parameter validation.

This task should be rather straightforward to implement once the parameter validation is implemented, as we should be able to access the command (Snakefile's shell) of each rule/step when iterating over them. Check other workflow engines for reference.

The logic to parse and load the snakemake specification (Snakefile) should come from https://github.com/reanahub/reana-client/issues/540. After this, one should be able to access the multiple rules and values declared in the Snakefile.

Expected output

workflow/snakemake/Snakefile:

rule all:
    input:
        "results/data.root",
        "results/plot.png"

rule gendata:
    input:
        gendata_tool=config["gendata"]
    output:
        "results/data.root"
    params:
        events=config["events"],
        data=config["data"]
    container:
        "reanahub/reana-env-root6:6.18.04"
    shell:
        "mkdir -p results && root -b -q '{input.gendata_tool}({params.events},\"{params.data}\")' && cd /"

rule fitdata:
    input:
        fitdata_tool=config["fitdata"]
    output:
        "results/plot.png"
    container:
        "reanahub/reana-env-root6:6.18.04"
    params:
        data=config["data"],
        plot=config["plot"]
    shell: 
        "sudo root -b -q '{input.fitdata_tool}(\"{params.data}\",\"{params.plot}\")'"

Output:

$ reana-client validate -f reana-snakemake.yaml
==> Verifying REANA specification file... ~/code/reanahub/reana-demo-root6-roofit/reana-snakemake.yaml
  -> SUCCESS: Valid REANA specification file.
==> Verifying REANA specification parameters...
  -> SUCCESS: REANA specification parameters appear valid.
==> Verifying workflow parameters and commands...
  -> WARNING: Operation "cd /" found in step "gendata" might be dangerous.
  -> WARNING: Operation "sudo" found in step "fitdata" might be dangerous.
  -> SUCCESS: Workflow parameters and commands appear valid.