1# coding=utf-8
2# --------------------------------------------------------------------------
3# Copyright (c) Microsoft Corporation. All rights reserved.
4# Licensed under the MIT License. See License.txt in the project root for license information.
5# Code generated by Microsoft (R) AutoRest Code Generator.
6# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7# --------------------------------------------------------------------------
8from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar
9import warnings
10
11from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
12from azure.core.pipeline import PipelineResponse
13from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
14from azure.mgmt.core.exceptions import ARMErrorFormat
15
16from ... import models as _models
17
18T = TypeVar('T')
19ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
20
21class ProactiveDetectionConfigurationsOperations:
22    """ProactiveDetectionConfigurationsOperations async operations.
23
24    You should not instantiate this class directly. Instead, you should create a Client instance that
25    instantiates it for you and attaches it as an attribute.
26
27    :ivar models: Alias to model classes used in this operation group.
28    :type models: ~azure.mgmt.applicationinsights.v2015_05_01.models
29    :param client: Client for service requests.
30    :param config: Configuration of service client.
31    :param serializer: An object model serializer.
32    :param deserializer: An object model deserializer.
33    """
34
35    models = _models
36
37    def __init__(self, client, config, serializer, deserializer) -> None:
38        self._client = client
39        self._serialize = serializer
40        self._deserialize = deserializer
41        self._config = config
42
43    async def list(
44        self,
45        resource_group_name: str,
46        resource_name: str,
47        **kwargs
48    ) -> List["_models.ApplicationInsightsComponentProactiveDetectionConfiguration"]:
49        """Gets a list of ProactiveDetection configurations of an Application Insights component.
50
51        :param resource_group_name: The name of the resource group. The name is case insensitive.
52        :type resource_group_name: str
53        :param resource_name: The name of the Application Insights component resource.
54        :type resource_name: str
55        :keyword callable cls: A custom type or function that will be passed the direct response
56        :return: list of ApplicationInsightsComponentProactiveDetectionConfiguration, or the result of cls(response)
57        :rtype: list[~azure.mgmt.applicationinsights.v2015_05_01.models.ApplicationInsightsComponentProactiveDetectionConfiguration]
58        :raises: ~azure.core.exceptions.HttpResponseError
59        """
60        cls = kwargs.pop('cls', None)  # type: ClsType[List["_models.ApplicationInsightsComponentProactiveDetectionConfiguration"]]
61        error_map = {
62            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
63        }
64        error_map.update(kwargs.pop('error_map', {}))
65        api_version = "2015-05-01"
66        accept = "application/json"
67
68        # Construct URL
69        url = self.list.metadata['url']  # type: ignore
70        path_format_arguments = {
71            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
72            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
73            'resourceName': self._serialize.url("resource_name", resource_name, 'str'),
74        }
75        url = self._client.format_url(url, **path_format_arguments)
76
77        # Construct parameters
78        query_parameters = {}  # type: Dict[str, Any]
79        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
80
81        # Construct headers
82        header_parameters = {}  # type: Dict[str, Any]
83        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
84
85        request = self._client.get(url, query_parameters, header_parameters)
86        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
87        response = pipeline_response.http_response
88
89        if response.status_code not in [200]:
90            map_error(status_code=response.status_code, response=response, error_map=error_map)
91            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
92
93        deserialized = self._deserialize('[ApplicationInsightsComponentProactiveDetectionConfiguration]', pipeline_response)
94
95        if cls:
96            return cls(pipeline_response, deserialized, {})
97
98        return deserialized
99    list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ProactiveDetectionConfigs'}  # type: ignore
100
101    async def get(
102        self,
103        resource_group_name: str,
104        resource_name: str,
105        configuration_id: str,
106        **kwargs
107    ) -> "_models.ApplicationInsightsComponentProactiveDetectionConfiguration":
108        """Get the ProactiveDetection configuration for this configuration id.
109
110        :param resource_group_name: The name of the resource group. The name is case insensitive.
111        :type resource_group_name: str
112        :param resource_name: The name of the Application Insights component resource.
113        :type resource_name: str
114        :param configuration_id: The ProactiveDetection configuration ID. This is unique within a
115         Application Insights component.
116        :type configuration_id: str
117        :keyword callable cls: A custom type or function that will be passed the direct response
118        :return: ApplicationInsightsComponentProactiveDetectionConfiguration, or the result of cls(response)
119        :rtype: ~azure.mgmt.applicationinsights.v2015_05_01.models.ApplicationInsightsComponentProactiveDetectionConfiguration
120        :raises: ~azure.core.exceptions.HttpResponseError
121        """
122        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ApplicationInsightsComponentProactiveDetectionConfiguration"]
123        error_map = {
124            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
125        }
126        error_map.update(kwargs.pop('error_map', {}))
127        api_version = "2015-05-01"
128        accept = "application/json"
129
130        # Construct URL
131        url = self.get.metadata['url']  # type: ignore
132        path_format_arguments = {
133            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
134            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
135            'resourceName': self._serialize.url("resource_name", resource_name, 'str'),
136            'ConfigurationId': self._serialize.url("configuration_id", configuration_id, 'str'),
137        }
138        url = self._client.format_url(url, **path_format_arguments)
139
140        # Construct parameters
141        query_parameters = {}  # type: Dict[str, Any]
142        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
143
144        # Construct headers
145        header_parameters = {}  # type: Dict[str, Any]
146        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
147
148        request = self._client.get(url, query_parameters, header_parameters)
149        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
150        response = pipeline_response.http_response
151
152        if response.status_code not in [200]:
153            map_error(status_code=response.status_code, response=response, error_map=error_map)
154            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
155
156        deserialized = self._deserialize('ApplicationInsightsComponentProactiveDetectionConfiguration', pipeline_response)
157
158        if cls:
159            return cls(pipeline_response, deserialized, {})
160
161        return deserialized
162    get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ProactiveDetectionConfigs/{ConfigurationId}'}  # type: ignore
163
164    async def update(
165        self,
166        resource_group_name: str,
167        resource_name: str,
168        configuration_id: str,
169        proactive_detection_properties: "_models.ApplicationInsightsComponentProactiveDetectionConfiguration",
170        **kwargs
171    ) -> "_models.ApplicationInsightsComponentProactiveDetectionConfiguration":
172        """Update the ProactiveDetection configuration for this configuration id.
173
174        :param resource_group_name: The name of the resource group. The name is case insensitive.
175        :type resource_group_name: str
176        :param resource_name: The name of the Application Insights component resource.
177        :type resource_name: str
178        :param configuration_id: The ProactiveDetection configuration ID. This is unique within a
179         Application Insights component.
180        :type configuration_id: str
181        :param proactive_detection_properties: Properties that need to be specified to update the
182         ProactiveDetection configuration.
183        :type proactive_detection_properties: ~azure.mgmt.applicationinsights.v2015_05_01.models.ApplicationInsightsComponentProactiveDetectionConfiguration
184        :keyword callable cls: A custom type or function that will be passed the direct response
185        :return: ApplicationInsightsComponentProactiveDetectionConfiguration, or the result of cls(response)
186        :rtype: ~azure.mgmt.applicationinsights.v2015_05_01.models.ApplicationInsightsComponentProactiveDetectionConfiguration
187        :raises: ~azure.core.exceptions.HttpResponseError
188        """
189        cls = kwargs.pop('cls', None)  # type: ClsType["_models.ApplicationInsightsComponentProactiveDetectionConfiguration"]
190        error_map = {
191            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
192        }
193        error_map.update(kwargs.pop('error_map', {}))
194        api_version = "2015-05-01"
195        content_type = kwargs.pop("content_type", "application/json")
196        accept = "application/json"
197
198        # Construct URL
199        url = self.update.metadata['url']  # type: ignore
200        path_format_arguments = {
201            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
202            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str', min_length=1),
203            'resourceName': self._serialize.url("resource_name", resource_name, 'str'),
204            'ConfigurationId': self._serialize.url("configuration_id", configuration_id, 'str'),
205        }
206        url = self._client.format_url(url, **path_format_arguments)
207
208        # Construct parameters
209        query_parameters = {}  # type: Dict[str, Any]
210        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
211
212        # Construct headers
213        header_parameters = {}  # type: Dict[str, Any]
214        header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
215        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
216
217        body_content_kwargs = {}  # type: Dict[str, Any]
218        body_content = self._serialize.body(proactive_detection_properties, 'ApplicationInsightsComponentProactiveDetectionConfiguration')
219        body_content_kwargs['content'] = body_content
220        request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs)
221        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
222        response = pipeline_response.http_response
223
224        if response.status_code not in [200]:
225            map_error(status_code=response.status_code, response=response, error_map=error_map)
226            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
227
228        deserialized = self._deserialize('ApplicationInsightsComponentProactiveDetectionConfiguration', pipeline_response)
229
230        if cls:
231            return cls(pipeline_response, deserialized, {})
232
233        return deserialized
234    update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ProactiveDetectionConfigs/{ConfigurationId}'}  # type: ignore
235