Skip to content

Commit cfa8f77

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents b90217e + 523b0cf commit cfa8f77

File tree

6 files changed

+132
-21
lines changed

6 files changed

+132
-21
lines changed

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/GalleryTemplatesClient.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ public Dictionary<string, TemplateFileParameterV1> ParseTemplateParameterFileCon
278278
return parameters;
279279
}
280280

281+
public Dictionary<string, TemplateFileParameterV1> ParseTemplateParameterContent(string templateParameterContent)
282+
{
283+
Dictionary<string, TemplateFileParameterV1> parameters = new Dictionary<string, TemplateFileParameterV1>();
284+
285+
if (!string.IsNullOrEmpty(templateParameterContent))
286+
{
287+
try
288+
{
289+
parameters = JsonConvert.DeserializeObject<Dictionary<string, TemplateFileParameterV1>>(templateParameterContent);
290+
}
291+
catch (JsonSerializationException)
292+
{
293+
parameters = new Dictionary<string, TemplateFileParameterV1>(
294+
JsonConvert.DeserializeObject<TemplateFileParameterV2>(templateParameterContent).Parameters);
295+
}
296+
}
297+
298+
return parameters;
299+
}
300+
281301
private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(string templateContent, Hashtable templateParameterObject, string templateParameterFilePath, string[] staticParameters)
282302
{
283303
RuntimeDefinedParameterDictionary dynamicParameters = new RuntimeDefinedParameterDictionary();
@@ -315,6 +335,11 @@ private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(stri
315335
var parametersFromFile = ParseTemplateParameterFileContents(templateParameterFilePath);
316336
UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromFile));
317337
}
338+
if (templateParameterFilePath != null && Uri.IsWellFormedUriString(templateParameterFilePath, UriKind.Absolute))
339+
{
340+
var parametersFromUri = ParseTemplateParameterContent(GeneralUtilities.DownloadFile(templateParameterFilePath));
341+
UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromUri));
342+
}
318343
return dynamicParameters;
319344
}
320345

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,41 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
329329
Deployment deployment = new Deployment
330330
{
331331
Properties = new DeploymentProperties {
332-
Mode = deploymentMode,
333-
Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
334-
Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
332+
Mode = deploymentMode
335333
}
336334
};
337335

336+
if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
337+
{
338+
deployment.Properties.TemplateLink = new TemplateLink
339+
{
340+
Uri = new Uri(parameters.TemplateFile)
341+
};
342+
}
343+
else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
344+
{
345+
deployment.Properties.TemplateLink = new TemplateLink
346+
{
347+
Uri = new Uri(GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity))
348+
};
349+
}
350+
else
351+
{
352+
deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);
353+
}
354+
355+
if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
356+
{
357+
deployment.Properties.ParametersLink = new ParametersLink
358+
{
359+
Uri = new Uri(parameters.ParameterUri)
360+
};
361+
}
362+
else
363+
{
364+
deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
365+
}
366+
338367
return deployment;
339368
}
340369

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceWithParameterBaseCmdlet.cs

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ public abstract class ResourceWithParameterBaseCmdlet : ResourcesBaseCmdlet
3232
protected const string BaseParameterSetName = "Default";
3333
protected const string GalleryTemplateParameterObjectParameterSetName = "Deployment via Gallery and template parameters object";
3434
protected const string GalleryTemplateParameterFileParameterSetName = "Deployment via Gallery and template parameters file";
35+
protected const string GalleryTemplateParameterUriParameterSetName = "Deployment via Gallery and template parameters uri";
3536
protected const string TemplateFileParameterObjectParameterSetName = "Deployment via template file and template parameters object";
3637
protected const string TemplateFileParameterFileParameterSetName = "Deployment via template file and template parameters file";
38+
protected const string TemplateFileParameterUriParameterSetName = "Deployment via template file template parameters uri";
3739
protected const string TemplateUriParameterObjectParameterSetName = "Deployment via template uri and template parameters object";
3840
protected const string TemplateUriParameterFileParameterSetName = "Deployment via template uri and template parameters file";
41+
protected const string TemplateUriParameterUriParameterSetName = "Deployment via template uri and template parameters uri";
3942
protected const string ParameterlessTemplateFileParameterSetName = "Deployment via template file without parameters";
4043
protected const string ParameterlessGalleryTemplateParameterSetName = "Deployment via Gallery without parameters";
4144
protected const string ParameterlessTemplateUriParameterSetName = "Deployment via template uri without parameters";
@@ -71,10 +74,21 @@ protected ResourceWithParameterBaseCmdlet()
7174
[ValidateNotNullOrEmpty]
7275
public string TemplateParameterFile { get; set; }
7376

77+
[Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName,
78+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
79+
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
80+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
81+
[Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName,
82+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
83+
[ValidateNotNullOrEmpty]
84+
public string TemplateParameterUri { get; set; }
85+
7486
[Parameter(ParameterSetName = GalleryTemplateParameterObjectParameterSetName,
7587
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
7688
[Parameter(ParameterSetName = GalleryTemplateParameterFileParameterSetName,
7789
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
90+
[Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName,
91+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
7892
[Parameter(ParameterSetName = ParameterlessGalleryTemplateParameterSetName,
7993
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
8094
[ValidateNotNullOrEmpty]
@@ -84,6 +98,8 @@ protected ResourceWithParameterBaseCmdlet()
8498
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
8599
[Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName,
86100
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
101+
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
102+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
87103
[Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName,
88104
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
89105
[ValidateNotNullOrEmpty]
@@ -93,17 +109,21 @@ protected ResourceWithParameterBaseCmdlet()
93109
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
94110
[Parameter(ParameterSetName = TemplateUriParameterFileParameterSetName,
95111
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
112+
[Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName,
113+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
96114
[Parameter(ParameterSetName = ParameterlessTemplateUriParameterSetName,
97115
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
98116
[ValidateNotNullOrEmpty]
99117
public string TemplateUri { get; set; }
100118

101119
[Parameter(ParameterSetName = TemplateFileParameterObjectParameterSetName,
102-
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
120+
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
103121
[Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName,
104-
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
122+
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
123+
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
124+
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
105125
[Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName,
106-
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
126+
Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The storage account which the cmdlet should use to upload the template file to. If not specified, the current storage account of the subscription will be used.")]
107127
[ValidateNotNullOrEmpty]
108128
public string StorageAccountName { get; set; }
109129

@@ -141,31 +161,64 @@ public object GetDynamicParameters()
141161
!GalleryTemplateIdentity.Equals(galleryTemplateName, StringComparison.OrdinalIgnoreCase))
142162
{
143163
galleryTemplateName = GalleryTemplateIdentity;
144-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
145-
GalleryTemplateIdentity,
146-
TemplateParameterObject,
147-
this.TryResolvePath(TemplateParameterFile),
148-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
164+
if(string.IsNullOrEmpty(TemplateParameterUri))
165+
{
166+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
167+
GalleryTemplateIdentity,
168+
TemplateParameterObject,
169+
this.TryResolvePath(TemplateParameterFile),
170+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
171+
}
172+
else
173+
{
174+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
175+
GalleryTemplateIdentity,
176+
TemplateParameterObject,
177+
TemplateParameterUri,
178+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
179+
}
149180
}
150181
else if (!string.IsNullOrEmpty(TemplateFile) &&
151182
!TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase))
152183
{
153184
templateFile = TemplateFile;
154-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
155-
this.TryResolvePath(TemplateFile),
156-
TemplateParameterObject,
157-
this.TryResolvePath(TemplateParameterFile),
158-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
185+
if (string.IsNullOrEmpty(TemplateParameterUri))
186+
{
187+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
188+
this.TryResolvePath(TemplateFile),
189+
TemplateParameterObject,
190+
this.TryResolvePath(TemplateParameterFile),
191+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
192+
}
193+
else
194+
{
195+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
196+
this.TryResolvePath(TemplateFile),
197+
TemplateParameterObject,
198+
TemplateParameterUri,
199+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
200+
}
159201
}
160202
else if (!string.IsNullOrEmpty(TemplateUri) &&
161203
!TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase))
162204
{
163205
templateUri = TemplateUri;
164-
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
165-
TemplateUri,
166-
TemplateParameterObject,
167-
this.TryResolvePath(TemplateParameterFile),
168-
MyInvocation.MyCommand.Parameters.Keys.ToArray());
206+
if (string.IsNullOrEmpty(TemplateParameterUri))
207+
{
208+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
209+
TemplateUri,
210+
TemplateParameterObject,
211+
this.TryResolvePath(TemplateParameterFile),
212+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
213+
}
214+
else
215+
{
216+
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
217+
TemplateUri,
218+
TemplateParameterObject,
219+
TemplateParameterUri,
220+
MyInvocation.MyCommand.Parameters.Keys.ToArray());
221+
}
169222
}
170223

171224
return dynamicParameters;

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ValidatePSResourceGroupDeploymentParameters.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class ValidatePSResourceGroupDeploymentParameters
2626

2727
public Hashtable TemplateParameterObject { get; set; }
2828

29+
public string ParameterUri { get; set; }
30+
2931
public string TemplateVersion { get; set; }
3032

3133
public string StorageAccountName { get; set; }

src/ResourceManager/Resources/Commands.Resources/ResourceGroupDeployments/NewAzureResourceGroupDeploymentCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public override void ExecuteCmdlet()
5656
GalleryTemplateIdentity = GalleryTemplateIdentity,
5757
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
5858
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
59+
ParameterUri = TemplateParameterUri,
5960
TemplateVersion = TemplateVersion,
6061
StorageAccountName = StorageAccountName
6162
};

src/ResourceManager/Resources/Commands.Resources/Templates/TestAzureResourceGroupTemplateCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public override void ExecuteCmdlet()
4646
GalleryTemplateIdentity = GalleryTemplateIdentity,
4747
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
4848
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
49+
ParameterUri = TemplateParameterUri,
4950
TemplateVersion = TemplateVersion,
5051
StorageAccountName = StorageAccountName
5152
};

0 commit comments

Comments
 (0)