# coding: utf-8

"""
    IriusRisk API

    Products API  # noqa: E501

    OpenAPI spec version: 1
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from iriusrisk_python_client_lib.api_client import ApiClient


class ThreatsApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post(self, api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, **kwargs):  # noqa: E501
        """Creates a new threat in a library.  # noqa: E501

        Creates a new threat in a library. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post(api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param CreateThreatLibraryRequestBody create_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryThreat
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, **kwargs)  # noqa: E501
        else:
            (data) = self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, **kwargs)  # noqa: E501
            return data

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post_with_http_info(self, api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, **kwargs):  # noqa: E501
        """Creates a new threat in a library.  # noqa: E501

        Creates a new threat in a library. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, create_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param CreateThreatLibraryRequestBody create_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryThreat
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['api_token', 'library_ref', 'risk_pattern_ref', 'use_case_ref', 'create_threat_library_request_body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'api_token' is set
        if ('api_token' not in params or
                params['api_token'] is None):
            raise ValueError("Missing the required parameter `api_token` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post`")  # noqa: E501
        # verify the required parameter 'library_ref' is set
        if ('library_ref' not in params or
                params['library_ref'] is None):
            raise ValueError("Missing the required parameter `library_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post`")  # noqa: E501
        # verify the required parameter 'risk_pattern_ref' is set
        if ('risk_pattern_ref' not in params or
                params['risk_pattern_ref'] is None):
            raise ValueError("Missing the required parameter `risk_pattern_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post`")  # noqa: E501
        # verify the required parameter 'use_case_ref' is set
        if ('use_case_ref' not in params or
                params['use_case_ref'] is None):
            raise ValueError("Missing the required parameter `use_case_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post`")  # noqa: E501
        # verify the required parameter 'create_threat_library_request_body' is set
        if ('create_threat_library_request_body' not in params or
                params['create_threat_library_request_body'] is None):
            raise ValueError("Missing the required parameter `create_threat_library_request_body` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_post`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'library_ref' in params:
            path_params['libraryRef'] = params['library_ref']  # noqa: E501
        if 'risk_pattern_ref' in params:
            path_params['riskPatternRef'] = params['risk_pattern_ref']  # noqa: E501
        if 'use_case_ref' in params:
            path_params['useCaseRef'] = params['use_case_ref']  # noqa: E501

        query_params = []

        header_params = {}
        if 'api_token' in params:
            header_params['api-token'] = params['api_token']  # noqa: E501

        form_params = []
        local_var_files = {}

        body_params = None
        if 'create_threat_library_request_body' in params:
            body_params = params['create_threat_library_request_body']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/libraries/{libraryRef}/riskpatterns/{riskPatternRef}/usecases/{useCaseRef}/threats', 'POST',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='LibraryThreat',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, **kwargs):  # noqa: E501
        """Associates a countermeasure to a threat in a risk pattern.  # noqa: E501

        Associates a countermeasure to a threat in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param AssociateCountermeasureThreatLibraryRequestBody associate_countermeasure_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryControl
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, **kwargs)  # noqa: E501
        else:
            (data) = self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, **kwargs)  # noqa: E501
            return data

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put_with_http_info(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, **kwargs):  # noqa: E501
        """Associates a countermeasure to a threat in a risk pattern.  # noqa: E501

        Associates a countermeasure to a threat in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_countermeasure_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param AssociateCountermeasureThreatLibraryRequestBody associate_countermeasure_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryControl
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['api_token', 'library_ref', 'risk_pattern_ref', 'use_case_ref', 'threat_ref', 'associate_countermeasure_threat_library_request_body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'api_token' is set
        if ('api_token' not in params or
                params['api_token'] is None):
            raise ValueError("Missing the required parameter `api_token` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'library_ref' is set
        if ('library_ref' not in params or
                params['library_ref'] is None):
            raise ValueError("Missing the required parameter `library_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'risk_pattern_ref' is set
        if ('risk_pattern_ref' not in params or
                params['risk_pattern_ref'] is None):
            raise ValueError("Missing the required parameter `risk_pattern_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'use_case_ref' is set
        if ('use_case_ref' not in params or
                params['use_case_ref'] is None):
            raise ValueError("Missing the required parameter `use_case_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'threat_ref' is set
        if ('threat_ref' not in params or
                params['threat_ref'] is None):
            raise ValueError("Missing the required parameter `threat_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'associate_countermeasure_threat_library_request_body' is set
        if ('associate_countermeasure_threat_library_request_body' not in params or
                params['associate_countermeasure_threat_library_request_body'] is None):
            raise ValueError("Missing the required parameter `associate_countermeasure_threat_library_request_body` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_countermeasures_put`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'library_ref' in params:
            path_params['libraryRef'] = params['library_ref']  # noqa: E501
        if 'risk_pattern_ref' in params:
            path_params['riskPatternRef'] = params['risk_pattern_ref']  # noqa: E501
        if 'use_case_ref' in params:
            path_params['useCaseRef'] = params['use_case_ref']  # noqa: E501
        if 'threat_ref' in params:
            path_params['threatRef'] = params['threat_ref']  # noqa: E501

        query_params = []

        header_params = {}
        if 'api_token' in params:
            header_params['api-token'] = params['api_token']  # noqa: E501

        form_params = []
        local_var_files = {}

        body_params = None
        if 'associate_countermeasure_threat_library_request_body' in params:
            body_params = params['associate_countermeasure_threat_library_request_body']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/libraries/{libraryRef}/riskpatterns/{riskPatternRef}/usecases/{useCaseRef}/threats/{threatRef}/countermeasures', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='LibraryControl',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, **kwargs):  # noqa: E501
        """Associates weakness to a threat in a risk pattern.  # noqa: E501

        Associates weakness to a threat in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param AssociateWeaknessThreatLibraryRequestBody associate_weakness_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryWeakness
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, **kwargs)  # noqa: E501
        else:
            (data) = self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, **kwargs)  # noqa: E501
            return data

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put_with_http_info(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, **kwargs):  # noqa: E501
        """Associates weakness to a threat in a risk pattern.  # noqa: E501

        Associates weakness to a threat in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, associate_weakness_threat_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param AssociateWeaknessThreatLibraryRequestBody associate_weakness_threat_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryWeakness
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['api_token', 'library_ref', 'risk_pattern_ref', 'use_case_ref', 'threat_ref', 'associate_weakness_threat_library_request_body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'api_token' is set
        if ('api_token' not in params or
                params['api_token'] is None):
            raise ValueError("Missing the required parameter `api_token` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501
        # verify the required parameter 'library_ref' is set
        if ('library_ref' not in params or
                params['library_ref'] is None):
            raise ValueError("Missing the required parameter `library_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501
        # verify the required parameter 'risk_pattern_ref' is set
        if ('risk_pattern_ref' not in params or
                params['risk_pattern_ref'] is None):
            raise ValueError("Missing the required parameter `risk_pattern_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501
        # verify the required parameter 'use_case_ref' is set
        if ('use_case_ref' not in params or
                params['use_case_ref'] is None):
            raise ValueError("Missing the required parameter `use_case_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501
        # verify the required parameter 'threat_ref' is set
        if ('threat_ref' not in params or
                params['threat_ref'] is None):
            raise ValueError("Missing the required parameter `threat_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501
        # verify the required parameter 'associate_weakness_threat_library_request_body' is set
        if ('associate_weakness_threat_library_request_body' not in params or
                params['associate_weakness_threat_library_request_body'] is None):
            raise ValueError("Missing the required parameter `associate_weakness_threat_library_request_body` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_put`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'library_ref' in params:
            path_params['libraryRef'] = params['library_ref']  # noqa: E501
        if 'risk_pattern_ref' in params:
            path_params['riskPatternRef'] = params['risk_pattern_ref']  # noqa: E501
        if 'use_case_ref' in params:
            path_params['useCaseRef'] = params['use_case_ref']  # noqa: E501
        if 'threat_ref' in params:
            path_params['threatRef'] = params['threat_ref']  # noqa: E501

        query_params = []

        header_params = {}
        if 'api_token' in params:
            header_params['api-token'] = params['api_token']  # noqa: E501

        form_params = []
        local_var_files = {}

        body_params = None
        if 'associate_weakness_threat_library_request_body' in params:
            body_params = params['associate_weakness_threat_library_request_body']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/libraries/{libraryRef}/riskpatterns/{riskPatternRef}/usecases/{useCaseRef}/threats/{threatRef}/weaknesses', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='LibraryWeakness',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, **kwargs):  # noqa: E501
        """Associates a countermeasure to a weakness in a risk pattern.  # noqa: E501

        Associates a countermeasure to a weakness in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param str weakness_ref: Reference for Weakness (required)
        :param AssociateCountermeasureWeaknessLibraryRequestBody associate_countermeasure_weakness_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryControl
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, **kwargs)  # noqa: E501
        else:
            (data) = self.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, **kwargs)  # noqa: E501
            return data

    def libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put_with_http_info(self, api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, **kwargs):  # noqa: E501
        """Associates a countermeasure to a weakness in a risk pattern.  # noqa: E501

        Associates a countermeasure to a weakness in a risk pattern. Conditions to be able to perform the action:   - To have the permission **LIBRARY_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put_with_http_info(api_token, library_ref, risk_pattern_ref, use_case_ref, threat_ref, weakness_ref, associate_countermeasure_weakness_library_request_body, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str library_ref: Reference for library (required)
        :param str risk_pattern_ref: Reference for Risk Pattern (required)
        :param str use_case_ref: Reference for Use Case (required)
        :param str threat_ref: Reference for Threat (required)
        :param str weakness_ref: Reference for Weakness (required)
        :param AssociateCountermeasureWeaknessLibraryRequestBody associate_countermeasure_weakness_library_request_body: JSON data that contains information of the fields (required)
        :return: LibraryControl
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['api_token', 'library_ref', 'risk_pattern_ref', 'use_case_ref', 'threat_ref', 'weakness_ref', 'associate_countermeasure_weakness_library_request_body']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'api_token' is set
        if ('api_token' not in params or
                params['api_token'] is None):
            raise ValueError("Missing the required parameter `api_token` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'library_ref' is set
        if ('library_ref' not in params or
                params['library_ref'] is None):
            raise ValueError("Missing the required parameter `library_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'risk_pattern_ref' is set
        if ('risk_pattern_ref' not in params or
                params['risk_pattern_ref'] is None):
            raise ValueError("Missing the required parameter `risk_pattern_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'use_case_ref' is set
        if ('use_case_ref' not in params or
                params['use_case_ref'] is None):
            raise ValueError("Missing the required parameter `use_case_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'threat_ref' is set
        if ('threat_ref' not in params or
                params['threat_ref'] is None):
            raise ValueError("Missing the required parameter `threat_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'weakness_ref' is set
        if ('weakness_ref' not in params or
                params['weakness_ref'] is None):
            raise ValueError("Missing the required parameter `weakness_ref` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501
        # verify the required parameter 'associate_countermeasure_weakness_library_request_body' is set
        if ('associate_countermeasure_weakness_library_request_body' not in params or
                params['associate_countermeasure_weakness_library_request_body'] is None):
            raise ValueError("Missing the required parameter `associate_countermeasure_weakness_library_request_body` when calling `libraries_library_ref_riskpatterns_risk_pattern_ref_usecases_use_case_ref_threats_threat_ref_weaknesses_weakness_ref_countermeasures_put`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'library_ref' in params:
            path_params['libraryRef'] = params['library_ref']  # noqa: E501
        if 'risk_pattern_ref' in params:
            path_params['riskPatternRef'] = params['risk_pattern_ref']  # noqa: E501
        if 'use_case_ref' in params:
            path_params['useCaseRef'] = params['use_case_ref']  # noqa: E501
        if 'threat_ref' in params:
            path_params['threatRef'] = params['threat_ref']  # noqa: E501
        if 'weakness_ref' in params:
            path_params['weaknessRef'] = params['weakness_ref']  # noqa: E501

        query_params = []

        header_params = {}
        if 'api_token' in params:
            header_params['api-token'] = params['api_token']  # noqa: E501

        form_params = []
        local_var_files = {}

        body_params = None
        if 'associate_countermeasure_weakness_library_request_body' in params:
            body_params = params['associate_countermeasure_weakness_library_request_body']
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/libraries/{libraryRef}/riskpatterns/{riskPatternRef}/usecases/{useCaseRef}/threats/{threatRef}/weaknesses/{weaknessRef}/countermeasures', 'PUT',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='LibraryControl',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def products_ref_threats_get(self, api_token, ref, **kwargs):  # noqa: E501
        """Gets a list of all threats of a product  # noqa: E501

        Returns a list of all the threats of a product. Conditions to be able to perform the action:   - To have the permission **THREAT_VIEW** granted, or   - To have the permission **THREAT_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.products_ref_threats_get(api_token, ref, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str ref: ID for product (required)
        :return: list[ComponentUseCaseThreatShort]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.products_ref_threats_get_with_http_info(api_token, ref, **kwargs)  # noqa: E501
        else:
            (data) = self.products_ref_threats_get_with_http_info(api_token, ref, **kwargs)  # noqa: E501
            return data

    def products_ref_threats_get_with_http_info(self, api_token, ref, **kwargs):  # noqa: E501
        """Gets a list of all threats of a product  # noqa: E501

        Returns a list of all the threats of a product. Conditions to be able to perform the action:   - To have the permission **THREAT_VIEW** granted, or   - To have the permission **THREAT_UPDATE** granted.   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.products_ref_threats_get_with_http_info(api_token, ref, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str api_token: Authentication token (required)
        :param str ref: ID for product (required)
        :return: list[ComponentUseCaseThreatShort]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['api_token', 'ref']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method products_ref_threats_get" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'api_token' is set
        if ('api_token' not in params or
                params['api_token'] is None):
            raise ValueError("Missing the required parameter `api_token` when calling `products_ref_threats_get`")  # noqa: E501
        # verify the required parameter 'ref' is set
        if ('ref' not in params or
                params['ref'] is None):
            raise ValueError("Missing the required parameter `ref` when calling `products_ref_threats_get`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'ref' in params:
            path_params['ref'] = params['ref']  # noqa: E501

        query_params = []

        header_params = {}
        if 'api_token' in params:
            header_params['api-token'] = params['api_token']  # noqa: E501

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = []  # noqa: E501

        return self.api_client.call_api(
            '/products/{ref}/threats', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[ComponentUseCaseThreatShort]',  # noqa: E501
            auth_settings=auth_settings,
            async_req=params.get('async_req'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
