Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,9 @@ cloud register:
endpoint_active_directory_resource_id:
rule_exclusions:
- option_length_too_long
endpoint_microsoft_graph_resource_id:
rule_exclusions:
- option_length_too_long
endpoint_resource_manager:
rule_exclusions:
- option_length_too_long
Expand All @@ -1257,6 +1260,9 @@ cloud register:
endpoint_vm_image_alias_doc:
rule_exclusions:
- option_length_too_long
skip_endpoint_discovery:
rule_exclusions:
- option_length_too_long
suffix_acr_login_server_endpoint:
rule_exclusions:
- option_length_too_long
Expand Down Expand Up @@ -1289,6 +1295,9 @@ cloud update:
endpoint_active_directory_resource_id:
rule_exclusions:
- option_length_too_long
endpoint_microsoft_graph_resource_id:
rule_exclusions:
- option_length_too_long
endpoint_resource_manager:
rule_exclusions:
- option_length_too_long
Expand All @@ -1298,6 +1307,9 @@ cloud update:
endpoint_vm_image_alias_doc:
rule_exclusions:
- option_length_too_long
skip_endpoint_discovery:
rule_exclusions:
- option_length_too_long
suffix_acr_login_server_endpoint:
rule_exclusions:
- option_length_too_long
Expand Down
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def load_arguments(self, command):
c.argument('cloud_name', options_list=('--name', '-n'), help='Name of a registered cloud', completer=get_cloud_name_completion_list)
c.argument('profile', help='Profile to use for this cloud. The azure stack profiles `2017-03-09-profile` `2018-03-01-hybrid` `2019-03-01-hybrid` and `2020-09-01-hybrid` have been deprecated and removed. To continue using Azure Stack, please install the Azure CLI `2.66.*` (LTS) version. For more details, refer to: https://learn.microsoft.com/en-us/cli/azure/whats-new-overview#important-notice-for-azure-stack-hub-customers', choices=list(API_PROFILES))
c.argument('cloud_config', options_list=('--cloud-config',), help='JSON encoded cloud configuration. Use @{file} to load from a file.', type=shell_safe_json_parse)
c.argument('skip_endpoint_discovery', action='store_true', help="If specified, the cloud endpoints' auto discovery will be skipped")
c.argument('endpoint_management', help='The management service endpoint')
c.argument('endpoint_resource_manager', help='The resource management endpoint')
c.argument('endpoint_sql_management', help='The sql server management endpoint')
c.argument('endpoint_gallery', help='The template gallery endpoint')
c.argument('endpoint_active_directory', help='The Active Directory login endpoint')
c.argument('endpoint_active_directory_resource_id', help='The resource ID to obtain AD tokens for')
c.argument('endpoint_active_directory_graph_resource_id', help='The Active Directory resource ID')
c.argument('endpoint_microsoft_graph_resource_id', help='The Microsoft Graph resource ID')
c.argument('endpoint_active_directory_data_lake_resource_id', help='The Active Directory resource ID for data lake services')
c.argument('endpoint_vm_image_alias_doc', help='The uri of the document which caches commonly used virtual machine images')
c.argument('suffix_sql_server_hostname', help='The dns suffix for sql servers')
Expand Down
36 changes: 21 additions & 15 deletions src/azure-cli/azure/cli/command_modules/cloud/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ def _populate_from_metadata_endpoint(arm_endpoint, session=None):
raise CLIError(error_msg_fmt.format(msg))


def _build_cloud(cli_ctx, cloud_name, cloud_config=None, cloud_args=None):
def _build_cloud(cli_ctx, cloud_name, skip_endpoint_discovery=False, cloud_config=None, cloud_args=None):
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

[nitpick] The skip-discovery branch duplicates parts of the cloud construction logic. Consider refactoring so common setup (e.g., setting c.name, c.profile, and applying cloud_args) is shared, reducing code duplication.

Copilot uses AI. Check for mistakes.
if cloud_config:
# Using JSON format so convert the keys to snake case
cloud_args = {to_snake_case(k): v for k, v in cloud_config.items()}
arm_endpoint = None
if 'endpoints' in cloud_args:
arm_endpoint = (cloud_args['endpoints'].get('resource_manager', None) or
cloud_args['endpoints'].get('resourceManager', None))
if 'endpoint_resource_manager' in cloud_args:
arm_endpoint = cloud_args['endpoint_resource_manager']
c = _populate_from_metadata_endpoint(arm_endpoint)
c.name = cloud_name
if skip_endpoint_discovery:
c = Cloud(cloud_name)
else:
arm_endpoint = None
if 'endpoints' in cloud_args:
arm_endpoint = (cloud_args['endpoints'].get('resource_manager', None) or
cloud_args['endpoints'].get('resourceManager', None))
if 'endpoint_resource_manager' in cloud_args:
arm_endpoint = cloud_args['endpoint_resource_manager']
c = _populate_from_metadata_endpoint(arm_endpoint)
c.name = cloud_name
c.profile = cloud_args.get('profile', None)
try:
endpoints = cloud_args['endpoints']
Expand All @@ -92,8 +95,7 @@ def _build_cloud(cli_ctx, cloud_name, cloud_config=None, cloud_args=None):

required_endpoints = {'resource_manager': '--endpoint-resource-manager',
'active_directory': '--endpoint-active-directory',
'active_directory_resource_id': '--endpoint-active-directory-resource-id',
'active_directory_graph_resource_id': '--endpoint-active-directory-graph-resource-id'}
'active_directory_resource_id': '--endpoint-active-directory-resource-id'}
missing_endpoints = [e_param for e_name, e_param in required_endpoints.items()
if not c.endpoints.has_endpoint_set(e_name)]
if missing_endpoints and not cloud_is_registered(cli_ctx, cloud_name):
Expand All @@ -108,13 +110,15 @@ def register_cloud(cmd,
cloud_name,
cloud_config=None,
profile=None,
skip_endpoint_discovery=False,
endpoint_management=None,
endpoint_resource_manager=None,
endpoint_sql_management=None,
endpoint_gallery=None,
endpoint_active_directory=None,
endpoint_active_directory_resource_id=None,
endpoint_active_directory_graph_resource_id=None,
endpoint_microsoft_graph_resource_id=None,
endpoint_active_directory_data_lake_resource_id=None,
endpoint_vm_image_alias_doc=None,
suffix_sql_server_hostname=None,
Expand All @@ -123,8 +127,8 @@ def register_cloud(cmd,
suffix_azure_datalake_store_file_system_endpoint=None,
suffix_azure_datalake_analytics_catalog_and_job_endpoint=None,
suffix_acr_login_server_endpoint=None):
c = _build_cloud(cmd.cli_ctx, cloud_name, cloud_config=cloud_config,
cloud_args=locals())
c = _build_cloud(cmd.cli_ctx, cloud_name, skip_endpoint_discovery=skip_endpoint_discovery,
cloud_config=cloud_config, cloud_args=locals())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using locals() is very hacky and unpredictable. It may end up with unwanted variables being recorded in the cloud.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's an old implementation which is unrelated with my changes. So I didn't modify it

Copy link
Copy Markdown
Member

@jiasli jiasli Jun 13, 2025

Choose a reason for hiding this comment

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

I know. Technical debt, not necessary to address right now.

try:
add_cloud(cmd.cli_ctx, c)
except CloudAlreadyRegisteredException as e:
Expand All @@ -135,13 +139,15 @@ def modify_cloud(cmd,
cloud_name=None,
cloud_config=None,
profile=None,
skip_endpoint_discovery=False,
endpoint_management=None,
endpoint_resource_manager=None,
endpoint_sql_management=None,
endpoint_gallery=None,
endpoint_active_directory=None,
endpoint_active_directory_resource_id=None,
endpoint_active_directory_graph_resource_id=None,
endpoint_microsoft_graph_resource_id=None,
endpoint_active_directory_data_lake_resource_id=None,
endpoint_vm_image_alias_doc=None,
suffix_sql_server_hostname=None,
Expand All @@ -152,8 +158,8 @@ def modify_cloud(cmd,
suffix_acr_login_server_endpoint=None):
if not cloud_name:
cloud_name = cmd.cli_ctx.cloud.name
c = _build_cloud(cmd.cli_ctx, cloud_name, cloud_config=cloud_config,
cloud_args=locals())
c = _build_cloud(cmd.cli_ctx, cloud_name, skip_endpoint_discovery=skip_endpoint_discovery,
cloud_config=cloud_config, cloud_args=locals())
try:
update_cloud(cmd.cli_ctx, c)
except CloudNotRegisteredException as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ def test_cloud_scenario(self):
assert result['endpoints']['activeDirectory'] == 'https://login.myendpoint.com/'
assert result['endpoints']['management'] == 'https://management.myendpoint.com/'

# Skip cloud discovery
self.cmd('cloud update --name {name} --endpoint-resource-manager https://foo.example.com --skip-endpoint-discovery')
result = self.cmd('cloud show --name {name}').get_output_in_json()
assert result['endpoints']['resourceManager'] == 'https://foo.example.com'

# TODO: Test all arguments of `az cloud update`

self.cmd('cloud set --name {name} --profile latest')
Expand Down
Loading