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
14from msrest.polling import LROPoller, NoPolling
15from msrestazure.polling.arm_polling import ARMPolling
16
17from .. import models
18
19
20class NamespacesOperations(object):
21    """NamespacesOperations operations.
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: Client API version. Constant value: "2017-04-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 = "2017-04-01"
38
39        self.config = config
40
41    def check_name_availability_method(
42            self, name, custom_headers=None, raw=False, **operation_config):
43        """Check the specified namespace name availability.
44
45        :param name: The namespace name to check for availability. The
46         namespace name can contain only letters, numbers, and hyphens. The
47         namespace must start with a letter, and it must end with a letter or
48         number.
49        :type name: str
50        :param dict custom_headers: headers that will be added to the request
51        :param bool raw: returns the direct response alongside the
52         deserialized response
53        :param operation_config: :ref:`Operation configuration
54         overrides<msrest:optionsforoperations>`.
55        :return: CheckNameAvailabilityResult or ClientRawResponse if raw=true
56        :rtype: ~azure.mgmt.relay.models.CheckNameAvailabilityResult or
57         ~msrest.pipeline.ClientRawResponse
58        :raises:
59         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
60        """
61        parameters = models.CheckNameAvailability(name=name)
62
63        # Construct URL
64        url = self.check_name_availability_method.metadata['url']
65        path_format_arguments = {
66            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
67        }
68        url = self._client.format_url(url, **path_format_arguments)
69
70        # Construct parameters
71        query_parameters = {}
72        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
73
74        # Construct headers
75        header_parameters = {}
76        header_parameters['Accept'] = 'application/json'
77        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
78        if self.config.generate_client_request_id:
79            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
80        if custom_headers:
81            header_parameters.update(custom_headers)
82        if self.config.accept_language is not None:
83            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
84
85        # Construct body
86        body_content = self._serialize.body(parameters, 'CheckNameAvailability')
87
88        # Construct and send request
89        request = self._client.post(url, query_parameters, header_parameters, body_content)
90        response = self._client.send(request, stream=False, **operation_config)
91
92        if response.status_code not in [200]:
93            raise models.ErrorResponseException(self._deserialize, response)
94
95        deserialized = None
96
97        if response.status_code == 200:
98            deserialized = self._deserialize('CheckNameAvailabilityResult', response)
99
100        if raw:
101            client_raw_response = ClientRawResponse(deserialized, response)
102            return client_raw_response
103
104        return deserialized
105    check_name_availability_method.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Relay/checkNameAvailability'}
106
107    def list(
108            self, custom_headers=None, raw=False, **operation_config):
109        """Lists all the available namespaces within the subscription regardless
110        of the resourceGroups.
111
112        :param dict custom_headers: headers that will be added to the request
113        :param bool raw: returns the direct response alongside the
114         deserialized response
115        :param operation_config: :ref:`Operation configuration
116         overrides<msrest:optionsforoperations>`.
117        :return: An iterator like instance of RelayNamespace
118        :rtype:
119         ~azure.mgmt.relay.models.RelayNamespacePaged[~azure.mgmt.relay.models.RelayNamespace]
120        :raises:
121         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
122        """
123        def internal_paging(next_link=None, raw=False):
124
125            if not next_link:
126                # Construct URL
127                url = self.list.metadata['url']
128                path_format_arguments = {
129                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
130                }
131                url = self._client.format_url(url, **path_format_arguments)
132
133                # Construct parameters
134                query_parameters = {}
135                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
136
137            else:
138                url = next_link
139                query_parameters = {}
140
141            # Construct headers
142            header_parameters = {}
143            header_parameters['Accept'] = 'application/json'
144            if self.config.generate_client_request_id:
145                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
146            if custom_headers:
147                header_parameters.update(custom_headers)
148            if self.config.accept_language is not None:
149                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
150
151            # Construct and send request
152            request = self._client.get(url, query_parameters, header_parameters)
153            response = self._client.send(request, stream=False, **operation_config)
154
155            if response.status_code not in [200]:
156                raise models.ErrorResponseException(self._deserialize, response)
157
158            return response
159
160        # Deserialize response
161        deserialized = models.RelayNamespacePaged(internal_paging, self._deserialize.dependencies)
162
163        if raw:
164            header_dict = {}
165            client_raw_response = models.RelayNamespacePaged(internal_paging, self._deserialize.dependencies, header_dict)
166            return client_raw_response
167
168        return deserialized
169    list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Relay/namespaces'}
170
171    def list_by_resource_group(
172            self, resource_group_name, custom_headers=None, raw=False, **operation_config):
173        """Lists all the available namespaces within the ResourceGroup.
174
175        :param resource_group_name: Name of the Resource group within the
176         Azure subscription.
177        :type resource_group_name: str
178        :param dict custom_headers: headers that will be added to the request
179        :param bool raw: returns the direct response alongside the
180         deserialized response
181        :param operation_config: :ref:`Operation configuration
182         overrides<msrest:optionsforoperations>`.
183        :return: An iterator like instance of RelayNamespace
184        :rtype:
185         ~azure.mgmt.relay.models.RelayNamespacePaged[~azure.mgmt.relay.models.RelayNamespace]
186        :raises:
187         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
188        """
189        def internal_paging(next_link=None, raw=False):
190
191            if not next_link:
192                # Construct URL
193                url = self.list_by_resource_group.metadata['url']
194                path_format_arguments = {
195                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
196                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
197                }
198                url = self._client.format_url(url, **path_format_arguments)
199
200                # Construct parameters
201                query_parameters = {}
202                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
203
204            else:
205                url = next_link
206                query_parameters = {}
207
208            # Construct headers
209            header_parameters = {}
210            header_parameters['Accept'] = 'application/json'
211            if self.config.generate_client_request_id:
212                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
213            if custom_headers:
214                header_parameters.update(custom_headers)
215            if self.config.accept_language is not None:
216                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
217
218            # Construct and send request
219            request = self._client.get(url, query_parameters, header_parameters)
220            response = self._client.send(request, stream=False, **operation_config)
221
222            if response.status_code not in [200]:
223                raise models.ErrorResponseException(self._deserialize, response)
224
225            return response
226
227        # Deserialize response
228        deserialized = models.RelayNamespacePaged(internal_paging, self._deserialize.dependencies)
229
230        if raw:
231            header_dict = {}
232            client_raw_response = models.RelayNamespacePaged(internal_paging, self._deserialize.dependencies, header_dict)
233            return client_raw_response
234
235        return deserialized
236    list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces'}
237
238
239    def _create_or_update_initial(
240            self, resource_group_name, namespace_name, parameters, custom_headers=None, raw=False, **operation_config):
241        # Construct URL
242        url = self.create_or_update.metadata['url']
243        path_format_arguments = {
244            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
245            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
246            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
247        }
248        url = self._client.format_url(url, **path_format_arguments)
249
250        # Construct parameters
251        query_parameters = {}
252        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
253
254        # Construct headers
255        header_parameters = {}
256        header_parameters['Accept'] = 'application/json'
257        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
258        if self.config.generate_client_request_id:
259            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
260        if custom_headers:
261            header_parameters.update(custom_headers)
262        if self.config.accept_language is not None:
263            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
264
265        # Construct body
266        body_content = self._serialize.body(parameters, 'RelayNamespace')
267
268        # Construct and send request
269        request = self._client.put(url, query_parameters, header_parameters, body_content)
270        response = self._client.send(request, stream=False, **operation_config)
271
272        if response.status_code not in [200, 201]:
273            raise models.ErrorResponseException(self._deserialize, response)
274
275        deserialized = None
276
277        if response.status_code == 200:
278            deserialized = self._deserialize('RelayNamespace', response)
279        if response.status_code == 201:
280            deserialized = self._deserialize('RelayNamespace', response)
281
282        if raw:
283            client_raw_response = ClientRawResponse(deserialized, response)
284            return client_raw_response
285
286        return deserialized
287
288    def create_or_update(
289            self, resource_group_name, namespace_name, parameters, custom_headers=None, raw=False, polling=True, **operation_config):
290        """Create Azure Relay namespace.
291
292        :param resource_group_name: Name of the Resource group within the
293         Azure subscription.
294        :type resource_group_name: str
295        :param namespace_name: The namespace name
296        :type namespace_name: str
297        :param parameters: Parameters supplied to create a namespace resource.
298        :type parameters: ~azure.mgmt.relay.models.RelayNamespace
299        :param dict custom_headers: headers that will be added to the request
300        :param bool raw: The poller return type is ClientRawResponse, the
301         direct response alongside the deserialized response
302        :param polling: True for ARMPolling, False for no polling, or a
303         polling object for personal polling strategy
304        :return: An instance of LROPoller that returns RelayNamespace or
305         ClientRawResponse<RelayNamespace> if raw==True
306        :rtype:
307         ~msrestazure.azure_operation.AzureOperationPoller[~azure.mgmt.relay.models.RelayNamespace]
308         or
309         ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[~azure.mgmt.relay.models.RelayNamespace]]
310        :raises:
311         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
312        """
313        raw_result = self._create_or_update_initial(
314            resource_group_name=resource_group_name,
315            namespace_name=namespace_name,
316            parameters=parameters,
317            custom_headers=custom_headers,
318            raw=True,
319            **operation_config
320        )
321
322        def get_long_running_output(response):
323            deserialized = self._deserialize('RelayNamespace', response)
324
325            if raw:
326                client_raw_response = ClientRawResponse(deserialized, response)
327                return client_raw_response
328
329            return deserialized
330
331        lro_delay = operation_config.get(
332            'long_running_operation_timeout',
333            self.config.long_running_operation_timeout)
334        if polling is True: polling_method = ARMPolling(lro_delay, **operation_config)
335        elif polling is False: polling_method = NoPolling()
336        else: polling_method = polling
337        return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
338    create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}'}
339
340
341    def _delete_initial(
342            self, resource_group_name, namespace_name, custom_headers=None, raw=False, **operation_config):
343        # Construct URL
344        url = self.delete.metadata['url']
345        path_format_arguments = {
346            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
347            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
348            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
349        }
350        url = self._client.format_url(url, **path_format_arguments)
351
352        # Construct parameters
353        query_parameters = {}
354        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
355
356        # Construct headers
357        header_parameters = {}
358        if self.config.generate_client_request_id:
359            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
360        if custom_headers:
361            header_parameters.update(custom_headers)
362        if self.config.accept_language is not None:
363            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
364
365        # Construct and send request
366        request = self._client.delete(url, query_parameters, header_parameters)
367        response = self._client.send(request, stream=False, **operation_config)
368
369        if response.status_code not in [200, 202, 204]:
370            raise models.ErrorResponseException(self._deserialize, response)
371
372        if raw:
373            client_raw_response = ClientRawResponse(None, response)
374            return client_raw_response
375
376    def delete(
377            self, resource_group_name, namespace_name, custom_headers=None, raw=False, polling=True, **operation_config):
378        """Deletes an existing namespace. This operation also removes all
379        associated resources under the namespace.
380
381        :param resource_group_name: Name of the Resource group within the
382         Azure subscription.
383        :type resource_group_name: str
384        :param namespace_name: The namespace name
385        :type namespace_name: str
386        :param dict custom_headers: headers that will be added to the request
387        :param bool raw: The poller return type is ClientRawResponse, the
388         direct response alongside the deserialized response
389        :param polling: True for ARMPolling, False for no polling, or a
390         polling object for personal polling strategy
391        :return: An instance of LROPoller that returns None or
392         ClientRawResponse<None> if raw==True
393        :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or
394         ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]]
395        :raises:
396         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
397        """
398        raw_result = self._delete_initial(
399            resource_group_name=resource_group_name,
400            namespace_name=namespace_name,
401            custom_headers=custom_headers,
402            raw=True,
403            **operation_config
404        )
405
406        def get_long_running_output(response):
407            if raw:
408                client_raw_response = ClientRawResponse(None, response)
409                return client_raw_response
410
411        lro_delay = operation_config.get(
412            'long_running_operation_timeout',
413            self.config.long_running_operation_timeout)
414        if polling is True: polling_method = ARMPolling(lro_delay, **operation_config)
415        elif polling is False: polling_method = NoPolling()
416        else: polling_method = polling
417        return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
418    delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}'}
419
420    def get(
421            self, resource_group_name, namespace_name, custom_headers=None, raw=False, **operation_config):
422        """Returns the description for the specified namespace.
423
424        :param resource_group_name: Name of the Resource group within the
425         Azure subscription.
426        :type resource_group_name: str
427        :param namespace_name: The namespace name
428        :type namespace_name: str
429        :param dict custom_headers: headers that will be added to the request
430        :param bool raw: returns the direct response alongside the
431         deserialized response
432        :param operation_config: :ref:`Operation configuration
433         overrides<msrest:optionsforoperations>`.
434        :return: RelayNamespace or ClientRawResponse if raw=true
435        :rtype: ~azure.mgmt.relay.models.RelayNamespace or
436         ~msrest.pipeline.ClientRawResponse
437        :raises:
438         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
439        """
440        # Construct URL
441        url = self.get.metadata['url']
442        path_format_arguments = {
443            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
444            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
445            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
446        }
447        url = self._client.format_url(url, **path_format_arguments)
448
449        # Construct parameters
450        query_parameters = {}
451        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
452
453        # Construct headers
454        header_parameters = {}
455        header_parameters['Accept'] = 'application/json'
456        if self.config.generate_client_request_id:
457            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
458        if custom_headers:
459            header_parameters.update(custom_headers)
460        if self.config.accept_language is not None:
461            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
462
463        # Construct and send request
464        request = self._client.get(url, query_parameters, header_parameters)
465        response = self._client.send(request, stream=False, **operation_config)
466
467        if response.status_code not in [200]:
468            raise models.ErrorResponseException(self._deserialize, response)
469
470        deserialized = None
471
472        if response.status_code == 200:
473            deserialized = self._deserialize('RelayNamespace', response)
474
475        if raw:
476            client_raw_response = ClientRawResponse(deserialized, response)
477            return client_raw_response
478
479        return deserialized
480    get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}'}
481
482    def update(
483            self, resource_group_name, namespace_name, tags=None, sku=None, custom_headers=None, raw=False, **operation_config):
484        """Creates or updates a namespace. Once created, this namespace's resource
485        manifest is immutable. This operation is idempotent.
486
487        :param resource_group_name: Name of the Resource group within the
488         Azure subscription.
489        :type resource_group_name: str
490        :param namespace_name: The namespace name
491        :type namespace_name: str
492        :param tags: Resource tags.
493        :type tags: dict[str, str]
494        :param sku: SKU of the namespace.
495        :type sku: ~azure.mgmt.relay.models.Sku
496        :param dict custom_headers: headers that will be added to the request
497        :param bool raw: returns the direct response alongside the
498         deserialized response
499        :param operation_config: :ref:`Operation configuration
500         overrides<msrest:optionsforoperations>`.
501        :return: RelayNamespace or ClientRawResponse if raw=true
502        :rtype: ~azure.mgmt.relay.models.RelayNamespace or
503         ~msrest.pipeline.ClientRawResponse
504        :raises:
505         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
506        """
507        parameters = models.RelayUpdateParameters(tags=tags, sku=sku)
508
509        # Construct URL
510        url = self.update.metadata['url']
511        path_format_arguments = {
512            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
513            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
514            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
515        }
516        url = self._client.format_url(url, **path_format_arguments)
517
518        # Construct parameters
519        query_parameters = {}
520        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
521
522        # Construct headers
523        header_parameters = {}
524        header_parameters['Accept'] = 'application/json'
525        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
526        if self.config.generate_client_request_id:
527            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
528        if custom_headers:
529            header_parameters.update(custom_headers)
530        if self.config.accept_language is not None:
531            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
532
533        # Construct body
534        body_content = self._serialize.body(parameters, 'RelayUpdateParameters')
535
536        # Construct and send request
537        request = self._client.patch(url, query_parameters, header_parameters, body_content)
538        response = self._client.send(request, stream=False, **operation_config)
539
540        if response.status_code not in [200, 201]:
541            raise models.ErrorResponseException(self._deserialize, response)
542
543        deserialized = None
544
545        if response.status_code == 200:
546            deserialized = self._deserialize('RelayNamespace', response)
547        if response.status_code == 201:
548            deserialized = self._deserialize('RelayNamespace', response)
549
550        if raw:
551            client_raw_response = ClientRawResponse(deserialized, response)
552            return client_raw_response
553
554        return deserialized
555    update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}'}
556
557    def list_authorization_rules(
558            self, resource_group_name, namespace_name, custom_headers=None, raw=False, **operation_config):
559        """Authorization rules for a namespace.
560
561        :param resource_group_name: Name of the Resource group within the
562         Azure subscription.
563        :type resource_group_name: str
564        :param namespace_name: The namespace name
565        :type namespace_name: str
566        :param dict custom_headers: headers that will be added to the request
567        :param bool raw: returns the direct response alongside the
568         deserialized response
569        :param operation_config: :ref:`Operation configuration
570         overrides<msrest:optionsforoperations>`.
571        :return: An iterator like instance of AuthorizationRule
572        :rtype:
573         ~azure.mgmt.relay.models.AuthorizationRulePaged[~azure.mgmt.relay.models.AuthorizationRule]
574        :raises:
575         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
576        """
577        def internal_paging(next_link=None, raw=False):
578
579            if not next_link:
580                # Construct URL
581                url = self.list_authorization_rules.metadata['url']
582                path_format_arguments = {
583                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
584                    'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
585                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
586                }
587                url = self._client.format_url(url, **path_format_arguments)
588
589                # Construct parameters
590                query_parameters = {}
591                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
592
593            else:
594                url = next_link
595                query_parameters = {}
596
597            # Construct headers
598            header_parameters = {}
599            header_parameters['Accept'] = 'application/json'
600            if self.config.generate_client_request_id:
601                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
602            if custom_headers:
603                header_parameters.update(custom_headers)
604            if self.config.accept_language is not None:
605                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
606
607            # Construct and send request
608            request = self._client.get(url, query_parameters, header_parameters)
609            response = self._client.send(request, stream=False, **operation_config)
610
611            if response.status_code not in [200]:
612                raise models.ErrorResponseException(self._deserialize, response)
613
614            return response
615
616        # Deserialize response
617        deserialized = models.AuthorizationRulePaged(internal_paging, self._deserialize.dependencies)
618
619        if raw:
620            header_dict = {}
621            client_raw_response = models.AuthorizationRulePaged(internal_paging, self._deserialize.dependencies, header_dict)
622            return client_raw_response
623
624        return deserialized
625    list_authorization_rules.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules'}
626
627    def create_or_update_authorization_rule(
628            self, resource_group_name, namespace_name, authorization_rule_name, rights, custom_headers=None, raw=False, **operation_config):
629        """Creates or updates an authorization rule for a namespace.
630
631        :param resource_group_name: Name of the Resource group within the
632         Azure subscription.
633        :type resource_group_name: str
634        :param namespace_name: The namespace name
635        :type namespace_name: str
636        :param authorization_rule_name: The authorization rule name.
637        :type authorization_rule_name: str
638        :param rights: The rights associated with the rule.
639        :type rights: list[str or ~azure.mgmt.relay.models.AccessRights]
640        :param dict custom_headers: headers that will be added to the request
641        :param bool raw: returns the direct response alongside the
642         deserialized response
643        :param operation_config: :ref:`Operation configuration
644         overrides<msrest:optionsforoperations>`.
645        :return: AuthorizationRule or ClientRawResponse if raw=true
646        :rtype: ~azure.mgmt.relay.models.AuthorizationRule or
647         ~msrest.pipeline.ClientRawResponse
648        :raises:
649         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
650        """
651        parameters = models.AuthorizationRule(rights=rights)
652
653        # Construct URL
654        url = self.create_or_update_authorization_rule.metadata['url']
655        path_format_arguments = {
656            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
657            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
658            'authorizationRuleName': self._serialize.url("authorization_rule_name", authorization_rule_name, 'str', min_length=1),
659            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
660        }
661        url = self._client.format_url(url, **path_format_arguments)
662
663        # Construct parameters
664        query_parameters = {}
665        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
666
667        # Construct headers
668        header_parameters = {}
669        header_parameters['Accept'] = 'application/json'
670        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
671        if self.config.generate_client_request_id:
672            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
673        if custom_headers:
674            header_parameters.update(custom_headers)
675        if self.config.accept_language is not None:
676            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
677
678        # Construct body
679        body_content = self._serialize.body(parameters, 'AuthorizationRule')
680
681        # Construct and send request
682        request = self._client.put(url, query_parameters, header_parameters, body_content)
683        response = self._client.send(request, stream=False, **operation_config)
684
685        if response.status_code not in [200]:
686            raise models.ErrorResponseException(self._deserialize, response)
687
688        deserialized = None
689
690        if response.status_code == 200:
691            deserialized = self._deserialize('AuthorizationRule', response)
692
693        if raw:
694            client_raw_response = ClientRawResponse(deserialized, response)
695            return client_raw_response
696
697        return deserialized
698    create_or_update_authorization_rule.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules/{authorizationRuleName}'}
699
700    def delete_authorization_rule(
701            self, resource_group_name, namespace_name, authorization_rule_name, custom_headers=None, raw=False, **operation_config):
702        """Deletes a namespace authorization rule.
703
704        :param resource_group_name: Name of the Resource group within the
705         Azure subscription.
706        :type resource_group_name: str
707        :param namespace_name: The namespace name
708        :type namespace_name: str
709        :param authorization_rule_name: The authorization rule name.
710        :type authorization_rule_name: str
711        :param dict custom_headers: headers that will be added to the request
712        :param bool raw: returns the direct response alongside the
713         deserialized response
714        :param operation_config: :ref:`Operation configuration
715         overrides<msrest:optionsforoperations>`.
716        :return: None or ClientRawResponse if raw=true
717        :rtype: None or ~msrest.pipeline.ClientRawResponse
718        :raises:
719         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
720        """
721        # Construct URL
722        url = self.delete_authorization_rule.metadata['url']
723        path_format_arguments = {
724            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
725            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
726            'authorizationRuleName': self._serialize.url("authorization_rule_name", authorization_rule_name, 'str', min_length=1),
727            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
728        }
729        url = self._client.format_url(url, **path_format_arguments)
730
731        # Construct parameters
732        query_parameters = {}
733        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
734
735        # Construct headers
736        header_parameters = {}
737        if self.config.generate_client_request_id:
738            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
739        if custom_headers:
740            header_parameters.update(custom_headers)
741        if self.config.accept_language is not None:
742            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
743
744        # Construct and send request
745        request = self._client.delete(url, query_parameters, header_parameters)
746        response = self._client.send(request, stream=False, **operation_config)
747
748        if response.status_code not in [200, 204]:
749            raise models.ErrorResponseException(self._deserialize, response)
750
751        if raw:
752            client_raw_response = ClientRawResponse(None, response)
753            return client_raw_response
754    delete_authorization_rule.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules/{authorizationRuleName}'}
755
756    def get_authorization_rule(
757            self, resource_group_name, namespace_name, authorization_rule_name, custom_headers=None, raw=False, **operation_config):
758        """Authorization rule for a namespace by name.
759
760        :param resource_group_name: Name of the Resource group within the
761         Azure subscription.
762        :type resource_group_name: str
763        :param namespace_name: The namespace name
764        :type namespace_name: str
765        :param authorization_rule_name: The authorization rule name.
766        :type authorization_rule_name: str
767        :param dict custom_headers: headers that will be added to the request
768        :param bool raw: returns the direct response alongside the
769         deserialized response
770        :param operation_config: :ref:`Operation configuration
771         overrides<msrest:optionsforoperations>`.
772        :return: AuthorizationRule or ClientRawResponse if raw=true
773        :rtype: ~azure.mgmt.relay.models.AuthorizationRule or
774         ~msrest.pipeline.ClientRawResponse
775        :raises:
776         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
777        """
778        # Construct URL
779        url = self.get_authorization_rule.metadata['url']
780        path_format_arguments = {
781            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
782            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
783            'authorizationRuleName': self._serialize.url("authorization_rule_name", authorization_rule_name, 'str', min_length=1),
784            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
785        }
786        url = self._client.format_url(url, **path_format_arguments)
787
788        # Construct parameters
789        query_parameters = {}
790        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
791
792        # Construct headers
793        header_parameters = {}
794        header_parameters['Accept'] = 'application/json'
795        if self.config.generate_client_request_id:
796            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
797        if custom_headers:
798            header_parameters.update(custom_headers)
799        if self.config.accept_language is not None:
800            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
801
802        # Construct and send request
803        request = self._client.get(url, query_parameters, header_parameters)
804        response = self._client.send(request, stream=False, **operation_config)
805
806        if response.status_code not in [200]:
807            raise models.ErrorResponseException(self._deserialize, response)
808
809        deserialized = None
810
811        if response.status_code == 200:
812            deserialized = self._deserialize('AuthorizationRule', response)
813
814        if raw:
815            client_raw_response = ClientRawResponse(deserialized, response)
816            return client_raw_response
817
818        return deserialized
819    get_authorization_rule.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules/{authorizationRuleName}'}
820
821    def list_keys(
822            self, resource_group_name, namespace_name, authorization_rule_name, custom_headers=None, raw=False, **operation_config):
823        """Primary and secondary connection strings to the namespace.
824
825        :param resource_group_name: Name of the Resource group within the
826         Azure subscription.
827        :type resource_group_name: str
828        :param namespace_name: The namespace name
829        :type namespace_name: str
830        :param authorization_rule_name: The authorization rule name.
831        :type authorization_rule_name: str
832        :param dict custom_headers: headers that will be added to the request
833        :param bool raw: returns the direct response alongside the
834         deserialized response
835        :param operation_config: :ref:`Operation configuration
836         overrides<msrest:optionsforoperations>`.
837        :return: AccessKeys or ClientRawResponse if raw=true
838        :rtype: ~azure.mgmt.relay.models.AccessKeys or
839         ~msrest.pipeline.ClientRawResponse
840        :raises:
841         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
842        """
843        # Construct URL
844        url = self.list_keys.metadata['url']
845        path_format_arguments = {
846            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
847            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
848            'authorizationRuleName': self._serialize.url("authorization_rule_name", authorization_rule_name, 'str', min_length=1),
849            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
850        }
851        url = self._client.format_url(url, **path_format_arguments)
852
853        # Construct parameters
854        query_parameters = {}
855        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
856
857        # Construct headers
858        header_parameters = {}
859        header_parameters['Accept'] = 'application/json'
860        if self.config.generate_client_request_id:
861            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
862        if custom_headers:
863            header_parameters.update(custom_headers)
864        if self.config.accept_language is not None:
865            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
866
867        # Construct and send request
868        request = self._client.post(url, query_parameters, header_parameters)
869        response = self._client.send(request, stream=False, **operation_config)
870
871        if response.status_code not in [200]:
872            raise models.ErrorResponseException(self._deserialize, response)
873
874        deserialized = None
875
876        if response.status_code == 200:
877            deserialized = self._deserialize('AccessKeys', response)
878
879        if raw:
880            client_raw_response = ClientRawResponse(deserialized, response)
881            return client_raw_response
882
883        return deserialized
884    list_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules/{authorizationRuleName}/listKeys'}
885
886    def regenerate_keys(
887            self, resource_group_name, namespace_name, authorization_rule_name, key_type, key=None, custom_headers=None, raw=False, **operation_config):
888        """Regenerates the primary or secondary connection strings to the
889        namespace.
890
891        :param resource_group_name: Name of the Resource group within the
892         Azure subscription.
893        :type resource_group_name: str
894        :param namespace_name: The namespace name
895        :type namespace_name: str
896        :param authorization_rule_name: The authorization rule name.
897        :type authorization_rule_name: str
898        :param key_type: The access key to regenerate. Possible values
899         include: 'PrimaryKey', 'SecondaryKey'
900        :type key_type: str or ~azure.mgmt.relay.models.KeyType
901        :param key: Optional. If the key value is provided, this is set to key
902         type, or autogenerated key value set for key type.
903        :type key: str
904        :param dict custom_headers: headers that will be added to the request
905        :param bool raw: returns the direct response alongside the
906         deserialized response
907        :param operation_config: :ref:`Operation configuration
908         overrides<msrest:optionsforoperations>`.
909        :return: AccessKeys or ClientRawResponse if raw=true
910        :rtype: ~azure.mgmt.relay.models.AccessKeys or
911         ~msrest.pipeline.ClientRawResponse
912        :raises:
913         :class:`ErrorResponseException<azure.mgmt.relay.models.ErrorResponseException>`
914        """
915        parameters = models.RegenerateAccessKeyParameters(key_type=key_type, key=key)
916
917        # Construct URL
918        url = self.regenerate_keys.metadata['url']
919        path_format_arguments = {
920            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
921            'namespaceName': self._serialize.url("namespace_name", namespace_name, 'str', max_length=50, min_length=6),
922            'authorizationRuleName': self._serialize.url("authorization_rule_name", authorization_rule_name, 'str', min_length=1),
923            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
924        }
925        url = self._client.format_url(url, **path_format_arguments)
926
927        # Construct parameters
928        query_parameters = {}
929        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
930
931        # Construct headers
932        header_parameters = {}
933        header_parameters['Accept'] = 'application/json'
934        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
935        if self.config.generate_client_request_id:
936            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
937        if custom_headers:
938            header_parameters.update(custom_headers)
939        if self.config.accept_language is not None:
940            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
941
942        # Construct body
943        body_content = self._serialize.body(parameters, 'RegenerateAccessKeyParameters')
944
945        # Construct and send request
946        request = self._client.post(url, query_parameters, header_parameters, body_content)
947        response = self._client.send(request, stream=False, **operation_config)
948
949        if response.status_code not in [200]:
950            raise models.ErrorResponseException(self._deserialize, response)
951
952        deserialized = None
953
954        if response.status_code == 200:
955            deserialized = self._deserialize('AccessKeys', response)
956
957        if raw:
958            client_raw_response = ClientRawResponse(deserialized, response)
959            return client_raw_response
960
961        return deserialized
962    regenerate_keys.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Relay/namespaces/{namespaceName}/authorizationRules/{authorizationRuleName}/regenerateKeys'}
963