Skip to content

Commit 890c4ce

Browse files
authored
Add AppInsights to CLI client factory (Azure#15220)
* Add AppInsights to CLI client factory * Read AppInsights cloud definition from CLI * ChangeLog
1 parent 732d319 commit 890c4ce

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

sdk/core/azure-common/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Release History
22

3-
## 1.1.26 (Unreleased)
3+
## 1.1.26 (2020-11-10)
44

5+
- get_client_from_cli_profile now supports azure-applicationinsights 0.1.0 package
56

67
## 1.1.25 (2020-03-09)
78

sdk/core/azure-common/azure/common/client_factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def _client_resource(client_class, cloud):
3838
"""
3939
if client_class.__name__ == 'GraphRbacManagementClient':
4040
return cloud.endpoints.active_directory_graph_resource_id, cloud.endpoints.active_directory_graph_resource_id
41+
if client_class.__name__ == 'ApplicationInsightsDataClient':
42+
return cloud.endpoints.app_insights_resource_id, cloud.endpoints.app_insights_resource_id+"/v1"
4143
if client_class.__name__ == 'KeyVaultClient':
4244
vault_host = cloud.suffixes.keyvault_dns[1:]
4345
vault_url = 'https://{}'.format(vault_host)

sdk/core/azure-common/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@
6363
'Programming Language :: Python :: 2',
6464
'Programming Language :: Python :: 2.7',
6565
'Programming Language :: Python :: 3',
66-
'Programming Language :: Python :: 3.4',
6766
'Programming Language :: Python :: 3.5',
6867
'Programming Language :: Python :: 3.6',
6968
'Programming Language :: Python :: 3.7',
7069
'Programming Language :: Python :: 3.8',
70+
'Programming Language :: Python :: 3.9',
7171
'License :: OSI Approved :: MIT License',
7272
],
7373
zip_safe=False,

sdk/core/azure-common/tests/test_client_factory.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from io import open
1818

1919
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
20+
# https://github.com/Azure/azure-cli/blob/4e1ff0ec626ea46d74793ad92a1b5eddc2b6e45b/src/azure-cli-core/azure/cli/core/cloud.py#L310
21+
AZURE_PUBLIC_CLOUD.endpoints.app_insights_resource_id='https://api.applicationinsights.io'
2022

2123
from azure.common.client_factory import *
2224

@@ -64,6 +66,16 @@ def __init__(self, credentials, tenant_id, base_url):
6466
self.tenant_id = tenant_id
6567
self.base_url = base_url
6668

69+
class ApplicationInsightsDataClient(object):
70+
def __init__(self, credentials, base_url):
71+
if credentials is None:
72+
raise ValueError("Parameter 'credentials' must not be None.")
73+
if not base_url:
74+
base_url = 'should not be used'
75+
76+
self.credentials = credentials
77+
self.base_url = base_url
78+
6779
class KeyVaultClient(object):
6880
def __init__(self, credentials):
6981
if credentials is None:
@@ -91,6 +103,11 @@ def __init__(self, credentials):
91103
assert client.tenant_id == 'tenant_id'
92104
assert client.base_url == "https://graph.windows.net/"
93105

106+
client = get_client_from_cli_profile(ApplicationInsightsDataClient)
107+
get_azure_cli_credentials.assert_called_with(resource="https://api.applicationinsights.io", with_tenant=True)
108+
assert client.credentials == 'credentials'
109+
assert client.base_url == "https://api.applicationinsights.io/v1"
110+
94111
client = get_client_from_cli_profile(KeyVaultClient)
95112
get_azure_cli_credentials.assert_called_with(resource="https://vault.azure.net", with_tenant=True)
96113
assert client.credentials == 'credentials'

0 commit comments

Comments
 (0)