7
7
# --------------------------------------------------------------------------
8
8
9
9
from copy import deepcopy
10
- from typing import Any , TYPE_CHECKING
10
+ from typing import Any , Optional , TYPE_CHECKING , cast
11
+ from typing_extensions import Self
11
12
12
13
from azure .core .pipeline import policies
13
14
from azure .core .rest import HttpRequest , HttpResponse
15
+ from azure .core .settings import settings
14
16
from azure .mgmt .core import ARMPipelineClient
15
17
from azure .mgmt .core .policies import ARMAutoResourceProviderRegistrationPolicy
18
+ from azure .mgmt .core .tools import get_arm_endpoints
16
19
17
20
from . import models as _models
18
21
from ._configuration import AzureSphereMgmtClientConfiguration
29
32
)
30
33
31
34
if TYPE_CHECKING :
32
- # pylint: disable=unused-import,ungrouped-imports
33
35
from azure .core .credentials import TokenCredential
34
36
35
37
36
- class AzureSphereMgmtClient : # pylint: disable=client-accepts-api-version-keyword, too-many-instance-attributes
38
+ class AzureSphereMgmtClient : # pylint: disable=too-many-instance-attributes
37
39
"""Azure Sphere resource management API.
38
40
39
41
:ivar operations: Operations operations
@@ -56,7 +58,7 @@ class AzureSphereMgmtClient: # pylint: disable=client-accepts-api-version-keywo
56
58
:type credential: ~azure.core.credentials.TokenCredential
57
59
:param subscription_id: The ID of the target subscription. Required.
58
60
:type subscription_id: str
59
- :param base_url: Service URL. Default value is "https://management.azure.com" .
61
+ :param base_url: Service URL. Default value is None .
60
62
:type base_url: str
61
63
:keyword api_version: Api Version. Default value is "2024-04-01". Note that overriding this
62
64
default value may result in unsupported behavior.
@@ -66,15 +68,17 @@ class AzureSphereMgmtClient: # pylint: disable=client-accepts-api-version-keywo
66
68
"""
67
69
68
70
def __init__ (
69
- self ,
70
- credential : "TokenCredential" ,
71
- subscription_id : str ,
72
- base_url : str = "https://management.azure.com" ,
73
- ** kwargs : Any
71
+ self , credential : "TokenCredential" , subscription_id : str , base_url : Optional [str ] = None , ** kwargs : Any
74
72
) -> None :
73
+ _cloud = kwargs .pop ("cloud_setting" , None ) or settings .current .azure_cloud # type: ignore
74
+ _endpoints = get_arm_endpoints (_cloud )
75
+ if not base_url :
76
+ base_url = _endpoints ["resource_manager" ]
77
+ credential_scopes = kwargs .pop ("credential_scopes" , _endpoints ["credential_scopes" ])
75
78
self ._config = AzureSphereMgmtClientConfiguration (
76
- credential = credential , subscription_id = subscription_id , ** kwargs
79
+ credential = credential , subscription_id = subscription_id , credential_scopes = credential_scopes , ** kwargs
77
80
)
81
+
78
82
_policies = kwargs .pop ("policies" , None )
79
83
if _policies is None :
80
84
_policies = [
@@ -93,7 +97,7 @@ def __init__(
93
97
policies .SensitiveHeaderCleanupPolicy (** kwargs ) if self ._config .redirect_policy else None ,
94
98
self ._config .http_logging_policy ,
95
99
]
96
- self ._client : ARMPipelineClient = ARMPipelineClient (base_url = base_url , policies = _policies , ** kwargs )
100
+ self ._client : ARMPipelineClient = ARMPipelineClient (base_url = cast ( str , base_url ) , policies = _policies , ** kwargs )
97
101
98
102
client_models = {k : v for k , v in _models .__dict__ .items () if isinstance (v , type )}
99
103
self ._serialize = Serializer (client_models )
@@ -133,7 +137,7 @@ def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
133
137
def close (self ) -> None :
134
138
self ._client .close ()
135
139
136
- def __enter__ (self ) -> "AzureSphereMgmtClient" :
140
+ def __enter__ (self ) -> Self :
137
141
self ._client .__enter__ ()
138
142
return self
139
143
0 commit comments