Skip to content

Commit e1d64ea

Browse files
AllyWjiasli
andauthored
{Application-insights} Add auth adaptor for track 1 sdk (#8551)
* add auth adaptor for track 1 sdk * Update src/application-insights/HISTORY.rst Co-authored-by: Jiashuo Li <4003950+jiasli@users.noreply.github.com>
1 parent fe0909b commit e1d64ea

8 files changed

+1517
-2216
lines changed

src/application-insights/HISTORY.rst

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
33
Release History
44
===============
5+
1.2.3
6+
++++++++++++++++++
7+
* `az monitor app-insights events/metrics/query`: Fix error: Profile.get_login_credentials() got an unexpected keyword argument 'resource'
58

69
1.2.2
710
++++++++++++++++++

src/application-insights/azext_applicationinsights/_client_factory.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,37 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6+
class _Track1Credential: # pylint: disable=too-few-public-methods
7+
8+
def __init__(self, credential, resource):
9+
"""Track 1 credential that can be fed into Track 1 SDK clients. Exposes signed_session protocol.
10+
:param credential: Track 2 credential that exposes get_token protocol
11+
:param resource: AAD resource
12+
"""
13+
self._credential = credential
14+
self._resource = resource
15+
16+
def signed_session(self, session=None):
17+
import requests
18+
from azure.cli.core.auth.util import resource_to_scopes
19+
session = session or requests.Session()
20+
token = self._credential.get_token(*resource_to_scopes(self._resource))
21+
header = "{} {}".format('Bearer', token.token)
22+
session.headers['Authorization'] = header
23+
return session
24+
625

726
def applicationinsights_data_plane_client(cli_ctx, _, subscription=None):
827
"""Initialize Log Analytics data client for use with CLI."""
928
from .vendored_sdks.applicationinsights import ApplicationInsightsDataClient
1029
from azure.cli.core._profile import Profile
1130
profile = Profile(cli_ctx=cli_ctx)
12-
cred, _, _ = profile.get_login_credentials(
13-
resource=cli_ctx.cloud.endpoints.app_insights_resource_id,
14-
subscription_id=subscription
15-
)
31+
# Note: temporarily adapt track2 auth to track1 by the guidance:
32+
# https://github.com/Azure/azure-cli/pull/29631#issuecomment-2716799520
33+
# need to be removed after migrated by codegen
34+
cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
1635
return ApplicationInsightsDataClient(
17-
cred,
36+
_Track1Credential(cred, cli_ctx.cloud.endpoints.app_insights_resource_id),
1837
base_url=f'{cli_ctx.cloud.endpoints.app_insights_resource_id}/v1'
1938
)
2039

src/application-insights/azext_applicationinsights/tests/latest/recordings/test_connect_function.yaml

+518-927
Large diffs are not rendered by default.

src/application-insights/azext_applicationinsights/tests/latest/recordings/test_connect_function_cross_resource_groups.yaml

+514-925
Large diffs are not rendered by default.

src/application-insights/azext_applicationinsights/tests/latest/recordings/test_connect_webapp.yaml

+230-179
Large diffs are not rendered by default.

src/application-insights/azext_applicationinsights/tests/latest/recordings/test_connect_webapp_cross_resource_group.yaml

+225-179
Large diffs are not rendered by default.

src/application-insights/azext_applicationinsights/tests/latest/test_applicationinsights_mgmt.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55

66
# pylint: disable=line-too-long
7+
import unittest
78
from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest, StorageAccountPreparer
89
from .recording_processors import StorageAccountSASReplacer
910
from azure.cli.testsdk.scenario_tests import AllowLargeResponse
@@ -349,6 +350,7 @@ def test_component_with_linked_storage(self, resource_group, location, storage_a
349350
with self.assertRaisesRegex(ResourceNotFoundError, "Operation returned an invalid status 'Not Found'"):
350351
self.cmd('monitor app-insights component linked-storage show --app {name_a} -g {resource_group}')
351352

353+
@unittest.skip("The operation 'action' on resource type 'components' is disallowed for cmd 'monitor app-insights component continues-export create'.")
352354
@AllowLargeResponse()
353355
@ResourceGroupPreparer(parameter_name_for_location='location')
354356
@StorageAccountPreparer(kind='StorageV2')

src/application-insights/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from codecs import open
99
from setuptools import setup, find_packages
1010

11-
VERSION = "1.2.2"
11+
VERSION = "1.2.3"
1212

1313
CLASSIFIERS = [
1414
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)