Skip to content

Commit e193150

Browse files
committed
adjust
1 parent 15dbe5f commit e193150

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/application-insights/azext_applicationinsights/_client_factory.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6+
class _Track1Credential:
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
11-
from .util import Track1Credential
1230
profile = Profile(cli_ctx=cli_ctx)
1331
# Note: temporarily adapt track2 auth to track1 by the guidance:
1432
# https://github.com/Azure/azure-cli/pull/29631#issuecomment-2716799520
1533
# need to be removed after migrated by codegen
16-
# cred, _, _ = profile.get_login_credentials(
17-
# resource=cli_ctx.cloud.endpoints.app_insights_resource_id,
18-
# subscription_id=subscription
19-
# )
20-
# return ApplicationInsightsDataClient(
21-
# cred,
22-
# base_url=f'{cli_ctx.cloud.endpoints.app_insights_resource_id}/v1'
23-
# )
24-
2534
cred, _, _ = profile.get_login_credentials(subscription_id=subscription)
2635
return ApplicationInsightsDataClient(
27-
Track1Credential(cred, cli_ctx.cloud.endpoints.app_insights_resource_id),
36+
_Track1Credential(cred, cli_ctx.cloud.endpoints.app_insights_resource_id),
2837
base_url=f'{cli_ctx.cloud.endpoints.app_insights_resource_id}/v1'
2938
)
3039

0 commit comments

Comments
 (0)