@@ -54,28 +54,28 @@ class CloudSettings:
54
54
first_party_authority_url = DEFAULT_FIRST_PARTY_AUTHORITY_URL ,
55
55
)
56
56
57
- @classmethod
58
- @distributed_trace (name_of_span = "CloudSettings.get_cloud_info" , kind = SpanKind .CLIENT )
59
- def get_cloud_info_for_cluster (cls , kusto_uri : str , proxies : Optional [Dict [str , str ]] = None ) -> CloudInfo :
60
- normalized_authority = cls ._normalize_uri (kusto_uri )
61
-
62
- # tracing attributes for cloud info
63
- Span .set_cloud_info_attributes (kusto_uri )
64
-
65
- if normalized_authority in cls ._cloud_cache : # Double-checked locking to avoid unnecessary lock access
66
- return cls ._cloud_cache [normalized_authority ]
67
-
68
- with cls ._cloud_cache_lock :
69
- if normalized_authority in cls ._cloud_cache :
70
- return cls ._cloud_cache [normalized_authority ]
71
-
72
- url_parts = urlparse (kusto_uri )
57
+ @classmethod
58
+ @distributed_trace (name_of_span = "CloudSettings.get_cloud_info" , kind = SpanKind .CLIENT )
59
+ def get_cloud_info_for_cluster (cls , kusto_uri : str , proxies : Optional [Dict [str , str ]] = None , session : requests . Session = None ) -> CloudInfo :
60
+ normalized_authority = cls ._normalize_uri (kusto_uri )
61
+
62
+ # tracing attributes for cloud info
63
+ Span .set_cloud_info_attributes (kusto_uri )
64
+
65
+ if normalized_authority in cls ._cloud_cache : # Double-checked locking to avoid unnecessary lock access
66
+ return cls ._cloud_cache [normalized_authority ]
67
+
68
+ with cls ._cloud_cache_lock :
69
+ if normalized_authority in cls ._cloud_cache :
70
+ return cls ._cloud_cache [normalized_authority ]
71
+
72
+ url_parts = urlparse (kusto_uri )
73
73
url = f"{ url_parts .scheme } ://{ url_parts .netloc } /{ METADATA_ENDPOINT } "
74
74
75
75
try :
76
76
# trace http get call for result
77
77
result = MonitoredActivity .invoke (
78
- lambda : requests .get (url , proxies = proxies , allow_redirects = False ),
78
+ lambda : ( session or requests ) .get (url , proxies = proxies , allow_redirects = False ),
79
79
name_of_span = "CloudSettings.http_get" ,
80
80
tracing_attributes = Span .create_http_attributes (url = url , method = "GET" ),
81
81
)
@@ -87,32 +87,32 @@ def get_cloud_info_for_cluster(cls, kusto_uri: str, proxies: Optional[Dict[str,
87
87
if content is None or content == {}:
88
88
raise KustoServiceError ("Kusto returned an invalid cloud metadata response" , result )
89
89
root = content ["AzureAD" ]
90
- if root is not None :
91
- cls ._cloud_cache [normalized_authority ] = CloudInfo (
92
- login_endpoint = root ["LoginEndpoint" ],
93
- login_mfa_required = root ["LoginMfaRequired" ],
94
- kusto_client_app_id = root ["KustoClientAppId" ],
95
- kusto_client_redirect_uri = root ["KustoClientRedirectUri" ],
96
- kusto_service_resource_id = root ["KustoServiceResourceId" ],
97
- first_party_authority_url = root ["FirstPartyAuthorityUrl" ],
98
- )
99
- else :
100
- cls ._cloud_cache [normalized_authority ] = cls .DEFAULT_CLOUD
101
- elif result .status_code == 404 :
102
- # For now as long not all proxies implement the metadata endpoint, if no endpoint exists return public cloud data
103
- cls ._cloud_cache [normalized_authority ] = cls .DEFAULT_CLOUD
104
- else :
105
- raise KustoServiceError ("Kusto returned an invalid cloud metadata response" , result )
90
+ if root is not None :
91
+ cls ._cloud_cache [normalized_authority ] = CloudInfo (
92
+ login_endpoint = root ["LoginEndpoint" ],
93
+ login_mfa_required = root ["LoginMfaRequired" ],
94
+ kusto_client_app_id = root ["KustoClientAppId" ],
95
+ kusto_client_redirect_uri = root ["KustoClientRedirectUri" ],
96
+ kusto_service_resource_id = root ["KustoServiceResourceId" ],
97
+ first_party_authority_url = root ["FirstPartyAuthorityUrl" ],
98
+ )
99
+ else :
100
+ cls ._cloud_cache [normalized_authority ] = cls .DEFAULT_CLOUD
101
+ elif result .status_code == 404 :
102
+ # For now as long not all proxies implement the metadata endpoint, if no endpoint exists return public cloud data
103
+ cls ._cloud_cache [normalized_authority ] = cls .DEFAULT_CLOUD
104
+ else :
105
+ raise KustoServiceError ("Kusto returned an invalid cloud metadata response" , result )
106
106
return cls ._cloud_cache [normalized_authority ]
107
107
108
108
@classmethod
109
109
def add_to_cache (cls , url : str , cloud_info : CloudInfo ):
110
110
with cls ._cloud_cache_lock :
111
111
cls ._cloud_cache [cls ._normalize_uri (url )] = cloud_info
112
112
113
- @classmethod
114
- def _normalize_uri (cls , kusto_uri ):
115
- """Extracts and returns the authority part of the URI (schema, host, port)"""
116
- url_parts = urlparse (kusto_uri )
117
- # Return only the scheme and netloc (which contains host and port if present)
113
+ @classmethod
114
+ def _normalize_uri (cls , kusto_uri ):
115
+ """Extracts and returns the authority part of the URI (schema, host, port)"""
116
+ url_parts = urlparse (kusto_uri )
117
+ # Return only the scheme and netloc (which contains host and port if present)
118
118
return f"{ url_parts .scheme } ://{ url_parts .netloc } "
0 commit comments