1# --------------------------------------------------------------------------
2#
3# Copyright (c) Microsoft Corporation. All rights reserved.
4#
5# The MIT License (MIT)
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the ""Software""), to
9# deal in the Software without restriction, including without limitation the
10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11# sell copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23# IN THE SOFTWARE.
24#
25# --------------------------------------------------------------------------
26from collections.abc import Iterable
27from azure.core import AsyncPipelineClient
28from .policies import (
29 AsyncARMAutoResourceProviderRegistrationPolicy,
30 ARMHttpLoggingPolicy,
31)
32
33
34class AsyncARMPipelineClient(AsyncPipelineClient):
35 """A pipeline client designed for ARM explicitly.
36
37 :param str base_url: URL for the request.
38 :keyword AsyncPipeline pipeline: If omitted, a Pipeline object is created and returned.
39 :keyword list[AsyncHTTPPolicy] policies: If omitted, the standard policies of the configuration object is used.
40 :keyword per_call_policies: If specified, the policies will be added into the policy list before RetryPolicy
41 :paramtype per_call_policies: Union[AsyncHTTPPolicy, SansIOHTTPPolicy,
42 list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]
43 :keyword per_retry_policies: If specified, the policies will be added into the policy list after RetryPolicy
44 :paramtype per_retry_policies: Union[AsyncHTTPPolicy, SansIOHTTPPolicy,
45 list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]
46 :keyword AsyncHttpTransport transport: If omitted, AioHttpTransport is used for asynchronous transport.
47 """
48
49 def __init__(self, base_url, **kwargs):
50 if "policies" not in kwargs:
51 if "config" not in kwargs:
52 raise ValueError("Current implementation requires to pass 'config' if you don't pass 'policies'")
53 per_call_policies = kwargs.get("per_call_policies", [])
54 if isinstance(per_call_policies, Iterable):
55 per_call_policies.append(AsyncARMAutoResourceProviderRegistrationPolicy())
56 else:
57 per_call_policies = [
58 per_call_policies,
59 AsyncARMAutoResourceProviderRegistrationPolicy(),
60 ]
61 kwargs["per_call_policies"] = per_call_policies
62 config = kwargs.get("config")
63 if not config.http_logging_policy:
64 config.http_logging_policy = kwargs.get("http_logging_policy", ARMHttpLoggingPolicy(**kwargs))
65 kwargs["config"] = config
66 super(AsyncARMPipelineClient, self).__init__(base_url, **kwargs)