Skip to content

Commit 7bb478d

Browse files
{Monitor} Add cloud endpoint and credential scope mappings (#10400)
1 parent 7fb97e9 commit 7bb478d

5 files changed

Lines changed: 218 additions & 28 deletions

File tree

‎src/log-analytics/HISTORY.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
1.0.0b3
2+
++++++++++++++++++
3+
* Add explicit host fallbacks for Azure Government and Azure China.
4+
* Use cloud-specific credential scopes to avoid requesting public Azure tokens in clouds.
5+
* Add regression tests - test_cloud_host_template_fallbacks, test_cloud_specific_credential_scopes
6+
7+
18
1.0.0b2
29
++++++++++++++++++
310
* Fix CloudEndpointNotSetException error.

‎src/log-analytics/azext_loganalytics/aaz/latest/_clients.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
@register_client("AAZMicrosoftOperationalinsightsDataPlaneClient_log_analytics")
1515
class AAZMicrosoftOperationalinsightsDataPlaneClient(AAZBaseClient):
1616
_CLOUD_HOST_TEMPLATES = {
17+
CloudNameEnum.AzureChinaCloud: "https://api.loganalytics.azure.cn",
1718
CloudNameEnum.AzureCloud: "https://api.loganalytics.io",
19+
CloudNameEnum.AzureUSGovernment: "https://api.loganalytics.us",
1820
}
1921
_CLOUD_HOST_METADATA_INDEX = "logAnalyticsResourceId"
2022

21-
_AAD_CREDENTIAL_SCOPES = [
22-
"https://api.loganalytics.io/.default",
23-
]
23+
_AAD_CREDENTIAL_SCOPES = {
24+
CloudNameEnum.AzureChinaCloud: ["https://api.loganalytics.azure.cn/.default"],
25+
CloudNameEnum.AzureCloud: ["https://api.loganalytics.io/.default"],
26+
CloudNameEnum.AzureUSGovernment: ["https://api.loganalytics.us/.default"],
27+
}
2428

2529
@classmethod
2630
def _build_base_url(cls, ctx, **kwargs):
@@ -31,9 +35,13 @@ def _build_base_url(cls, ctx, **kwargs):
3135

3236
@classmethod
3337
def _build_configuration(cls, ctx, credential, **kwargs):
38+
credential_scopes = cls._AAD_CREDENTIAL_SCOPES.get(ctx.cli_ctx.cloud.name)
39+
if not credential_scopes:
40+
endpoint = cls._build_base_url(ctx, **kwargs)
41+
credential_scopes = [f"{endpoint.rstrip('/')}/.default"]
3442
return AAZClientConfiguration(
3543
credential=credential,
36-
credential_scopes=cls._AAD_CREDENTIAL_SCOPES,
44+
credential_scopes=credential_scopes,
3745
**kwargs
3846
)
3947

0 commit comments

Comments
 (0)