Skip to content

Commit 16baddc

Browse files
committed
Detect references to /var/spool/cwl
1 parent 078f1b5 commit 16baddc

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

cwltool/load_tool.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Text, Tuple, Union, cast)
1414

1515
import requests.sessions
16-
from six import itervalues, string_types
16+
from six import iteritems, itervalues, string_types
1717
from six.moves import urllib
1818

1919
import schema_salad.schema as schema
@@ -220,6 +220,33 @@ def validate_document(document_loader, # type: Loader
220220

221221
workflowobj = fetch_document(uri, fetcher_constructor=fetcher_constructor)[1]
222222

223+
def var_spool_cwl_detector(obj, # type: Union[Mapping, Iterable, Text]
224+
item=None, # type: Optional[Any]
225+
obj_key=None, # type: Optional[Any]
226+
): # type: (...)->None
227+
""" Detects any textual reference to /var/spool/cwl. """
228+
if isinstance(obj, string_types):
229+
if "var/spool/cwl" in obj:
230+
message = SourceLine(
231+
item=item, key=obj_key, raise_type=Text,
232+
include_traceback=_logger.isEnabledFor(logging.DEBUG)).makeError(
233+
"Non-portable reference to /var/spool/cwl found: "
234+
"'{}'.\n Replace with /var/spool/cwl/ with "
235+
"$(runtime.outdir).".format(obj))
236+
if not strict:
237+
_logger.warning(message)
238+
else:
239+
raise ValidationException(message)
240+
else:
241+
return
242+
elif isinstance(obj, Mapping):
243+
for key, value in iteritems(obj):
244+
var_spool_cwl_detector(value, obj, key)
245+
elif isinstance(obj, Iterable):
246+
for element in obj:
247+
var_spool_cwl_detector(element, obj, None)
248+
var_spool_cwl_detector(workflowobj)
249+
223250
fileuri = urllib.parse.urldefrag(uri)[0]
224251
if "cwlVersion" not in workflowobj:
225252
if metadata and 'cwlVersion' in metadata:

tests/non_portable.cwl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
5+
requirements:
6+
DockerRequirement:
7+
dockerPull: debian
8+
InitialWorkDirRequirement:
9+
listing:
10+
- class: File
11+
basename: hi.txt
12+
contents: Hello, World!
13+
14+
inputs: []
15+
16+
baseCommand:
17+
- cat
18+
- /var/spool/cwl/hi.txt
19+
20+
stdout: result.txt
21+
22+
outputs:
23+
result: stdout

0 commit comments

Comments
 (0)