@@ -15,6 +15,8 @@ original_storage_public_access=""
1515original_storage_default_action=" "
1616original_search_public_access=" "
1717original_foundry_public_access=" "
18+ aif_resource_group=" "
19+ aif_account_resource_id=" "
1820
1921# Function to enable public network access temporarily
2022enable_public_access () {
@@ -67,15 +69,27 @@ enable_public_access() {
6769 fi
6870
6971 # Enable public access for AI Foundry
70- aif_resource_name=$( basename " $aif_resource_id " )
71- echo " Enabling public access for AI Foundry resource: $aif_resource_name "
72- original_foundry_public_access=$( az cognitiveservices account show --name " $aif_resource_name " --resource-group " $resourceGroupName " --query " properties.publicNetworkAccess" --output tsv)
72+ # Extract the account resource ID (remove /projects/... part if present)
73+ aif_account_resource_id=$( echo " $aif_resource_id " | sed ' s|/projects/.*||' )
74+ aif_resource_name=$( basename " $aif_account_resource_id " )
75+ # Extract resource group from the AI Foundry account resource ID
76+ aif_resource_group=$( echo " $aif_account_resource_id " | sed -n ' s|.*/resourceGroups/\([^/]*\)/.*|\1|p' )
77+
78+ # # Validate that we extracted a resource group name
79+ # if [ -z "$aif_resource_group" ]; then
80+ # echo "⚠ Warning: Could not extract resource group from AI Foundry resource ID: $aif_resource_id"
81+ # echo " Falling back to using the main resource group: $resourceGroupName"
82+ # aif_resource_group="$resourceGroupName"
83+ # fi
84+
85+ echo " Enabling public access for AI Foundry resource: $aif_resource_name (Resource Group: $aif_resource_group )"
86+ original_foundry_public_access=$( az cognitiveservices account show --name " $aif_resource_name " --resource-group " $aif_resource_group " --query " properties.publicNetworkAccess" --output tsv)
7387 if [ -z " $original_foundry_public_access " ] || [ " $original_foundry_public_access " = " null" ]; then
7488 echo " ⚠ Info: Could not retrieve AI Foundry network access status."
7589 echo " AI Foundry network access might be managed differently."
7690 elif [ " $original_foundry_public_access " != " Enabled" ]; then
7791 echo " Current AI Foundry public access: $original_foundry_public_access "
78- if MSYS_NO_PATHCONV=1 az resource update --ids " $aif_resource_id " --api-version 2024-10-01 --set properties.publicNetworkAccess=Enabled properties.apiProperties=" {}" --output none; then
92+ if MSYS_NO_PATHCONV=1 az resource update --ids " $aif_account_resource_id " --api-version 2024-10-01 --set properties.publicNetworkAccess=Enabled properties.apiProperties=" {}" --output none; then
7993 echo " ✓ AI Foundry public access enabled"
8094 else
8195 echo " ⚠ Warning: Failed to enable AI Foundry public access automatically."
@@ -150,7 +164,7 @@ restore_network_access() {
150164 if [ -n " $original_foundry_public_access " ] && [ " $original_foundry_public_access " != " Enabled" ]; then
151165 echo " Restoring AI Foundry public access to: $original_foundry_public_access "
152166 # Try using the working approach to restore the original setting
153- if MSYS_NO_PATHCONV=1 az resource update --ids " $aif_resource_id " --api-version 2024-10-01 --set properties.publicNetworkAccess=" $original_foundry_public_access " properties.apiProperties=" {}" --output none 2> /dev/null; then
167+ if MSYS_NO_PATHCONV=1 az resource update --ids " $aif_account_resource_id " --api-version 2024-10-01 --set properties.publicNetworkAccess=" $original_foundry_public_access " properties.apiProperties=" {}" --output none 2> /dev/null; then
154168 echo " ✓ AI Foundry access restored"
155169 else
156170 echo " ⚠ Warning: Failed to restore AI Foundry access automatically."
0 commit comments