77# --------------------------------------------------------------------------
88
99from 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
1112
13+ from azure .core .pipeline import policies
1214from azure .core .rest import HttpRequest , HttpResponse
15+ from azure .core .settings import settings
1316from azure .mgmt .core import ARMPipelineClient
17+ from azure .mgmt .core .policies import ARMAutoResourceProviderRegistrationPolicy
18+ from azure .mgmt .core .tools import get_arm_endpoints
1419
1520from . import models as _models
1621from ._configuration import AstroMgmtClientConfiguration
17- from ._serialization import Deserializer , Serializer
22+ from ._utils . serialization import Deserializer , Serializer
1823from .operations import Operations , OrganizationsOperations
1924
2025if TYPE_CHECKING :
21- # pylint: disable=unused-import,ungrouped-imports
2226 from azure .core .credentials import TokenCredential
2327
2428
25- class AstroMgmtClient : # pylint: disable=client-accepts-api-version-keyword
29+ class AstroMgmtClient :
2630 """AstroMgmtClient.
2731
2832 :ivar operations: Operations operations
@@ -33,24 +37,46 @@ class AstroMgmtClient: # pylint: disable=client-accepts-api-version-keyword
3337 :type credential: ~azure.core.credentials.TokenCredential
3438 :param subscription_id: The ID of the target subscription. Required.
3539 :type subscription_id: str
36- :param base_url: Service URL. Default value is "https://management.azure.com" .
40+ :param base_url: Service URL. Default value is None .
3741 :type base_url: str
38- :keyword api_version: Api Version. Default value is "2023 -08-01 ". Note that overriding this
42+ :keyword api_version: Api Version. Default value is "2024 -08-27 ". Note that overriding this
3943 default value may result in unsupported behavior.
4044 :paramtype api_version: str
4145 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no
4246 Retry-After header is present.
4347 """
4448
4549 def __init__ (
46- self ,
47- credential : "TokenCredential" ,
48- subscription_id : str ,
49- base_url : str = "https://management.azure.com" ,
50- ** kwargs : Any
50+ self , credential : "TokenCredential" , subscription_id : str , base_url : Optional [str ] = None , ** kwargs : Any
5151 ) -> None :
52- self ._config = AstroMgmtClientConfiguration (credential = credential , subscription_id = subscription_id , ** kwargs )
53- self ._client : ARMPipelineClient = ARMPipelineClient (base_url = base_url , config = self ._config , ** kwargs )
52+ _cloud = kwargs .pop ("cloud_setting" , None ) or settings .current .azure_cloud # type: ignore
53+ _endpoints = get_arm_endpoints (_cloud )
54+ if not base_url :
55+ base_url = _endpoints ["resource_manager" ]
56+ credential_scopes = kwargs .pop ("credential_scopes" , _endpoints ["credential_scopes" ])
57+ self ._config = AstroMgmtClientConfiguration (
58+ credential = credential , subscription_id = subscription_id , credential_scopes = credential_scopes , ** kwargs
59+ )
60+
61+ _policies = kwargs .pop ("policies" , None )
62+ if _policies is None :
63+ _policies = [
64+ policies .RequestIdPolicy (** kwargs ),
65+ self ._config .headers_policy ,
66+ self ._config .user_agent_policy ,
67+ self ._config .proxy_policy ,
68+ policies .ContentDecodePolicy (** kwargs ),
69+ ARMAutoResourceProviderRegistrationPolicy (),
70+ self ._config .redirect_policy ,
71+ self ._config .retry_policy ,
72+ self ._config .authentication_policy ,
73+ self ._config .custom_hook_policy ,
74+ self ._config .logging_policy ,
75+ policies .DistributedTracingPolicy (** kwargs ),
76+ policies .SensitiveHeaderCleanupPolicy (** kwargs ) if self ._config .redirect_policy else None ,
77+ self ._config .http_logging_policy ,
78+ ]
79+ self ._client : ARMPipelineClient = ARMPipelineClient (base_url = cast (str , base_url ), policies = _policies , ** kwargs )
5480
5581 client_models = {k : v for k , v in _models .__dict__ .items () if isinstance (v , type )}
5682 self ._serialize = Serializer (client_models )
@@ -59,7 +85,7 @@ def __init__(
5985 self .operations = Operations (self ._client , self ._config , self ._serialize , self ._deserialize )
6086 self .organizations = OrganizationsOperations (self ._client , self ._config , self ._serialize , self ._deserialize )
6187
62- def _send_request (self , request : HttpRequest , ** kwargs : Any ) -> HttpResponse :
88+ def _send_request (self , request : HttpRequest , * , stream : bool = False , * *kwargs : Any ) -> HttpResponse :
6389 """Runs the network request through the client's chained policies.
6490
6591 >>> from azure.core.rest import HttpRequest
@@ -79,12 +105,12 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
79105
80106 request_copy = deepcopy (request )
81107 request_copy .url = self ._client .format_url (request_copy .url )
82- return self ._client .send_request (request_copy , ** kwargs )
108+ return self ._client .send_request (request_copy , stream = stream , ** kwargs ) # type: ignore
83109
84110 def close (self ) -> None :
85111 self ._client .close ()
86112
87- def __enter__ (self ) -> "AstroMgmtClient" :
113+ def __enter__ (self ) -> Self :
88114 self ._client .__enter__ ()
89115 return self
90116
0 commit comments