|
6 | 6 | # Changes may cause incorrect behavior and will be lost if the code is regenerated. |
7 | 7 | # -------------------------------------------------------------------------- |
8 | 8 |
|
9 | | -from typing import TYPE_CHECKING |
| 9 | +import sys |
| 10 | +from typing import Any, TYPE_CHECKING |
10 | 11 |
|
11 | 12 | from azure.core.configuration import Configuration |
12 | 13 | from azure.core.pipeline import policies |
13 | | -from azure.mgmt.core.policies import ARMHttpLoggingPolicy |
| 14 | +from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy |
14 | 15 |
|
15 | 16 | from ._version import VERSION |
16 | 17 |
|
| 18 | +if sys.version_info >= (3, 8): |
| 19 | + from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports |
| 20 | +else: |
| 21 | + from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports |
| 22 | + |
17 | 23 | if TYPE_CHECKING: |
18 | 24 | # pylint: disable=unused-import,ungrouped-imports |
19 | | - from typing import Any |
20 | | - |
21 | 25 | from azure.core.credentials import TokenCredential |
22 | 26 |
|
23 | 27 |
|
24 | | -class RelayAPIConfiguration(Configuration): |
| 28 | +class RelayAPIConfiguration(Configuration): # pylint: disable=too-many-instance-attributes |
25 | 29 | """Configuration for RelayAPI. |
26 | 30 |
|
27 | 31 | Note that all parameters used to create this instance are saved as instance |
28 | 32 | attributes. |
29 | 33 |
|
30 | | - :param credential: Credential needed for the client to connect to Azure. |
| 34 | + :param credential: Credential needed for the client to connect to Azure. Required. |
31 | 35 | :type credential: ~azure.core.credentials.TokenCredential |
32 | | - :param subscription_id: Subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. |
| 36 | + :param subscription_id: Subscription credentials which uniquely identify the Microsoft Azure |
| 37 | + subscription. The subscription ID forms part of the URI for every service call. Required. |
33 | 38 | :type subscription_id: str |
| 39 | + :keyword api_version: Api Version. Default value is "2021-11-01". Note that overriding this |
| 40 | + default value may result in unsupported behavior. |
| 41 | + :paramtype api_version: str |
34 | 42 | """ |
35 | 43 |
|
36 | | - def __init__( |
37 | | - self, |
38 | | - credential, # type: "TokenCredential" |
39 | | - subscription_id, # type: str |
40 | | - **kwargs # type: Any |
41 | | - ): |
42 | | - # type: (...) -> None |
| 44 | + def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: |
| 45 | + super(RelayAPIConfiguration, self).__init__(**kwargs) |
| 46 | + api_version = kwargs.pop("api_version", "2021-11-01") # type: Literal["2021-11-01"] |
| 47 | + |
43 | 48 | if credential is None: |
44 | 49 | raise ValueError("Parameter 'credential' must not be None.") |
45 | 50 | if subscription_id is None: |
46 | 51 | raise ValueError("Parameter 'subscription_id' must not be None.") |
47 | | - super(RelayAPIConfiguration, self).__init__(**kwargs) |
48 | 52 |
|
49 | 53 | self.credential = credential |
50 | 54 | self.subscription_id = subscription_id |
51 | | - self.api_version = "2017-04-01" |
52 | | - self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) |
53 | | - kwargs.setdefault('sdk_moniker', 'mgmt-relay/{}'.format(VERSION)) |
| 55 | + self.api_version = api_version |
| 56 | + self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) |
| 57 | + kwargs.setdefault("sdk_moniker", "mgmt-relay/{}".format(VERSION)) |
54 | 58 | self._configure(**kwargs) |
55 | 59 |
|
56 | 60 | def _configure( |
57 | | - self, |
58 | | - **kwargs # type: Any |
| 61 | + self, **kwargs # type: Any |
59 | 62 | ): |
60 | 63 | # type: (...) -> None |
61 | | - self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) |
62 | | - self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) |
63 | | - self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) |
64 | | - self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) |
65 | | - self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs) |
66 | | - self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) |
67 | | - self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) |
68 | | - self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) |
69 | | - self.authentication_policy = kwargs.get('authentication_policy') |
| 64 | + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) |
| 65 | + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) |
| 66 | + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) |
| 67 | + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) |
| 68 | + self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs) |
| 69 | + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) |
| 70 | + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) |
| 71 | + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) |
| 72 | + self.authentication_policy = kwargs.get("authentication_policy") |
70 | 73 | if self.credential and not self.authentication_policy: |
71 | | - self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) |
| 74 | + self.authentication_policy = ARMChallengeAuthenticationPolicy( |
| 75 | + self.credential, *self.credential_scopes, **kwargs |
| 76 | + ) |
0 commit comments