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 TagResourceOperations(object):
19    """TagResourceOperations 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_service(
42            self, resource_group_name, service_name, filter=None, top=None, skip=None, custom_headers=None, raw=False, **operation_config):
43        """Lists a collection of resources associated with tags.
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 filter: |   Field     |     Usage     |     Supported operators
50         |     Supported functions
51         |</br>|-------------|-------------|-------------|-------------|</br>|
52         aid | filter | ge, le, eq, ne, gt, lt | substringof, contains,
53         startswith, endswith | </br>| name | filter | ge, le, eq, ne, gt, lt |
54         substringof, contains, startswith, endswith | </br>| displayName |
55         filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith,
56         endswith | </br>| apiName | filter | ge, le, eq, ne, gt, lt |
57         substringof, contains, startswith, endswith | </br>| apiRevision |
58         filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith,
59         endswith | </br>| path | filter | ge, le, eq, ne, gt, lt |
60         substringof, contains, startswith, endswith | </br>| description |
61         filter | ge, le, eq, ne, gt, lt | substringof, contains, startswith,
62         endswith | </br>| serviceUrl | filter | ge, le, eq, ne, gt, lt |
63         substringof, contains, startswith, endswith | </br>| method | filter |
64         ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
65         </br>| urlTemplate | filter | ge, le, eq, ne, gt, lt | substringof,
66         contains, startswith, endswith | </br>| terms | filter | ge, le, eq,
67         ne, gt, lt | substringof, contains, startswith, endswith | </br>|
68         state | filter | eq |     | </br>| isCurrent | filter | eq |     |
69         </br>
70        :type filter: str
71        :param top: Number of records to return.
72        :type top: int
73        :param skip: Number of records to skip.
74        :type skip: int
75        :param dict custom_headers: headers that will be added to the request
76        :param bool raw: returns the direct response alongside the
77         deserialized response
78        :param operation_config: :ref:`Operation configuration
79         overrides<msrest:optionsforoperations>`.
80        :return: An iterator like instance of TagResourceContract
81        :rtype:
82         ~azure.mgmt.apimanagement.models.TagResourceContractPaged[~azure.mgmt.apimanagement.models.TagResourceContract]
83        :raises:
84         :class:`ErrorResponseException<azure.mgmt.apimanagement.models.ErrorResponseException>`
85        """
86        def prepare_request(next_link=None):
87            if not next_link:
88                # Construct URL
89                url = self.list_by_service.metadata['url']
90                path_format_arguments = {
91                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
92                    '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])?$'),
93                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
94                }
95                url = self._client.format_url(url, **path_format_arguments)
96
97                # Construct parameters
98                query_parameters = {}
99                if filter is not None:
100                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
101                if top is not None:
102                    query_parameters['$top'] = self._serialize.query("top", top, 'int', minimum=1)
103                if skip is not None:
104                    query_parameters['$skip'] = self._serialize.query("skip", skip, 'int', minimum=0)
105                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
106
107            else:
108                url = next_link
109                query_parameters = {}
110
111            # Construct headers
112            header_parameters = {}
113            header_parameters['Accept'] = 'application/json'
114            if self.config.generate_client_request_id:
115                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
116            if custom_headers:
117                header_parameters.update(custom_headers)
118            if self.config.accept_language is not None:
119                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
120
121            # Construct and send request
122            request = self._client.get(url, query_parameters, header_parameters)
123            return request
124
125        def internal_paging(next_link=None):
126            request = prepare_request(next_link)
127
128            response = self._client.send(request, stream=False, **operation_config)
129
130            if response.status_code not in [200]:
131                raise models.ErrorResponseException(self._deserialize, response)
132
133            return response
134
135        # Deserialize response
136        header_dict = None
137        if raw:
138            header_dict = {}
139        deserialized = models.TagResourceContractPaged(internal_paging, self._deserialize.dependencies, header_dict)
140
141        return deserialized
142    list_by_service.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tagResources'}
143