def _get_local_docker_images(self): """Return a list with local docker images.""" from reana_client.utils import run_command # Check if docker is installed. run_command("docker version", display=False, return_output=True) docker_images = run_command( 'docker images --format "{{ .Repository }}:{{ .Tag }}"', display=False, return_output=True, ) return docker_images.splitlines()
def validate_parameters(self): """Validate input parameters for CWL workflows.""" def _check_dangerous_operations(workflow): """Check for "baseCommand" and "arguments" in workflow. If these keys are found, validate if they have dangerous operations. """ cmd_keys = ["baseCommand", "arguments"] for cmd_key in cmd_keys: if cmd_key in workflow: commands = ( workflow[cmd_key] if isinstance(workflow[cmd_key], list) else [workflow[cmd_key]] ) self._validate_dangerous_operations( commands, step=workflow.get("id") ) from reana_client.utils import run_command cwl_main_spec_path = self.reana_yaml["workflow"].get("file") if os.path.exists(cwl_main_spec_path): run_command( "cwltool --validate --strict {}".format(cwl_main_spec_path), display=False, return_output=True, stderr_output=True, ) else: raise ParameterValidationError( "Workflow path {} is not valid.".format(cwl_main_spec_path) ) workflow = self.specification.get("$graph", self.specification) if isinstance(workflow, dict): _check_dangerous_operations(workflow) elif isinstance(workflow, list): for wf in workflow: _check_dangerous_operations(wf)
def _get_image_uid_gids(self, image, tag): """Obtain environment image UID and GIDs. :returns: A tuple with UID and GIDs. """ from reana_client.utils import run_command # Check if docker is installed. run_command("docker version", display=False, return_output=True) # Run ``id``` command inside the container. uid_gid_output = run_command( 'docker run -i -t --rm {} sh -c "/usr/bin/id -u && /usr/bin/id -G"' .format(self._get_full_image_name(image, tag)), display=False, return_output=True, ) ids = uid_gid_output.splitlines() uid, gids = ( int(ids[-2]), [int(gid) for gid in ids[-1].split()], ) return uid, gids