@@ -34,31 +34,22 @@ def show_cloud(cmd, cloud_name=None):
3434 raise CLIError (e )
3535
3636
37- def _populate_from_metadata_endpoint (cloud , arm_endpoint , session = None ):
38- endpoints_in_metadata = ['active_directory_graph_resource_id' ,
39- 'active_directory_resource_id' , 'active_directory' ]
40- METADATA_ENDPOINT_SUFFIX = '/metadata/endpoints?api-version=2015-01-01'
41- if not arm_endpoint or all ([cloud .endpoints .has_endpoint_set (n ) for n in endpoints_in_metadata ]): # pylint: disable=use-a-generator
42- return
37+ def _populate_from_metadata_endpoint (arm_endpoint , session = None ):
38+ METADATA_ENDPOINT_SUFFIX = '/metadata/endpoints?api-version=2022-09-01'
39+ if not arm_endpoint : # pylint: disable=use-a-generator
40+ return Cloud ('' )
4341 import requests
42+ from azure .cli .core .cloud import _arm_to_cli_mapper
4443 error_msg_fmt = "Unable to get endpoints from the cloud.\n {}"
4544 try :
4645 session = requests .Session () if session is None else session
4746 metadata_endpoint = arm_endpoint + METADATA_ENDPOINT_SUFFIX
4847 response = session .get (metadata_endpoint )
4948 if response .status_code == 200 :
5049 metadata = response .json ()
51- if not cloud .endpoints .has_endpoint_set ('gallery' ):
52- setattr (cloud .endpoints , 'gallery' , metadata .get ('galleryEndpoint' ))
53- if not cloud .endpoints .has_endpoint_set ('active_directory_graph_resource_id' ):
54- setattr (cloud .endpoints , 'active_directory_graph_resource_id' , metadata .get ('graphEndpoint' ))
55- if not cloud .endpoints .has_endpoint_set ('active_directory' ):
56- setattr (cloud .endpoints , 'active_directory' , metadata ['authentication' ].get ('loginEndpoint' ))
57- if not cloud .endpoints .has_endpoint_set ('active_directory_resource_id' ):
58- setattr (cloud .endpoints , 'active_directory_resource_id' , metadata ['authentication' ]['audiences' ][0 ])
59- else :
60- msg = 'Server returned status code {} for {}' .format (response .status_code , metadata_endpoint )
61- raise CLIError (error_msg_fmt .format (msg ))
50+ return _arm_to_cli_mapper (metadata )
51+ msg = 'Server returned status code {} for {}' .format (response .status_code , metadata_endpoint )
52+ raise CLIError (error_msg_fmt .format (msg ))
6253 except (requests .exceptions .ConnectionError , requests .exceptions .HTTPError ) as err :
6354 msg = 'Please ensure you have network connection. Error detail: {}' .format (str (err ))
6455 raise CLIError (error_msg_fmt .format (msg ))
@@ -67,12 +58,18 @@ def _populate_from_metadata_endpoint(cloud, arm_endpoint, session=None):
6758 raise CLIError (error_msg_fmt .format (msg ))
6859
6960
70- def _build_cloud (cli_ctx , cloud_name , cloud_config = None , is_update = False , cloud_args = None ):
71- from azure .cli .core .cloud import CloudEndpointNotSetException
61+ def _build_cloud (cli_ctx , cloud_name , cloud_config = None , cloud_args = None ):
7262 if cloud_config :
7363 # Using JSON format so convert the keys to snake case
7464 cloud_args = {to_snake_case (k ): v for k , v in cloud_config .items ()}
75- c = Cloud (cloud_name )
65+ arm_endpoint = None
66+ if 'endpoints' in cloud_args :
67+ arm_endpoint = (cloud_args ['endpoints' ].get ('resource_manager' , None ) or
68+ cloud_args ['endpoints' ].get ('resourceManager' , None ))
69+ if 'endpoint_resource_manager' in cloud_args :
70+ arm_endpoint = cloud_args ['endpoint_resource_manager' ]
71+ c = _populate_from_metadata_endpoint (arm_endpoint )
72+ c .name = cloud_name
7673 c .profile = cloud_args .get ('profile' , None )
7774 try :
7875 endpoints = cloud_args ['endpoints' ]
@@ -93,18 +90,6 @@ def _build_cloud(cli_ctx, cloud_name, cloud_config=None, is_update=False, cloud_
9390 elif arg .startswith ('suffix_' ) and cloud_args [arg ] is not None :
9491 setattr (c .suffixes , arg .replace ('suffix_' , '' ), cloud_args [arg ])
9592
96- try :
97- arm_endpoint = c .endpoints .resource_manager
98- except CloudEndpointNotSetException :
99- arm_endpoint = None
100-
101- from azure .cli .core .breaking_change import print_conditional_breaking_change
102- if arm_endpoint and is_update :
103- print_conditional_breaking_change (cli_ctx , tag = 'CloudUpdateOutputBreakingChange' )
104- elif arm_endpoint :
105- print_conditional_breaking_change (cli_ctx , tag = 'CloudRegisterOutputBreakingChange' )
106-
107- _populate_from_metadata_endpoint (c , arm_endpoint )
10893 required_endpoints = {'resource_manager' : '--endpoint-resource-manager' ,
10994 'active_directory' : '--endpoint-active-directory' ,
11095 'active_directory_resource_id' : '--endpoint-active-directory-resource-id' ,
@@ -138,7 +123,7 @@ def register_cloud(cmd,
138123 suffix_azure_datalake_store_file_system_endpoint = None ,
139124 suffix_azure_datalake_analytics_catalog_and_job_endpoint = None ,
140125 suffix_acr_login_server_endpoint = None ):
141- c = _build_cloud (cmd .cli_ctx , cloud_name , cloud_config = cloud_config , is_update = False ,
126+ c = _build_cloud (cmd .cli_ctx , cloud_name , cloud_config = cloud_config ,
142127 cloud_args = locals ())
143128 try :
144129 add_cloud (cmd .cli_ctx , c )
@@ -167,7 +152,7 @@ def modify_cloud(cmd,
167152 suffix_acr_login_server_endpoint = None ):
168153 if not cloud_name :
169154 cloud_name = cmd .cli_ctx .cloud .name
170- c = _build_cloud (cmd .cli_ctx , cloud_name , cloud_config = cloud_config , is_update = True ,
155+ c = _build_cloud (cmd .cli_ctx , cloud_name , cloud_config = cloud_config ,
171156 cloud_args = locals ())
172157 try :
173158 update_cloud (cmd .cli_ctx , c )
0 commit comments