From dee7b4f3cd5383de8d92dbd8b5f0db0105f2b1d1 Mon Sep 17 00:00:00 2001 From: Zelin Wang Date: Wed, 21 Jan 2026 10:14:32 +0800 Subject: [PATCH 1/2] [Core] Replace GitHub URLs with AME Storage for network isolated requirements --- src/azure-cli-core/azure/cli/core/cloud.py | 8 +-- src/azure-cli-core/azure/cli/core/util.py | 55 +++++++++++++++---- .../azure/cli/command_modules/util/custom.py | 4 +- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/cloud.py b/src/azure-cli-core/azure/cli/core/cloud.py index 292884805a2..f8f90009835 100644 --- a/src/azure-cli-core/azure/cli/core/cloud.py +++ b/src/azure-cli-core/azure/cli/core/cloud.py @@ -373,7 +373,7 @@ class CloudNameEnum: # pylint: disable=too-few-public-methods active_directory_graph_resource_id='https://graph.windows.net/', microsoft_graph_resource_id='https://graph.microsoft.com/', active_directory_data_lake_resource_id='https://datalake.azure.net/', - vm_image_alias_doc='https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json', + vm_image_alias_doc='https://azcliprod.blob.core.windows.net/cli/vm/aliases.json', media_resource_id='https://rest.media.azure.net', ossrdbms_resource_id='https://ossrdbms-aad.database.windows.net', app_insights_resource_id='https://api.applicationinsights.io', @@ -410,7 +410,7 @@ class CloudNameEnum: # pylint: disable=too-few-public-methods active_directory_resource_id='https://management.core.chinacloudapi.cn/', active_directory_graph_resource_id='https://graph.chinacloudapi.cn/', microsoft_graph_resource_id='https://microsoftgraph.chinacloudapi.cn', - vm_image_alias_doc='https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json', + vm_image_alias_doc='https://azcliprod.blob.core.windows.net/cli/vm/aliases.json', media_resource_id='https://rest.media.chinacloudapi.cn', ossrdbms_resource_id='https://ossrdbms-aad.database.chinacloudapi.cn', app_insights_resource_id='https://api.applicationinsights.azure.cn', @@ -444,7 +444,7 @@ class CloudNameEnum: # pylint: disable=too-few-public-methods active_directory_resource_id='https://management.core.usgovcloudapi.net/', active_directory_graph_resource_id='https://graph.microsoftazure.us/', microsoft_graph_resource_id='https://graph.microsoft.us/', - vm_image_alias_doc='https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json', + vm_image_alias_doc='https://azcliprod.blob.core.windows.net/cli/vm/aliases.json', media_resource_id='https://rest.media.usgovcloudapi.net', ossrdbms_resource_id='https://ossrdbms-aad.database.usgovcloudapi.net', app_insights_resource_id='https://api.applicationinsights.us', @@ -479,7 +479,7 @@ class CloudNameEnum: # pylint: disable=too-few-public-methods active_directory_resource_id='https://management.core.cloudapi.de/', active_directory_graph_resource_id='https://graph.cloudapi.de/', microsoft_graph_resource_id='https://graph.microsoft.de', - vm_image_alias_doc='https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json', + vm_image_alias_doc='https://azcliprod.blob.core.windows.net/cli/vm/aliases.json', media_resource_id='https://rest.media.cloudapi.de', ossrdbms_resource_id='https://ossrdbms-aad.database.cloudapi.de', portal='https://portal.microsoftazure.de'), diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index b6f1a791baf..9da8ab0138c 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -52,6 +52,12 @@ "sys", "test2", "test3", "user4", "user5" ] +# AME Storage Account URL for version checking and VM image aliases (Network Isolation) +# Files are stored as: +# - https://azcliprod.blob.core.windows.net/cli/{package}/setup.py (CLI versions) +# - https://azcliprod.blob.core.windows.net/cli/vm/aliases.json (VM image aliases) +AME_STORAGE_BASE_URL = "https://azcliprod.blob.core.windows.net/cli" + def handle_exception(ex): # pylint: disable=too-many-locals, too-many-statements, too-many-branches # For error code, follow guidelines at https://docs.python.org/2/library/sys.html#sys.exit, @@ -291,14 +297,23 @@ def __init__(self, key, version): ] -def get_latest_from_github(package_path='azure-cli'): +def get_latest_version_from_ame_storage(package_path='azure-cli'): + """Get the latest version from AME Storage Account. + + This replaces get_latest_from_github() due to network isolation requirements. + The setup.py files are uploaded to AME Storage Account during release pipeline. + + Args: + package_path: Package name, e.g., 'azure-cli', 'azure-cli-core', 'azure-cli-telemetry', 'azure-cli-testsdk' + """ try: import requests - git_url = "https://raw.githubusercontent.com/Azure/azure-cli/main/src/{}/setup.py".format(package_path) - response = requests.get(git_url, timeout=10) + storage_url = "{}/{}/setup.py".format(AME_STORAGE_BASE_URL, package_path) + + response = requests.get(storage_url, timeout=10) if response.status_code != 200: logger.info("Failed to fetch the latest version from '%s' with status code '%s' and reason '%s'", - git_url, response.status_code, response.reason) + storage_url, response.status_code, response.reason) return None for line in response.iter_lines(): txt = line.decode('utf-8', errors='ignore') @@ -307,16 +322,28 @@ def get_latest_from_github(package_path='azure-cli'): if match: return match.group(1) except Exception as ex: # pylint: disable=broad-except - logger.info("Failed to get the latest version from '%s'. %s", git_url, str(ex)) + logger.info("Failed to get the latest version from '%s'. %s", storage_url, str(ex)) return None -def _update_latest_from_github(versions): - if not check_connectivity(url='https://raw.githubusercontent.com', max_retries=0): +def get_latest_from_github(package_path='azure-cli'): + """Deprecated: Use get_latest_version_from_ame_storage() instead. + + This function is kept for backward compatibility but now reads from AME Storage Account. + """ + return get_latest_version_from_ame_storage(package_path) + + +def _update_latest_from_ame_storage(versions): + """Update versions from AME Storage Account. + + This replaces _update_latest_from_github() due to network isolation requirements. + """ + if not check_connectivity(url=AME_STORAGE_BASE_URL, max_retries=0): return versions, False success = True for pkg in ['azure-cli-core', 'azure-cli-telemetry']: - version = get_latest_from_github(pkg) + version = get_latest_version_from_ame_storage(pkg) if not version: success = False else: @@ -328,6 +355,14 @@ def _update_latest_from_github(versions): return versions, success +def _update_latest_from_github(versions): + """Deprecated: Use _update_latest_from_ame_storage() instead. + + This function is kept for backward compatibility but now reads from AME Storage Account. + """ + return _update_latest_from_ame_storage(versions) + + def get_cached_latest_versions(versions=None): """ Get the latest versions from a cached file""" import datetime @@ -343,7 +378,7 @@ def get_cached_latest_versions(versions=None): if cache_versions and cache_versions['azure-cli']['local'] == versions['azure-cli']['local']: return cache_versions.copy(), True - versions, success = _update_latest_from_github(versions) + versions, success = _update_latest_from_ame_storage(versions) VERSIONS['versions'] = versions VERSIONS[_VERSION_UPDATE_TIME] = str(datetime.datetime.now()) return versions.copy(), success @@ -369,7 +404,7 @@ def get_az_version_string(use_cache=False): # pylint: disable=too-many-statemen versions = _get_local_versions() # get the versions from pypi - versions, success = get_cached_latest_versions(versions) if use_cache else _update_latest_from_github(versions) + versions, success = get_cached_latest_versions(versions) if use_cache else _update_latest_from_ame_storage(versions) updates_available_components = [] def _print(val=''): diff --git a/src/azure-cli/azure/cli/command_modules/util/custom.py b/src/azure-cli/azure/cli/command_modules/util/custom.py index ea2f2ea0bd0..21bb4716a40 100644 --- a/src/azure-cli/azure/cli/command_modules/util/custom.py +++ b/src/azure-cli/azure/cli/command_modules/util/custom.py @@ -50,8 +50,8 @@ def upgrade_version(cmd, update_all=None, yes=None, allow_preview=None): # pyli from packaging.version import parse update_cli = True - from azure.cli.core.util import get_latest_from_github - latest_version = get_latest_from_github() + from azure.cli.core.util import get_latest_version_from_ame_storage + latest_version = get_latest_version_from_ame_storage() if not latest_version: logger.warning("Failed to get the latest azure-cli version.") update_cli = False From 03fb3b6a72c96e63522fae72cea16082d77ab075 Mon Sep 17 00:00:00 2001 From: Zelin Wang Date: Wed, 21 Jan 2026 11:34:18 +0800 Subject: [PATCH 2/2] update --- src/azure-cli-core/azure/cli/core/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 9da8ab0138c..75a421f5dfd 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -302,7 +302,7 @@ def get_latest_version_from_ame_storage(package_path='azure-cli'): This replaces get_latest_from_github() due to network isolation requirements. The setup.py files are uploaded to AME Storage Account during release pipeline. - + Args: package_path: Package name, e.g., 'azure-cli', 'azure-cli-core', 'azure-cli-telemetry', 'azure-cli-testsdk' """