Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom token support #5272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
68800b6
Added spn and resource group creation in connectedk8s create
Nov 12, 2019
5090698
Vanilla CLI Code for Connected Cluster
Nov 22, 2019
fda117d
saved location data CLI changes after 0.1.2
Mar 11, 2020
e781176
Added the 0.1.2 version CLI code in master
Mar 11, 2020
969a45f
Removed a print statement
Mar 11, 2020
d60bd23
Fixed container status check
Mar 12, 2020
45e2db7
Updated pod status check
Mar 13, 2020
678c2b7
Merge pull request #1 from akashkeshari/akash/agent_monitor_fix
akashkeshari Mar 16, 2020
85aa7d9
Added 2020 version models and operations
Mar 24, 2020
d345685
Updated with key pair generation
Mar 29, 2020
4e90290
review of public private key pair
Apr 1, 2020
836e6fc
updated models with latest changes in swagger
Apr 4, 2020
a1bea49
Update CLI to support SPN less onboarding
Apr 7, 2020
6522421
Removed location data changes
Apr 13, 2020
dec8fab
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
9bd5580
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
854b36f
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
576704d
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
b26a0eb
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
6d445c3
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
9df8269
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
031639b
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
47ca292
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
b237d9c
Update src/connectedk8s/azext_connectedk8s/custom.py
akashkeshari Apr 21, 2020
6249ea7
Updated error messages
Apr 21, 2020
5223949
resolved a conflict
Apr 21, 2020
c1ecbf8
updated wrt style checks
Apr 21, 2020
f43ebfb
Added a recorded test
Apr 21, 2020
d237667
Updated forked master with original master
Apr 21, 2020
32c5089
Updated with latest master changes
Apr 21, 2020
a97f36e
Updated imports
Apr 21, 2020
025522c
removed python 2.x from setup.py
Apr 21, 2020
1967b02
Updated format.py
Apr 21, 2020
df87f51
Updated readme file
Apr 22, 2020
b747e92
Updated test file
Apr 22, 2020
9d9c954
updated setup.py
Apr 22, 2020
2db8c30
updated knack version in setup.py
Apr 22, 2020
bd26f72
updated knack version to 0.7.0rc4 in setup.py
Apr 22, 2020
9dbfa0b
Updated test file to pass kubeconfig
Apr 23, 2020
c45a3a6
Updated test file to pass kubeconfig
Apr 23, 2020
f27610a
Added async support for delete
Apr 24, 2020
9852a51
Added helm charts to test data folder
Apr 27, 2020
ddad5b7
Updated helm chart pull method
Apr 27, 2020
6e6cd75
corrected import order
Apr 27, 2020
eb723fb
Ran connectedk8s test
Apr 27, 2020
a5407c1
Updated some print statements
Apr 27, 2020
3b8f930
ran test with helm upgrade --install
Apr 27, 2020
9f72a47
Updated print to warning
Apr 27, 2020
5515568
Updated error message
Apr 27, 2020
fac6740
Updated exceptions to be generic
Apr 28, 2020
e0f5022
Added aks creation in tests
Apr 29, 2020
c9d1071
updated warning statements
Apr 29, 2020
3b78ee8
updated test to create aks cluster with ssh keys
Apr 29, 2020
96a2cbe
added spn calls in recorded tests
Apr 29, 2020
2c7b8b3
Updated api-version in recorded tests
Apr 29, 2020
b9fdd1e
removed mc delete as CI test needs it to be persistant
Apr 29, 2020
cfb21ab
switched to livescenariotest
Apr 29, 2020
005e414
updated params.py
Apr 30, 2020
ba268a1
corrected databricks change
Apr 30, 2020
0ff1943
updated pod monitoring
Apr 30, 2020
d77e433
updated identation
Apr 30, 2020
44f4547
updated print statement to warnings
Apr 30, 2020
3fa9b10
added telemetry code for connect cli
May 6, 2020
5c56299
Added exception telemetry for delete operation
May 12, 2020
4ddea41
Updated fork master with latest master
May 12, 2020
47fc01b
Updated with latest master
May 12, 2020
9239f83
Updated setup.py
May 12, 2020
ccdbff0
Changed default kubernetes distro
May 12, 2020
e6333d7
Distro detect.
pasankav May 12, 2020
1ef6cdd
Updated history
May 13, 2020
c1612c2
removed arm resourceid from telemetry
May 13, 2020
3ed99da
Merge branch 'akash/connect_telemetry' into pavan/distro_detect
pasankav May 14, 2020
8b26810
Add kubernetes distro and identifying it.
pasankav May 14, 2020
fdacc2b
Remove additional line.
pasankav May 15, 2020
3860c00
correct indentation.
pasankav May 15, 2020
b9b4915
Merge branch 'master' into pavan/distro_detect
pasankav May 15, 2020
f8c4e04
correct indentation.
pasankav May 15, 2020
b752e92
correct version number.
pasankav May 15, 2020
9404057
Merge pull request #5 from akashkeshari/pavan/distro_detect
akashkeshari May 18, 2020
669071f
Merge pull request #4 from akashkeshari/akash/connect_telemetry
akashkeshari May 18, 2020
65e69b8
Merge pull request #2 from akashkeshari/location_data
akashkeshari May 18, 2020
13b8795
Merge remote-tracking branch 'upstream/master'
Aug 13, 2020
da4a59b
merged with latest master
Aug 13, 2020
fcbda96
resolved merge conflict with upstream
Sep 6, 2020
6636a4f
Merge remote-tracking branch 'upstream/master' into master
Oct 16, 2020
a1ba684
Merge remote-tracking branch 'upstream/master' into master
Oct 28, 2020
6ea4e8a
Merge remote-tracking branch 'upstream/master' into master
Dec 2, 2020
3dec24b
Merge remote-tracking branch 'upstream/master' into master
Dec 21, 2020
025e0be
Merge remote-tracking branch 'upstream/master' into master
Jan 22, 2021
4375ef9
Merge remote-tracking branch 'upstream/master' into master
Feb 8, 2021
53aeb0e
Merge remote-tracking branch 'upstream/master' into master
Feb 19, 2021
c6490ec
Merge remote-tracking branch 'upstream/master' into master
May 27, 2021
1751193
updated the preview models
Jun 1, 2021
d6209cc
updated PUT operation for private link
Jun 1, 2021
c86190d
added track2 SDK
Jun 12, 2021
d659941
added pvt link properties in update command
Jun 13, 2021
b564979
removed aio folder
Jul 11, 2021
64ecdc1
disable cluster-connect when private link is getting enabled
Jul 25, 2021
b7ce14c
Merge remote-tracking branch 'upstream/main' into master
Jul 27, 2021
4195205
Merge remote-tracking branch 'upstream/main' into master
Jul 29, 2021
348aebc
Merge remote-tracking branch 'upstream/main' into master
Sep 6, 2021
c4b2f86
Merge remote-tracking branch 'upstream/main' into master
Sep 7, 2021
9f39b33
Merge remote-tracking branch 'upstream/main' into master
Sep 16, 2021
c7f4213
Merge remote-tracking branch 'upstream/main' into master
Oct 14, 2021
32e4d66
Merge remote-tracking branch 'upstream/main' into master
Dec 16, 2021
5817336
Merge remote-tracking branch 'upstream/main' into master
Dec 28, 2021
3e125ac
Merge remote-tracking branch 'upstream/main' into master
Jan 15, 2022
22cfe49
resolved merge conflicts
Jan 15, 2022
1bbcb18
few updates
Jan 17, 2022
1222b6d
fixed async operations
Jan 17, 2022
694be91
fixed async operation delete
Jan 18, 2022
b387dc1
Merge remote-tracking branch 'upstream/main' into master
Jan 30, 2022
b93a287
updated history file
Jan 30, 2022
715b357
updated setup.py
Jan 30, 2022
c1aec0c
fixed merge conflicts
Apr 13, 2022
0bc1174
Merge remote-tracking branch 'upstream/main' into akash/connectedk8s_…
Apr 13, 2022
abf7bd7
added shorter param name for pls arm id
Apr 13, 2022
53b0411
added a check in enable features
Apr 16, 2022
bfe92fd
few updates
Apr 19, 2022
775876b
fixed a help statement
Apr 19, 2022
d90c4f3
fixed patch behavior for existing pvt link enabled cc
Apr 21, 2022
c1ee570
updated prompt message
Apr 26, 2022
91396c2
added pvt link test and re-recorded the tests
Apr 28, 2022
87d636d
delete temporary kube config file
akashkeshari Apr 28, 2022
add4409
re-recorded the tests
Apr 28, 2022
466a095
Merge remote-tracking branch 'upstream/main' into akash/connectedk8s_…
Apr 29, 2022
ce7be95
updated --enable-private-link parameter to three state flag
May 5, 2022
e13415c
re-recorded the tests
May 5, 2022
3e95a8c
removed unused import
May 6, 2022
3fa3637
update if condition
May 6, 2022
3ce1c21
updated the SDK to new preview
Jun 7, 2022
05bd983
added preview client for patch of pvt link enabled resource
Jun 7, 2022
5d17db0
re-recorded tests
Jun 7, 2022
596c551
fix based on comment
Jun 8, 2022
ebb3b3a
merged with latest master
Jul 25, 2022
80f8636
added pls location check
Jul 27, 2022
3d15600
added custom token support
Aug 3, 2022
5fd2c31
added container log path parameter
Aug 9, 2022
95b8555
added the container log path in params.py
Aug 9, 2022
b92dcaa
updated with latest main branch
Aug 24, 2022
e1a0c2c
removed comments
Aug 24, 2022
38a9181
fixed extra line
Aug 24, 2022
f76615d
fix new line
Aug 24, 2022
2ac2fef
updates setup.py
Aug 24, 2022
7e703fb
added container log path parameter in update
Aug 25, 2022
e1f6e8f
merged with latest master
Sep 2, 2022
14051cc
few updates
Sep 4, 2022
0e1bd9b
commited untracked changes
Sep 20, 2022
5bc42b8
Merge remote-tracking branch 'upstream/main' into akash/connectedk8s_…
Sep 20, 2022
7642f31
updated setup & history file
Sep 20, 2022
9b5c2a9
updated no param condition
Sep 21, 2022
b768de1
merge with latest main
Oct 6, 2022
1f47279
resolving merge conflicts with main
Nov 21, 2022
a4cdf9e
updated client factory to use get_mgmt_service_client for custom cred…
Nov 23, 2022
13ee8d3
resolve merge conflict with latest main
Jan 22, 2023
d577184
added check for pls resource not found
Jan 23, 2023
21c4fa9
resolve merge conflict
Jan 30, 2023
e9a1620
merged with latest master
Feb 2, 2023
fb12ae8
updated history
Feb 3, 2023
ef70daf
Merge remote-tracking branch 'upstream/main' into akash/connectedk8s_…
Feb 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/connectedk8s/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Release History
===============
1.3.11
++++++

* Added support for custom AAD token
* Removed ARM64 unsupported warning
* Increased helm delete timeout for ARM64 clusters
* Added multi-architectural images for troubleshoot* Delete azure-arc-release NS if exists as part of delete command

1.3.10
++++++

Expand Down
74 changes: 64 additions & 10 deletions src/connectedk8s/azext_connectedk8s/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
from azure.cli.core._profile import Profile
from azure.cli.core import telemetry
from azure.cli.core.azclierror import ValidationError
from azure.cli.core.commands.client_factory import configure_common_settings
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.graphrbac import GraphRbacManagementClient

import os
import requests
import azext_connectedk8s._constants as consts
from collections import namedtuple

AccessToken = namedtuple("AccessToken", ["token", "expires_on"])


def cf_connectedk8s(cli_ctx, *_):
from azext_connectedk8s.vendored_sdks import ConnectedKubernetesClient
if os.getenv('AZURE_ACCESS_TOKEN'):
akashkeshari marked this conversation as resolved.
Show resolved Hide resolved
validate_custom_token()
credential = AccessTokenCredential(access_token=os.getenv('AZURE_ACCESS_TOKEN'))
return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient, subscription_id=os.getenv('AZURE_SUBSCRIPTION_ID'), credential=credential)
return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient)


Expand All @@ -21,6 +35,10 @@ def cf_connected_cluster(cli_ctx, _):

def cf_connectedk8s_prev_2022_10_01(cli_ctx, *_):
from azext_connectedk8s.vendored_sdks.preview_2022_10_01 import ConnectedKubernetesClient
if os.getenv('AZURE_ACCESS_TOKEN'):
validate_custom_token()
credential = AccessTokenCredential(access_token=os.getenv('AZURE_ACCESS_TOKEN'))
return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient, subscription_id=os.getenv('AZURE_SUBSCRIPTION_ID'), credential=credential)
return get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient)


Expand All @@ -30,36 +48,72 @@ def cf_connected_cluster_prev_2022_10_01(cli_ctx, _):

def cf_connectedmachine(cli_ctx, subscription_id):
from azure.mgmt.hybridcompute import HybridComputeManagementClient
if os.getenv('AZURE_ACCESS_TOKEN'):
credential = AccessTokenCredential(access_token=os.getenv('AZURE_ACCESS_TOKEN'))
return get_mgmt_service_client(cli_ctx, HybridComputeManagementClient, subscription_id=subscription_id, credential=credential).private_link_scopes
return get_mgmt_service_client(cli_ctx, HybridComputeManagementClient, subscription_id=subscription_id).private_link_scopes


def cf_resource_groups(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id).resource_groups
return _resource_client_factory(cli_ctx, subscription_id).resource_groups


def _resource_client_factory(cli_ctx, subscription_id=None):
from azure.mgmt.resource import ResourceManagementClient
if os.getenv('AZURE_ACCESS_TOKEN'):
credential = AccessTokenCredential(access_token=os.getenv('AZURE_ACCESS_TOKEN'))
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id, credential=credential)
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id)


def _resource_providers_client(cli_ctx):
from azure.mgmt.resource import ResourceManagementClient
return get_mgmt_service_client(cli_ctx, ResourceManagementClient).providers
def resource_providers_client(cli_ctx, subscription_id=None):
return _resource_client_factory(cli_ctx, subscription_id).providers

# Alternate: This should also work
# subscription_id = get_subscription_id(cli_ctx)
# return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id).providers


def _graph_client_factory(cli_ctx, **_):
profile = Profile(cli_ctx=cli_ctx)
cred, _, tenant_id = profile.get_login_credentials(
resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
client = GraphRbacManagementClient(cred, tenant_id,
base_url=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
if os.getenv('AZURE_ACCESS_TOKEN'):
credential = AccessTokenCredential(access_token=os.getenv('AZURE_ACCESS_TOKEN'))
client = GraphRbacManagementClient(credential, os.getenv('AZURE_TENANT_ID'),
akashkeshari marked this conversation as resolved.
Show resolved Hide resolved
base_url=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
else:
profile = Profile(cli_ctx=cli_ctx)
cred, _, tenant_id = profile.get_login_credentials(
resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
client = GraphRbacManagementClient(cred, tenant_id,
base_url=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
configure_common_settings(cli_ctx, client)
return client


def get_graph_client_service_principals(cli_ctx):
return _graph_client_factory(cli_ctx).service_principals


class AccessTokenCredential:
"""Simple access token Authentication. Returns the access token as-is.
"""

def __init__(self, access_token):
self.access_token = access_token

def get_token(self, *arg, **kwargs):
import time
# Assume the access token expires in 60 minutes
return AccessToken(self.access_token, int(time.time()) + 3600)

def signed_session(self, session=None):
session = session or requests.Session()
header = "{} {}".format('Bearer', self.access_token)
session.headers['Authorization'] = header
return session
Comment on lines +108 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for Track 1 SDK. Most likely you won't need it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we require this since the 'GraphRbacManagementClient' still calls this function. When this function was not implemented , I saw the following error : ''AccessTokenCredential' object has no attribute 'signed_session''

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraphRbacManagementClient is the old Track 1 SDK for AD Graph. Consider using MS Graph client: https://github.com/Azure/azure-cli/blob/dev/doc/microsoft_graph_client.md



def validate_custom_token():
if os.getenv('AZURE_SUBSCRIPTION_ID') is None:
telemetry.set_exception(exception='Required environment variables and parameters are not set', fault_type=consts.Custom_Token_Environments_Fault_Type,
summary='Required environment variables and parameters are not set')
raise ValidationError("Environment variable 'AZURE_SUBSCRIPTION_ID' should be set when custom access token is enabled.")
3 changes: 3 additions & 0 deletions src/connectedk8s/azext_connectedk8s/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
Dogfood_RMEndpoint = 'https://api-dogfood.resources.windows-int.net/'
Client_Request_Id_Header = 'x-ms-client-request-id'
Default_Onboarding_Source_Tracking_Guid = "77ade16b-0f55-403b-b7d2-739554a897f2"
Custom_Token_Environments_Fault_Type = 'custom-token-environment-error'
Release_Install_Namespace = "azure-arc-release"
Helm_Environment_File_Fault_Type = 'helm-environment-file-error'
Invalid_Location_Fault_Type = 'location-validation-error'
Location_Fetch_Fault_Type = 'location-fetch-error'
Pls_Location_Mismatch_Fault_Type = 'pls-location-mismatch-error'
Pls_Resource_Not_Found = 'pls-resource-not-found'
Invalid_Argument_Fault_Type = 'argument-validation-error'
Load_Kubeconfig_Fault_Type = 'kubeconfig-load-error'
Read_ConfigMap_Fault_Type = 'configmap-read-error'
Expand Down
5 changes: 4 additions & 1 deletion src/connectedk8s/azext_connectedk8s/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def load_arguments(self, _):

with self.argument_context('connectedk8s connect') as c:
c.argument('tags', tags_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
if os.getenv('AZURE_ACCESS_TOKEN'):
c.argument('location', arg_type=get_location_type(self.cli_ctx))
else:
c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
c.argument('cluster_name', options_list=['--name', '-n'], help='The name of the connected cluster.')
c.argument('kube_config', options_list=['--kube-config'], help='Path to the kube config file.')
c.argument('kube_context', options_list=['--kube-context'], help='Kubconfig context from current machine.')
Expand Down
1 change: 0 additions & 1 deletion src/connectedk8s/azext_connectedk8s/_precheckutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from msrest.exceptions import AuthenticationError, HttpOperationError, TokenExpiredError
from msrest.exceptions import ValidationError as MSRestValidationError
from kubernetes.client.rest import ApiException
from azext_connectedk8s._client_factory import _resource_client_factory, _resource_providers_client
import azext_connectedk8s._constants as consts
import azext_connectedk8s._utils as azext_utils
import azext_connectedk8s.custom as custom
Expand Down
40 changes: 33 additions & 7 deletions src/connectedk8s/azext_connectedk8s/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from msrest.exceptions import AuthenticationError, HttpOperationError, TokenExpiredError
from msrest.exceptions import ValidationError as MSRestValidationError
from kubernetes.client.rest import ApiException
from azext_connectedk8s._client_factory import _resource_client_factory, _resource_providers_client
from azext_connectedk8s._client_factory import resource_providers_client, cf_resource_groups
import azext_connectedk8s._constants as consts
import azext_connectedk8s._precheckutils as precheckutils
import azext_connectedk8s._troubleshootutils as troubleshootutils
Expand Down Expand Up @@ -53,11 +53,11 @@ def send(self, request, **kwargs):


def validate_location(cmd, location):
subscription_id = get_subscription_id(cmd.cli_ctx)
subscription_id = os.getenv('AZURE_SUBSCRIPTION_ID') if os.getenv('AZURE_ACCESS_TOKEN') else get_subscription_id(cmd.cli_ctx)
rp_locations = []
resourceClient = _resource_client_factory(cmd.cli_ctx, subscription_id=subscription_id)
resourceClient = resource_providers_client(cmd.cli_ctx, subscription_id=subscription_id)
try:
providerDetails = resourceClient.providers.get('Microsoft.Kubernetes')
providerDetails = resourceClient.get('Microsoft.Kubernetes')
except Exception as e: # pylint: disable=broad-except
arm_exception_handler(e, consts.Get_ResourceProvider_Fault_Type, 'Failed to fetch resource provider details')
for resourceTypes in providerDetails.resource_types:
Expand All @@ -71,6 +71,29 @@ def validate_location(cmd, location):
break


def validate_custom_token(cmd, resource_group_name, location):
if os.getenv('AZURE_ACCESS_TOKEN'):
if os.getenv('AZURE_SUBSCRIPTION_ID') is None:
akashkeshari marked this conversation as resolved.
Show resolved Hide resolved
telemetry.set_exception(exception='Required environment variables and parameters are not set', fault_type=consts.Custom_Token_Environments_Fault_Type,
summary='Required environment variables and parameters are not set')
raise ValidationError("Environment variable 'AZURE_SUBSCRIPTION_ID' should be set when custom access token is enabled.")
if os.getenv('AZURE_TENANT_ID') is None:
telemetry.set_exception(exception='Required environment variables and parameters are not set', fault_type=consts.Custom_Token_Environments_Fault_Type,
summary='Required environment variables and parameters are not set')
raise ValidationError("Environment variable 'AZURE_TENANT_ID' should be set when custom access token is enabled.")
if location is None:
try:
resource_client = cf_resource_groups(cmd.cli_ctx, os.getenv('AZURE_SUBSCRIPTION_ID'))
rg = resource_client.get(resource_group_name)
location = rg.location
except Exception as ex:
telemetry.set_exception(exception=ex, fault_type=consts.Location_Fetch_Fault_Type,
summary='Unable to fetch location from resource group')
raise ValidationError("Unable to fetch location from resource group: ".format(str(ex)))
return True, location
return False, location


def get_chart_path(registry_path, kube_config, kube_context, helm_client_location, chart_folder_name='AzureArcCharts', chart_name='azure-arc-k8sagents'):
# Pulling helm chart from registry
os.environ['HELM_EXPERIMENTAL_OCI'] = '1'
Expand Down Expand Up @@ -323,9 +346,12 @@ def get_helm_registry(cmd, config_dp_endpoint, dp_endpoint_dogfood=None, release
release_train = release_train_dogfood
uri_parameters = ["releaseTrain={}".format(release_train)]
resource = cmd.cli_ctx.cloud.endpoints.active_directory_resource_id
headers = None
if os.getenv('AZURE_ACCESS_TOKEN'):
headers = ["Authorization=Bearer {}".format(os.getenv('AZURE_ACCESS_TOKEN'))]
# Sending request
try:
r = send_raw_request(cmd.cli_ctx, 'post', get_chart_location_url, uri_parameters=uri_parameters, resource=resource)
r = send_raw_request(cmd.cli_ctx, 'post', get_chart_location_url, headers=headers, uri_parameters=uri_parameters, resource=resource)
except Exception as e:
telemetry.set_exception(exception=e, fault_type=consts.Get_HelmRegistery_Path_Fault_Type,
summary='Error while fetching helm chart registry path')
Expand Down Expand Up @@ -638,9 +664,9 @@ def names(self, names):
logger.debug("Error while trying to monkey patch the fix for list_node(): {}".format(str(ex)))


def check_provider_registrations(cli_ctx):
def check_provider_registrations(cli_ctx, subscription_id):
try:
rp_client = _resource_providers_client(cli_ctx)
rp_client = resource_providers_client(cli_ctx, subscription_id)
cc_registration_state = rp_client.get(consts.Connected_Cluster_Provider_Namespace).registration_state
if cc_registration_state != "Registered":
telemetry.set_exception(exception="{} provider is not registered".format(consts.Connected_Cluster_Provider_Namespace), fault_type=consts.CC_Provider_Namespace_Not_Registered_Fault_Type,
Expand Down
Loading