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 typing import TypeVar, AsyncContextManager, Any
27from collections.abc import MutableSequence
28from azure.core import AsyncPipelineClient
29from .policies import (
30 AsyncARMAutoResourceProviderRegistrationPolicy,
31 ARMHttpLoggingPolicy,
32)
33
34HTTPRequestType = TypeVar("HTTPRequestType")
35AsyncHTTPResponseType = TypeVar("AsyncHTTPResponseType", bound=AsyncContextManager)
36
37
38class AsyncARMPipelineClient(AsyncPipelineClient[HTTPRequestType, AsyncHTTPResponseType]):
39 """A pipeline client designed for ARM explicitly.
40
41 :param str base_url: URL for the request.
42 :keyword AsyncPipeline pipeline: If omitted, a Pipeline object is created and returned.
43 :keyword list[AsyncHTTPPolicy] policies: If omitted, the standard policies of the configuration object is used.
44 :keyword per_call_policies: If specified, the policies will be added into the policy list before RetryPolicy
45 :paramtype per_call_policies: Union[AsyncHTTPPolicy, SansIOHTTPPolicy,
46 list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]
47 :keyword per_retry_policies: If specified, the policies will be added into the policy list after RetryPolicy
48 :paramtype per_retry_policies: Union[AsyncHTTPPolicy, SansIOHTTPPolicy,
49 list[AsyncHTTPPolicy], list[SansIOHTTPPolicy]]
50 :keyword AsyncHttpTransport transport: If omitted, AioHttpTransport is used for asynchronous transport.
51 """
52
53 def __init__(self, base_url: str, **kwargs: Any):
54 if "policies" not in kwargs:
55 config = kwargs.get("config")
56 if not config:
57 raise ValueError("Current implementation requires to pass 'config' if you don't pass 'policies'")
58 per_call_policies = kwargs.get("per_call_policies", [])
59 if isinstance(per_call_policies, MutableSequence):
60 per_call_policies.append(AsyncARMAutoResourceProviderRegistrationPolicy())
61 else:
62 per_call_policies = [
63 per_call_policies,
64 AsyncARMAutoResourceProviderRegistrationPolicy(),
65 ]
66 kwargs["per_call_policies"] = per_call_policies
67 if not config.http_logging_policy:
68 config.http_logging_policy = kwargs.get("http_logging_policy", ARMHttpLoggingPolicy(**kwargs))
69 kwargs["config"] = config
70 super(AsyncARMPipelineClient, self).__init__(base_url, **kwargs)