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, Any
27from collections.abc import MutableSequence
28from azure.core import PipelineClient
29from .policies import ARMAutoResourceProviderRegistrationPolicy, ARMHttpLoggingPolicy
30
31HTTPResponseType = TypeVar("HTTPResponseType")
32HTTPRequestType = TypeVar("HTTPRequestType")
33
34
35class ARMPipelineClient(PipelineClient[HTTPRequestType, HTTPResponseType]):
36 """A pipeline client designed for ARM explicitly.
37
38 :param str base_url: URL for the request.
39 :keyword Pipeline pipeline: If omitted, a Pipeline object is created and returned.
40 :keyword list[HTTPPolicy] policies: If omitted, the standard policies of the configuration object is used.
41 :keyword per_call_policies: If specified, the policies will be added into the policy list before RetryPolicy
42 :paramtype per_call_policies: Union[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], 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[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], list[SansIOHTTPPolicy]]
45 :keyword HttpTransport transport: If omitted, RequestsTransport is used for synchronous transport.
46 """
47
48 def __init__(self, base_url: str, **kwargs: Any) -> None:
49 if "policies" not in kwargs:
50 config = kwargs.get("config")
51 if not config:
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, MutableSequence):
55 per_call_policies.append(ARMAutoResourceProviderRegistrationPolicy())
56 else:
57 per_call_policies = [
58 per_call_policies,
59 ARMAutoResourceProviderRegistrationPolicy(),
60 ]
61 kwargs["per_call_policies"] = per_call_policies
62 if not config.http_logging_policy:
63 config.http_logging_policy = kwargs.get("http_logging_policy", ARMHttpLoggingPolicy(**kwargs))
64 kwargs["config"] = config
65 super(ARMPipelineClient, self).__init__(base_url, **kwargs)