Exemplo n.º 1
0
    def test_if_compose_oauth_options_for_jes_backend_cromwell_can_deal_with_null_workflow_options(
        self, ):
        test_url = 'https://fake_url'
        test_service_account_key = 'data/fake_account_key.json'
        with open(test_service_account_key, 'r') as f:
            test_service_account_key_content = json.load(f)

        test_auth = CromwellAuth(
            url=test_url,
            header={"Authorization": "bearer fake_token"},
            auth=None,
            service_key_content=test_service_account_key_content,
        )

        result_options = utils.compose_oauth_options_for_jes_backend_cromwell(
            test_auth)
        result_options_in_dict = json.loads(result_options.getvalue())

        assert (result_options_in_dict['google_project'] ==
                test_service_account_key_content['project_id'])
        assert (result_options_in_dict['google_compute_service_account'] ==
                test_service_account_key_content['client_email'])
        assert result_options_in_dict[
            'user_service_account_json'] == json.dumps(
                test_service_account_key_content)
Exemplo n.º 2
0
    def test_compose_oauth_options_for_jes_backend_cromwell_add_required_fields_to_workflow_options(
        self, ):
        test_url = 'https://fake_url'
        test_service_account_key = 'data/fake_account_key.json'
        with open(test_service_account_key, 'r') as f:
            test_service_account_key_content = json.load(f)

        test_auth = CromwellAuth(
            url=test_url,
            header={"Authorization": "bearer fake_token"},
            auth=None,
            service_key_content=test_service_account_key_content,
        )

        result_options = utils.compose_oauth_options_for_jes_backend_cromwell(
            test_auth, self.options_file_BytesIO)
        # use .decode('utf-8') for Python3.5 compatibility
        result_options_in_dict = json.loads(
            result_options.getvalue().decode('utf-8'))

        assert (
            # use .decode('utf-8') for Python3.5 compatibility
            result_options_in_dict['read_from_cache'] == json.loads(
                self.options_file_BytesIO.getvalue().decode('utf-8'))
            ['read_from_cache'])
        assert (result_options_in_dict['google_project'] ==
                test_service_account_key_content['project_id'])
        assert (result_options_in_dict['google_compute_service_account'] ==
                test_service_account_key_content['client_email'])
        assert result_options_in_dict[
            'user_service_account_json'] == json.dumps(
                test_service_account_key_content)
Exemplo n.º 3
0
    def submit(
        cls: 'CromwellAPI',
        auth: CromwellAuth,
        wdl_file: Union[str, io.BytesIO],
        inputs_files: Union[List[Union[str, io.BytesIO]], str,
                            io.BytesIO] = None,
        options_file: Union[str, io.BytesIO] = None,
        dependencies: Union[str, List[str], io.BytesIO] = None,
        label_file: Union[str, io.BytesIO] = None,
        collection_name: str = None,
        on_hold: bool = False,
        validate_labels: bool = False,
        raise_for_status: bool = False,
    ) -> requests.Response:
        """ Submits a workflow to Cromwell.

        Args:
            auth: authentication class holding auth information to a
                Cromwell server.
            wdl_file: The workflow source file to submit for execution. Could be either the
                path to the file (str) or the file content in io.BytesIO.
            inputs_files: The input data in JSON
                format. Could be either the path to the file (str) or the file content in io.BytesIO. This could also
                be a list of unlimited input file paths/contents, each of them should have a type of
                Union[str, io.BytesIO].
            options_file: The Cromwell options file for workflows. Could be either
                the path to the file (str) or the file content in io.BytesIO.
            dependencies: Workflow dependency files. Could be the path to
                the zipped file (str) containing dependencies, a list of paths(List[str]) to all dependency files to be
                zipped or a zipped file in io.BytesIO.
            label_file: A collection of key/value pairs for workflow labels in JSON
                format, could be either the path to the JSON file (str) or the file content in io.BytesIO.
            collection_name: Collection in SAM that the workflow should belong to, if use CaaS.
            on_hold: Whether to submit the workflow in "On Hold" status.
            validate_labels: If True, validate cromwell labels.
            raise_for_status: Whether to check and raise for status based on the response.

        Raises:
            requests.exceptions.HTTPError: This will be raised when raise_for_status is True and Cromwell returns
                a response that satisfies 400 <= response.status_code < 600.

        Returns:
            HTTP response from Cromwell.
        """
        submission_manifest = utilities.prepare_workflow_manifest(
            wdl_file=wdl_file,
            inputs_files=inputs_files,
            options_file=options_file,
            dependencies=dependencies,
            label_file=label_file,
            collection_name=collection_name,
            on_hold=on_hold,
        )

        if auth.service_key_content:
            submission_manifest[
                'workflowOptions'] = utilities.compose_oauth_options_for_jes_backend_cromwell(
                    auth, submission_manifest.get('workflowOptions'))

        if validate_labels and label_file is not None:
            validate_cromwell_label(submission_manifest['labels'])

        response = requests.post(
            auth.url + cls._submit_endpoint,
            files=submission_manifest,
            auth=auth.auth,
            headers=auth.header,
        )

        if raise_for_status:
            cls._check_and_raise_status(response)
        return response