cwl_utils.sandboxjs

Safe execution of CWL Expressions in a NodeJS sandbox.

Attributes

CWLOutputType

default_timeout

Default number of seconds to wait while running a javascript engine.

seg_symbol

seg_single

seg_double

seg_index

segments

segment_re

param_str

param_re

Exceptions

JavascriptException

Common base class for all non-exit exceptions.

WorkflowException

Common base class for all non-exit exceptions.

Classes

JSEngine

Helper class that provides a standard way to create an ABC using

NodeJSEngine

Helper class that provides a standard way to create an ABC using

Functions

singularity_supports_userns()

Confirm if the version of Singularity install supports the --userns flag.

code_fragment_to_js(jscript[, jslib])

linenum(fn)

stdfmt(data)

get_js_engine()

set_js_engine(js_engine)

check_js_threshold_version(*args, **kwargs)

exec_js_process(*args, **kwargs)

new_js_proc(*args, **kwargs)

Module Contents

exception cwl_utils.sandboxjs.JavascriptException

Bases: Exception

Inheritance diagram of cwl_utils.sandboxjs.JavascriptException

Common base class for all non-exit exceptions.

exception cwl_utils.sandboxjs.WorkflowException

Bases: Exception

Inheritance diagram of cwl_utils.sandboxjs.WorkflowException

Common base class for all non-exit exceptions.

cwl_utils.sandboxjs.CWLOutputType
cwl_utils.sandboxjs.singularity_supports_userns()

Confirm if the version of Singularity install supports the –userns flag.

Return type:

bool

cwl_utils.sandboxjs.default_timeout = 20

Default number of seconds to wait while running a javascript engine.

cwl_utils.sandboxjs.seg_symbol = '\\w+'
cwl_utils.sandboxjs.seg_single = "\\['([^']|\\\\')+'\\]"
cwl_utils.sandboxjs.seg_double = '\\["([^"]|\\\\")+"\\]'
cwl_utils.sandboxjs.seg_index = '\\[[0-9]+\\]'
cwl_utils.sandboxjs.segments
cwl_utils.sandboxjs.segment_re
cwl_utils.sandboxjs.param_str
cwl_utils.sandboxjs.param_re
cwl_utils.sandboxjs.code_fragment_to_js(jscript, jslib='')
Parameters:
  • jscript (str) –

  • jslib (str) –

Return type:

str

cwl_utils.sandboxjs.linenum(fn)
Parameters:

fn (str) –

Return type:

str

cwl_utils.sandboxjs.stdfmt(data)
Parameters:

data (str) –

Return type:

str

class cwl_utils.sandboxjs.JSEngine

Bases: abc.ABC

Inheritance diagram of cwl_utils.sandboxjs.JSEngine

Helper class that provides a standard way to create an ABC using inheritance.

abstract eval(scan, jslib='', **kwargs)
Parameters:
  • scan (str) –

  • jslib (str) –

  • kwargs (Any) –

Return type:

Union[cwl_utils.types.CWLOutputType, Awaitable[cwl_utils.types.CWLOutputType]]

abstract regex_eval(parsed_string, remaining_string, current_value, **kwargs)
Parameters:
  • parsed_string (str) –

  • remaining_string (str) –

  • current_value (cwl_utils.types.CWLOutputType) –

  • kwargs (Any) –

Return type:

Union[cwl_utils.types.CWLOutputType, Awaitable[cwl_utils.types.CWLOutputType]]

class cwl_utils.sandboxjs.NodeJSEngine(have_node_slim=False, minimum_node_version_str='0.10.26', process_finished_str='r1cepzbhUTxtykz5XTC4\n')

Bases: JSEngine

Inheritance diagram of cwl_utils.sandboxjs.NodeJSEngine

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:
  • have_node_slim (bool) –

  • minimum_node_version_str (str) –

  • process_finished_str (str) –

localdata
__del__()
Return type:

None

check_js_threshold_version(working_alias)

Check if the nodeJS engine version on the system with the allowed minimum version.

https://github.com/nodejs/node/blob/master/CHANGELOG.md#nodejs-changelog

Parameters:

working_alias (str) –

Return type:

bool

exec_js_process(js_text, timeout=default_timeout, js_console=False, context=None, force_docker_pull=False, container_engine='docker')

Run a javascript text.

Parameters:
  • timeout (float) – Max number of seconds to wait.

  • js_text (str) –

  • js_console (bool) –

  • context (Optional[str]) –

  • force_docker_pull (bool) –

  • container_engine (str) –

Returns:

A tuple of the return code, stdout, and stderr of the javascript engine invocation.

Return type:

Tuple[int, str, str]

new_js_proc(js_text, force_docker_pull=False, container_engine='docker')

Return a subprocess ready to submit javascript to.

Parameters:
  • js_text (str) –

  • force_docker_pull (bool) –

  • container_engine (str) –

Return type:

subprocess.Popen[str]

eval(scan, jslib='', timeout=default_timeout, force_docker_pull=False, debug=False, js_console=False, container_engine='docker', **kwargs)
Parameters:
  • scan (str) –

  • jslib (str) –

  • timeout (float) –

  • force_docker_pull (bool) –

  • debug (bool) –

  • js_console (bool) –

  • container_engine (str) –

  • kwargs (Any) –

Return type:

cwl_utils.types.CWLOutputType

regex_eval(parsed_string, remaining_string, current_value, **kwargs)
Parameters:
  • parsed_string (str) –

  • remaining_string (str) –

  • current_value (cwl_utils.types.CWLOutputType) –

  • kwargs (Any) –

Return type:

cwl_utils.types.CWLOutputType

cwl_utils.sandboxjs.get_js_engine()
Return type:

JSEngine

cwl_utils.sandboxjs.set_js_engine(js_engine)
Parameters:

js_engine (JSEngine) –

Return type:

None

cwl_utils.sandboxjs.check_js_threshold_version(*args, **kwargs)
Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

bool

cwl_utils.sandboxjs.exec_js_process(*args, **kwargs)
Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Tuple[int, str, str]

cwl_utils.sandboxjs.new_js_proc(*args, **kwargs)
Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

subprocess.Popen[str]