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
5# license information.
6#
7# Code generated by Microsoft (R) AutoRest Code Generator.
8# Changes may cause incorrect behavior and will be lost if the code is
9# regenerated.
10# --------------------------------------------------------------------------
11
12import uuid
13from msrest.pipeline import ClientRawResponse
14
15from .. import models
16
17
18class ProductApiOperations(object):
19    """ProductApiOperations operations.
20
21    You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
22
23    :param client: Client for service requests.
24    :param config: Configuration of service client.
25    :param serializer: An object model serializer.
26    :param deserializer: An object model deserializer.
27    :ivar api_version: Version of the API to be used with the client request. Constant value: "2019-12-01".
28    """
29
30    models = models
31
32    def __init__(self, client, config, serializer, deserializer):
33
34        self._client = client
35        self._serialize = serializer
36        self._deserialize = deserializer
37        self.api_version = "2019-12-01"
38
39        self.config = config
40
41    def list_by_product(
42            self, resource_group_name, service_name, product_id, filter=None, top=None, skip=None, custom_headers=None, raw=False, **operation_config):
43        """Lists a collection of the APIs associated with a product.
44
45        :param resource_group_name: The name of the resource group.
46        :type resource_group_name: str
47        :param service_name: The name of the API Management service.
48        :type service_name: str
49        :param product_id: Product identifier. Must be unique in the current
50         API Management service instance.
51        :type product_id: str
52        :param filter: |   Field     |     Usage     |     Supported operators
53         |     Supported functions
54         |</br>|-------------|-------------|-------------|-------------|</br>|
55         name | filter | ge, le, eq, ne, gt, lt | substringof, contains,
56         startswith, endswith | </br>| displayName | filter | ge, le, eq, ne,
57         gt, lt | substringof, contains, startswith, endswith | </br>|
58         description | filter | ge, le, eq, ne, gt, lt | substringof, contains,
59         startswith, endswith | </br>| serviceUrl | filter | ge, le, eq, ne,
60         gt, lt | substringof, contains, startswith, endswith | </br>| path |
61         filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith,
62         endswith | </br>
63        :type filter: str
64        :param top: Number of records to return.
65        :type top: int
66        :param skip: Number of records to skip.
67        :type skip: int
68        :param dict custom_headers: headers that will be added to the request
69        :param bool raw: returns the direct response alongside the
70         deserialized response
71        :param operation_config: :ref:`Operation configuration
72         overrides<msrest:optionsforoperations>`.
73        :return: An iterator like instance of ApiContract
74        :rtype:
75         ~azure.mgmt.apimanagement.models.ApiContractPaged[~azure.mgmt.apimanagement.models.ApiContract]
76        :raises:
77         :class:`ErrorResponseException<azure.mgmt.apimanagement.models.ErrorResponseException>`
78        """
79        def prepare_request(next_link=None):
80            if not next_link:
81                # Construct URL
82                url = self.list_by_product.metadata['url']
83                path_format_arguments = {
84                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
85                    'serviceName': self._serialize.url("service_name", service_name, 'str', max_length=50, min_length=1, pattern=r'^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$'),
86                    'productId': self._serialize.url("product_id", product_id, 'str', max_length=256, min_length=1),
87                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
88                }
89                url = self._client.format_url(url, **path_format_arguments)
90
91                # Construct parameters
92                query_parameters = {}
93                if filter is not None:
94                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
95                if top is not None:
96                    query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=1)
97                if skip is not None:
98                    query_parameters['$skip'] = self._serialize.query("skip", skip, 'int', minimum=0)
99                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
100
101            else:
102                url = next_link
103                query_parameters = {}
104
105            # Construct headers
106            header_parameters = {}
107            header_parameters['Accept'] = 'application/json'
108            if self.config.generate_client_request_id:
109                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
110            if custom_headers:
111                header_parameters.update(custom_headers)
112            if self.config.accept_language is not None:
113                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
114
115            # Construct and send request
116            request = self._client.get(url, query_parameters, header_parameters)
117            return request
118
119        def internal_paging(next_link=None):
120            request = prepare_request(next_link)
121
122            response = self._client.send(request, stream=False, **operation_config)
123
124            if response.status_code not in [200]:
125                raise models.ErrorResponseException(self._deserialize, response)
126
127            return response
128
129        # Deserialize response
130        header_dict = None
131        if raw:
132            header_dict = {}
133        deserialized = models.ApiContractPaged(internal_paging, self._deserialize.dependencies, header_dict)
134
135        return deserialized
136    list_by_product.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/apis'}
137
138    def check_entity_exists(
139            self, resource_group_name, service_name, product_id, api_id, custom_headers=None, raw=False, **operation_config):
140        """Checks that API entity specified by identifier is associated with the
141        Product entity.
142
143        :param resource_group_name: The name of the resource group.
144        :type resource_group_name: str
145        :param service_name: The name of the API Management service.
146        :type service_name: str
147        :param product_id: Product identifier. Must be unique in the current
148         API Management service instance.
149        :type product_id: str
150        :param api_id: API revision identifier. Must be unique in the current
151         API Management service instance. Non-current revision has ;rev=n as a
152         suffix where n is the revision number.
153        :type api_id: str
154        :param dict custom_headers: headers that will be added to the request
155        :param bool raw: returns the direct response alongside the
156         deserialized response
157        :param operation_config: :ref:`Operation configuration
158         overrides<msrest:optionsforoperations>`.
159        :return: None or ClientRawResponse if raw=true
160        :rtype: None or ~msrest.pipeline.ClientRawResponse
161        :raises:
162         :class:`ErrorResponseException<azure.mgmt.apimanagement.models.ErrorResponseException>`
163        """
164        # Construct URL
165        url = self.check_entity_exists.metadata['url']
166        path_format_arguments = {
167            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
168            'serviceName': self._serialize.url("service_name", service_name, 'str', max_length=50, min_length=1, pattern=r'^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$'),
169            'productId': self._serialize.url("product_id", product_id, 'str', max_length=256, min_length=1),
170            'apiId': self._serialize.url("api_id", api_id, 'str', max_length=256, min_length=1, pattern=r'^[^*#&+:<>?]+$'),
171            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
172        }
173        url = self._client.format_url(url, **path_format_arguments)
174
175        # Construct parameters
176        query_parameters = {}
177        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
178
179        # Construct headers
180        header_parameters = {}
181        if self.config.generate_client_request_id:
182            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
183        if custom_headers:
184            header_parameters.update(custom_headers)
185        if self.config.accept_language is not None:
186            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
187
188        # Construct and send request
189        request = self._client.head(url, query_parameters, header_parameters)
190        response = self._client.send(request, stream=False, **operation_config)
191
192        if response.status_code not in [204]:
193            raise models.ErrorResponseException(self._deserialize, response)
194
195        if raw:
196            client_raw_response = ClientRawResponse(None, response)
197            return client_raw_response
198    check_entity_exists.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/apis/{apiId}'}
199
200    def create_or_update(
201            self, resource_group_name, service_name, product_id, api_id, custom_headers=None, raw=False, **operation_config):
202        """Adds an API to the specified product.
203
204        :param resource_group_name: The name of the resource group.
205        :type resource_group_name: str
206        :param service_name: The name of the API Management service.
207        :type service_name: str
208        :param product_id: Product identifier. Must be unique in the current
209         API Management service instance.
210        :type product_id: str
211        :param api_id: API revision identifier. Must be unique in the current
212         API Management service instance. Non-current revision has ;rev=n as a
213         suffix where n is the revision number.
214        :type api_id: str
215        :param dict custom_headers: headers that will be added to the request
216        :param bool raw: returns the direct response alongside the
217         deserialized response
218        :param operation_config: :ref:`Operation configuration
219         overrides<msrest:optionsforoperations>`.
220        :return: ApiContract or ClientRawResponse if raw=true
221        :rtype: ~azure.mgmt.apimanagement.models.ApiContract or
222         ~msrest.pipeline.ClientRawResponse
223        :raises:
224         :class:`ErrorResponseException<azure.mgmt.apimanagement.models.ErrorResponseException>`
225        """
226        # Construct URL
227        url = self.create_or_update.metadata['url']
228        path_format_arguments = {
229            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
230            'serviceName': self._serialize.url("service_name", service_name, 'str', max_length=50, min_length=1, pattern=r'^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$'),
231            'productId': self._serialize.url("product_id", product_id, 'str', max_length=256, min_length=1),
232            'apiId': self._serialize.url("api_id", api_id, 'str', max_length=256, min_length=1, pattern=r'^[^*#&+:<>?]+$'),
233            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
234        }
235        url = self._client.format_url(url, **path_format_arguments)
236
237        # Construct parameters
238        query_parameters = {}
239        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
240
241        # Construct headers
242        header_parameters = {}
243        header_parameters['Accept'] = 'application/json'
244        if self.config.generate_client_request_id:
245            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
246        if custom_headers:
247            header_parameters.update(custom_headers)
248        if self.config.accept_language is not None:
249            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
250
251        # Construct and send request
252        request = self._client.put(url, query_parameters, header_parameters)
253        response = self._client.send(request, stream=False, **operation_config)
254
255        if response.status_code not in [200, 201]:
256            raise models.ErrorResponseException(self._deserialize, response)
257
258        deserialized = None
259        if response.status_code == 200:
260            deserialized = self._deserialize('ApiContract', response)
261        if response.status_code == 201:
262            deserialized = self._deserialize('ApiContract', response)
263
264        if raw:
265            client_raw_response = ClientRawResponse(deserialized, response)
266            return client_raw_response
267
268        return deserialized
269    create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/apis/{apiId}'}
270
271    def delete(
272            self, resource_group_name, service_name, product_id, api_id, custom_headers=None, raw=False, **operation_config):
273        """Deletes the specified API from the specified product.
274
275        :param resource_group_name: The name of the resource group.
276        :type resource_group_name: str
277        :param service_name: The name of the API Management service.
278        :type service_name: str
279        :param product_id: Product identifier. Must be unique in the current
280         API Management service instance.
281        :type product_id: str
282        :param api_id: API revision identifier. Must be unique in the current
283         API Management service instance. Non-current revision has ;rev=n as a
284         suffix where n is the revision number.
285        :type api_id: str
286        :param dict custom_headers: headers that will be added to the request
287        :param bool raw: returns the direct response alongside the
288         deserialized response
289        :param operation_config: :ref:`Operation configuration
290         overrides<msrest:optionsforoperations>`.
291        :return: None or ClientRawResponse if raw=true
292        :rtype: None or ~msrest.pipeline.ClientRawResponse
293        :raises:
294         :class:`ErrorResponseException<azure.mgmt.apimanagement.models.ErrorResponseException>`
295        """
296        # Construct URL
297        url = self.delete.metadata['url']
298        path_format_arguments = {
299            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
300            'serviceName': self._serialize.url("service_name", service_name, 'str', max_length=50, min_length=1, pattern=r'^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$'),
301            'productId': self._serialize.url("product_id", product_id, 'str', max_length=256, min_length=1),
302            'apiId': self._serialize.url("api_id", api_id, 'str', max_length=256, min_length=1, pattern=r'^[^*#&+:<>?]+$'),
303            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
304        }
305        url = self._client.format_url(url, **path_format_arguments)
306
307        # Construct parameters
308        query_parameters = {}
309        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
310
311        # Construct headers
312        header_parameters = {}
313        if self.config.generate_client_request_id:
314            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
315        if custom_headers:
316            header_parameters.update(custom_headers)
317        if self.config.accept_language is not None:
318            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
319
320        # Construct and send request
321        request = self._client.delete(url, query_parameters, header_parameters)
322        response = self._client.send(request, stream=False, **operation_config)
323
324        if response.status_code not in [200, 204]:
325            raise models.ErrorResponseException(self._deserialize, response)
326
327        if raw:
328            client_raw_response = ClientRawResponse(None, response)
329            return client_raw_response
330    delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productId}/apis/{apiId}'}
331