|
1 | 1 | # coding=utf-8
|
2 | 2 | # --------------------------------------------------------------------------
|
3 | 3 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
4 |
| -# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for |
| 5 | +# license information. |
| 6 | +# |
5 | 7 | # Code generated by Microsoft (R) AutoRest Code Generator.
|
6 |
| -# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 8 | +# Changes may cause incorrect behavior and will be lost if the code is |
| 9 | +# regenerated. |
7 | 10 | # --------------------------------------------------------------------------
|
8 | 11 |
|
9 |
| -from copy import deepcopy |
10 |
| -from typing import Any, Optional, TYPE_CHECKING |
| 12 | +from typing import TYPE_CHECKING |
11 | 13 |
|
12 |
| -from azure.core.rest import HttpRequest, HttpResponse |
13 | 14 | from azure.mgmt.core import ARMPipelineClient
|
| 15 | +from azure.profiles import KnownProfiles, ProfileDefinition |
| 16 | +from azure.profiles.multiapiclient import MultiApiClientMixin |
14 | 17 | from msrest import Deserializer, Serializer
|
15 | 18 |
|
16 |
| -from . import models |
17 | 19 | from ._configuration import ManagedServiceIdentityClientConfiguration
|
18 |
| -from .operations import Operations, SystemAssignedIdentitiesOperations, UserAssignedIdentitiesOperations |
19 | 20 |
|
20 | 21 | if TYPE_CHECKING:
|
21 | 22 | # pylint: disable=unused-import,ungrouped-imports
|
| 23 | + from typing import Any, Optional |
| 24 | + |
22 | 25 | from azure.core.credentials import TokenCredential
|
23 | 26 |
|
24 |
| -class ManagedServiceIdentityClient: |
| 27 | +class _SDKClient(object): |
| 28 | + def __init__(self, *args, **kwargs): |
| 29 | + """This is a fake class to support current implemetation of MultiApiClientMixin." |
| 30 | + Will be removed in final version of multiapi azure-core based client |
| 31 | + """ |
| 32 | + pass |
| 33 | + |
| 34 | +class ManagedServiceIdentityClient(MultiApiClientMixin, _SDKClient): |
25 | 35 | """The Managed Service Identity Client.
|
26 | 36 |
|
27 |
| - :ivar system_assigned_identities: SystemAssignedIdentitiesOperations operations |
28 |
| - :vartype system_assigned_identities: |
29 |
| - azure.mgmt.msi.operations.SystemAssignedIdentitiesOperations |
30 |
| - :ivar operations: Operations operations |
31 |
| - :vartype operations: azure.mgmt.msi.operations.Operations |
32 |
| - :ivar user_assigned_identities: UserAssignedIdentitiesOperations operations |
33 |
| - :vartype user_assigned_identities: azure.mgmt.msi.operations.UserAssignedIdentitiesOperations |
| 37 | + This ready contains multiple API versions, to help you deal with all of the Azure clouds |
| 38 | + (Azure Stack, Azure Government, Azure China, etc.). |
| 39 | + By default, it uses the latest API version available on public Azure. |
| 40 | + For production, you should stick to a particular api-version and/or profile. |
| 41 | + The profile sets a mapping between an operation group and its API version. |
| 42 | + The api-version parameter sets the default API version if the operation |
| 43 | + group is not described in the profile. |
| 44 | +
|
34 | 45 | :param credential: Credential needed for the client to connect to Azure.
|
35 | 46 | :type credential: ~azure.core.credentials.TokenCredential
|
36 | 47 | :param subscription_id: The Id of the Subscription to which the identity belongs.
|
37 | 48 | :type subscription_id: str
|
38 |
| - :param base_url: Service URL. Default value is 'https://management.azure.com'. |
| 49 | + :param api_version: API version to use if no profile is provided, or if missing in profile. |
| 50 | + :type api_version: str |
| 51 | + :param base_url: Service URL |
39 | 52 | :type base_url: str
|
| 53 | + :param profile: A profile definition, from KnownProfiles to dict. |
| 54 | + :type profile: azure.profiles.KnownProfiles |
40 | 55 | """
|
41 | 56 |
|
| 57 | + DEFAULT_API_VERSION = '2018-11-30' |
| 58 | + _PROFILE_TAG = "azure.mgmt.msi.ManagedServiceIdentityClient" |
| 59 | + LATEST_PROFILE = ProfileDefinition({ |
| 60 | + _PROFILE_TAG: { |
| 61 | + None: DEFAULT_API_VERSION, |
| 62 | + }}, |
| 63 | + _PROFILE_TAG + " latest" |
| 64 | + ) |
| 65 | + |
42 | 66 | def __init__(
|
43 | 67 | self,
|
44 |
| - credential: "TokenCredential", |
45 |
| - subscription_id: str, |
46 |
| - base_url: str = "https://management.azure.com", |
47 |
| - **kwargs: Any |
48 |
| - ) -> None: |
49 |
| - self._config = ManagedServiceIdentityClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) |
| 68 | + credential, # type: "TokenCredential" |
| 69 | + subscription_id, # type: str |
| 70 | + api_version=None, # type: Optional[str] |
| 71 | + base_url="https://management.azure.com", # type: str |
| 72 | + profile=KnownProfiles.default, # type: KnownProfiles |
| 73 | + **kwargs # type: Any |
| 74 | + ): |
| 75 | + self._config = ManagedServiceIdentityClientConfiguration(credential, subscription_id, **kwargs) |
50 | 76 | self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
|
| 77 | + super(ManagedServiceIdentityClient, self).__init__( |
| 78 | + api_version=api_version, |
| 79 | + profile=profile |
| 80 | + ) |
51 | 81 |
|
52 |
| - client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} |
53 |
| - self._serialize = Serializer(client_models) |
54 |
| - self._deserialize = Deserializer(client_models) |
55 |
| - self._serialize.client_side_validation = False |
56 |
| - self.system_assigned_identities = SystemAssignedIdentitiesOperations(self._client, self._config, self._serialize, self._deserialize) |
57 |
| - self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) |
58 |
| - self.user_assigned_identities = UserAssignedIdentitiesOperations(self._client, self._config, self._serialize, self._deserialize) |
| 82 | + @classmethod |
| 83 | + def _models_dict(cls, api_version): |
| 84 | + return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)} |
59 | 85 |
|
| 86 | + @classmethod |
| 87 | + def models(cls, api_version=DEFAULT_API_VERSION): |
| 88 | + """Module depends on the API version: |
60 | 89 |
|
61 |
| - def _send_request( |
62 |
| - self, |
63 |
| - request, # type: HttpRequest |
64 |
| - **kwargs: Any |
65 |
| - ) -> HttpResponse: |
66 |
| - """Runs the network request through the client's chained policies. |
67 |
| -
|
68 |
| - >>> from azure.core.rest import HttpRequest |
69 |
| - >>> request = HttpRequest("GET", "https://www.example.org/") |
70 |
| - <HttpRequest [GET], url: 'https://www.example.org/'> |
71 |
| - >>> response = client._send_request(request) |
72 |
| - <HttpResponse: 200 OK> |
73 |
| -
|
74 |
| - For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart |
75 |
| -
|
76 |
| - :param request: The network request you want to make. Required. |
77 |
| - :type request: ~azure.core.rest.HttpRequest |
78 |
| - :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
79 |
| - :return: The response of your network call. Does not do error handling on your response. |
80 |
| - :rtype: ~azure.core.rest.HttpResponse |
| 90 | + * 2018-11-30: :mod:`v2018_11_30.models<azure.mgmt.msi.v2018_11_30.models>` |
| 91 | + * 2021-09-30-preview: :mod:`v2019_09_01_preview.models<azure.mgmt.msi.v2019_09_01_preview.models>` |
81 | 92 | """
|
82 |
| - |
83 |
| - request_copy = deepcopy(request) |
84 |
| - request_copy.url = self._client.format_url(request_copy.url) |
85 |
| - return self._client.send_request(request_copy, **kwargs) |
| 93 | + if api_version == '2018-11-30': |
| 94 | + from .v2018_11_30 import models |
| 95 | + return models |
| 96 | + elif api_version == '2021-09-30-preview': |
| 97 | + from .v2019_09_01_preview import models |
| 98 | + return models |
| 99 | + raise ValueError("API version {} is not available".format(api_version)) |
| 100 | + |
| 101 | + @property |
| 102 | + def operations(self): |
| 103 | + """Instance depends on the API version: |
| 104 | +
|
| 105 | + * 2018-11-30: :class:`Operations<azure.mgmt.msi.v2018_11_30.operations.Operations>` |
| 106 | + * 2021-09-30-preview: :class:`Operations<azure.mgmt.msi.v2019_09_01_preview.operations.Operations>` |
| 107 | + """ |
| 108 | + api_version = self._get_api_version('operations') |
| 109 | + if api_version == '2018-11-30': |
| 110 | + from .v2018_11_30.operations import Operations as OperationClass |
| 111 | + elif api_version == '2021-09-30-preview': |
| 112 | + from .v2019_09_01_preview.operations import Operations as OperationClass |
| 113 | + else: |
| 114 | + raise ValueError("API version {} does not have operation group 'operations'".format(api_version)) |
| 115 | + return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
| 116 | + |
| 117 | + @property |
| 118 | + def system_assigned_identities(self): |
| 119 | + """Instance depends on the API version: |
| 120 | +
|
| 121 | + * 2018-11-30: :class:`SystemAssignedIdentitiesOperations<azure.mgmt.msi.v2018_11_30.operations.SystemAssignedIdentitiesOperations>` |
| 122 | + * 2021-09-30-preview: :class:`SystemAssignedIdentitiesOperations<azure.mgmt.msi.v2019_09_01_preview.operations.SystemAssignedIdentitiesOperations>` |
| 123 | + """ |
| 124 | + api_version = self._get_api_version('system_assigned_identities') |
| 125 | + if api_version == '2018-11-30': |
| 126 | + from .v2018_11_30.operations import SystemAssignedIdentitiesOperations as OperationClass |
| 127 | + elif api_version == '2021-09-30-preview': |
| 128 | + from .v2019_09_01_preview.operations import SystemAssignedIdentitiesOperations as OperationClass |
| 129 | + else: |
| 130 | + raise ValueError("API version {} does not have operation group 'system_assigned_identities'".format(api_version)) |
| 131 | + return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
| 132 | + |
| 133 | + @property |
| 134 | + def user_assigned_identities(self): |
| 135 | + """Instance depends on the API version: |
| 136 | +
|
| 137 | + * 2018-11-30: :class:`UserAssignedIdentitiesOperations<azure.mgmt.msi.v2018_11_30.operations.UserAssignedIdentitiesOperations>` |
| 138 | + * 2021-09-30-preview: :class:`UserAssignedIdentitiesOperations<azure.mgmt.msi.v2019_09_01_preview.operations.UserAssignedIdentitiesOperations>` |
| 139 | + """ |
| 140 | + api_version = self._get_api_version('user_assigned_identities') |
| 141 | + if api_version == '2018-11-30': |
| 142 | + from .v2018_11_30.operations import UserAssignedIdentitiesOperations as OperationClass |
| 143 | + elif api_version == '2021-09-30-preview': |
| 144 | + from .v2019_09_01_preview.operations import UserAssignedIdentitiesOperations as OperationClass |
| 145 | + else: |
| 146 | + raise ValueError("API version {} does not have operation group 'user_assigned_identities'".format(api_version)) |
| 147 | + return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version))) |
86 | 148 |
|
87 | 149 | def close(self):
|
88 |
| - # type: () -> None |
89 | 150 | self._client.close()
|
90 |
| - |
91 | 151 | def __enter__(self):
|
92 |
| - # type: () -> ManagedServiceIdentityClient |
93 | 152 | self._client.__enter__()
|
94 | 153 | return self
|
95 |
| - |
96 | 154 | def __exit__(self, *exc_details):
|
97 |
| - # type: (Any) -> None |
98 | 155 | self._client.__exit__(*exc_details)
|
0 commit comments