Skip to content

Commit b886485

Browse files
authored
Update template utility to throw exception on uri download failure. (#24731)
* Update template utility to throw exception on uri download failure. Update to the template utility caused download failures of a template uri (or template parameter uri) to be suppressed. Update throws argument exception so uri can be fixed before proceeding. Update throws argument exception so uri can be fixed before proceeding. * Update failing test. * Updated changelog.
1 parent 1352799 commit b886485

File tree

4 files changed

+437
-17154
lines changed

4 files changed

+437
-17154
lines changed

src/Resources/ResourceManager/Utilities/TemplateUtility.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ private static string GetTemplateContentFromFile(string templateFilePath)
8686
if (Uri.IsWellFormedUriString(templateFilePath, UriKind.Absolute))
8787
{
8888
templateContent = GeneralUtilities.DownloadFile(templateFilePath);
89+
if (templateContent == null)
90+
{
91+
throw new PSArgumentException("Unable to download template file from provided uri.");
92+
}
8993
}
9094
else if (FileUtilities.DataStore.FileExists(templateFilePath))
9195
{
@@ -158,7 +162,12 @@ private static Hashtable GetTemplateParameterContentFromFile(string templatePara
158162
{
159163
if (Uri.IsWellFormedUriString(templateParameterFilePath, UriKind.Absolute))
160164
{
161-
templateParameterContent = new Hashtable(ParseTemplateParameterContent(GeneralUtilities.DownloadFile(templateParameterFilePath)));
165+
var fileContent = GeneralUtilities.DownloadFile(templateParameterFilePath);
166+
if (fileContent == null)
167+
{
168+
throw new PSArgumentException("Unable to download template parameter file from provided uri.");
169+
}
170+
templateParameterContent = new Hashtable(ParseTemplateParameterContent(fileContent));
162171
}
163172
else if (FileUtilities.DataStore.FileExists(templateParameterFilePath))
164173
{

src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,14 @@ function Test-RemoveDeployment
243243
{
244244
# Setup
245245
$deploymentName = "Test"
246-
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json"
246+
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/b5a68ce5005bc186070506b8d42a25b865f047a6/100-blank-template/azuredeploy.json"
247247
$rgName = "TestSDK0123"
248248

249249
try
250250
{
251251
# First create new resource group deployment
252252
New-AzResourceGroup -Name $rgName -Location "East US"
253-
$job = New-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templateUri -AsJob
254-
Wait-Job $job
255-
$deployment = Receive-Job $job
253+
$deployment = New-AzResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templateUri
256254

257255
# Test
258256
$res = Remove-AzResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName

0 commit comments

Comments
 (0)