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
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,26 @@ public Dictionary<string, TemplateFileParameterV1> ParseTemplateParameterFileCon
return parameters;
}

public Dictionary<string, TemplateFileParameterV1> ParseTemplateParameterContent(string templateParameterContent)
{
Dictionary<string, TemplateFileParameterV1> parameters = new Dictionary<string, TemplateFileParameterV1>();

if (!string.IsNullOrEmpty(templateParameterContent))
{
try
{
parameters = JsonConvert.DeserializeObject<Dictionary<string, TemplateFileParameterV1>>(templateParameterContent);
}
catch (JsonSerializationException)
{
parameters = new Dictionary<string, TemplateFileParameterV1>(
JsonConvert.DeserializeObject<TemplateFileParameterV2>(templateParameterContent).Parameters);
}
}

return parameters;
}

private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(string templateContent, Hashtable templateParameterObject, string templateParameterFilePath, string[] staticParameters)
{
RuntimeDefinedParameterDictionary dynamicParameters = new RuntimeDefinedParameterDictionary();
Expand Down Expand Up @@ -315,6 +335,11 @@ private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(stri
var parametersFromFile = ParseTemplateParameterFileContents(templateParameterFilePath);
UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromFile));
}
if (templateParameterFilePath != null && Uri.IsWellFormedUriString(templateParameterFilePath, UriKind.Absolute))
{
var parametersFromUri = ParseTemplateParameterContent(GeneralUtilities.DownloadFile(templateParameterFilePath));
UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromUri));
}
return dynamicParameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,41 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
Deployment deployment = new Deployment
{
Properties = new DeploymentProperties {
Mode = deploymentMode,
Template = GetTemplate(parameters.TemplateFile, parameters.GalleryTemplateIdentity),
Parameters = GetDeploymentParameters(parameters.TemplateParameterObject)
Mode = deploymentMode
}
};

if (Uri.IsWellFormedUriString(parameters.TemplateFile, UriKind.Absolute))
{
deployment.Properties.TemplateLink = new TemplateLink
{
Uri = new Uri(parameters.TemplateFile)
};
}
else if (!string.IsNullOrEmpty(parameters.GalleryTemplateIdentity))
{
deployment.Properties.TemplateLink = new TemplateLink
{
Uri = new Uri(GalleryTemplatesClient.GetGalleryTemplateFile(parameters.GalleryTemplateIdentity))
};
}
else
{
deployment.Properties.Template = FileUtilities.DataStore.ReadFileAsText(parameters.TemplateFile);
}

if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
{
deployment.Properties.ParametersLink = new ParametersLink
{
Uri = new Uri(parameters.ParameterUri)
};
}
else
{
deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
}

return deployment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ public abstract class ResourceWithParameterBaseCmdlet : ResourcesBaseCmdlet
protected const string BaseParameterSetName = "Default";
protected const string GalleryTemplateParameterObjectParameterSetName = "Deployment via Gallery and template parameters object";
protected const string GalleryTemplateParameterFileParameterSetName = "Deployment via Gallery and template parameters file";
protected const string GalleryTemplateParameterUriParameterSetName = "Deployment via Gallery and template parameters uri";
protected const string TemplateFileParameterObjectParameterSetName = "Deployment via template file and template parameters object";
protected const string TemplateFileParameterFileParameterSetName = "Deployment via template file and template parameters file";
protected const string TemplateFileParameterUriParameterSetName = "Deployment via template file template parameters uri";
protected const string TemplateUriParameterObjectParameterSetName = "Deployment via template uri and template parameters object";
protected const string TemplateUriParameterFileParameterSetName = "Deployment via template uri and template parameters file";
protected const string TemplateUriParameterUriParameterSetName = "Deployment via template uri and template parameters uri";
protected const string ParameterlessTemplateFileParameterSetName = "Deployment via template file without parameters";
protected const string ParameterlessGalleryTemplateParameterSetName = "Deployment via Gallery without parameters";
protected const string ParameterlessTemplateUriParameterSetName = "Deployment via template uri without parameters";
Expand Down Expand Up @@ -71,10 +74,21 @@ protected ResourceWithParameterBaseCmdlet()
[ValidateNotNullOrEmpty]
public string TemplateParameterFile { get; set; }

[Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
[Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template parameter file.")]
[ValidateNotNullOrEmpty]
public string TemplateParameterUri { get; set; }

[Parameter(ParameterSetName = GalleryTemplateParameterObjectParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
[Parameter(ParameterSetName = GalleryTemplateParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
[Parameter(ParameterSetName = GalleryTemplateParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
[Parameter(ParameterSetName = ParameterlessGalleryTemplateParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the template in the gallery.")]
[ValidateNotNullOrEmpty]
Expand All @@ -84,6 +98,8 @@ protected ResourceWithParameterBaseCmdlet()
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
[Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
[Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Local path to the template file.")]
[ValidateNotNullOrEmpty]
Expand All @@ -93,17 +109,21 @@ protected ResourceWithParameterBaseCmdlet()
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
[Parameter(ParameterSetName = TemplateUriParameterFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
[Parameter(ParameterSetName = TemplateUriParameterUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
[Parameter(ParameterSetName = ParameterlessTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Uri to the template file.")]
[ValidateNotNullOrEmpty]
public string TemplateUri { get; set; }

[Parameter(ParameterSetName = TemplateFileParameterObjectParameterSetName,
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.")]
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.")]
[Parameter(ParameterSetName = TemplateFileParameterFileParameterSetName,
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.")]
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.")]
[Parameter(ParameterSetName = TemplateFileParameterUriParameterSetName,
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.")]
[Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName,
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.")]
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.")]
[ValidateNotNullOrEmpty]
public string StorageAccountName { get; set; }

Expand Down Expand Up @@ -141,31 +161,64 @@ public object GetDynamicParameters()
!GalleryTemplateIdentity.Equals(galleryTemplateName, StringComparison.OrdinalIgnoreCase))
{
galleryTemplateName = GalleryTemplateIdentity;
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
GalleryTemplateIdentity,
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
if(string.IsNullOrEmpty(TemplateParameterUri))
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
GalleryTemplateIdentity,
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
else
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromGallery(
GalleryTemplateIdentity,
TemplateParameterObject,
TemplateParameterUri,
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
}
else if (!string.IsNullOrEmpty(TemplateFile) &&
!TemplateFile.Equals(templateFile, StringComparison.OrdinalIgnoreCase))
{
templateFile = TemplateFile;
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
this.TryResolvePath(TemplateFile),
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
if (string.IsNullOrEmpty(TemplateParameterUri))
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
this.TryResolvePath(TemplateFile),
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
else
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
this.TryResolvePath(TemplateFile),
TemplateParameterObject,
TemplateParameterUri,
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
}
else if (!string.IsNullOrEmpty(TemplateUri) &&
!TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase))
{
templateUri = TemplateUri;
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
TemplateUri,
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
if (string.IsNullOrEmpty(TemplateParameterUri))
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
TemplateUri,
TemplateParameterObject,
this.TryResolvePath(TemplateParameterFile),
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
else
{
dynamicParameters = GalleryTemplatesClient.GetTemplateParametersFromFile(
TemplateUri,
TemplateParameterObject,
TemplateParameterUri,
MyInvocation.MyCommand.Parameters.Keys.ToArray());
}
}

return dynamicParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ValidatePSResourceGroupDeploymentParameters

public Hashtable TemplateParameterObject { get; set; }

public string ParameterUri { get; set; }

public string TemplateVersion { get; set; }

public string StorageAccountName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override void ExecuteCmdlet()
GalleryTemplateIdentity = GalleryTemplateIdentity,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
ParameterUri = TemplateParameterUri,
TemplateVersion = TemplateVersion,
StorageAccountName = StorageAccountName
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override void ExecuteCmdlet()
GalleryTemplateIdentity = GalleryTemplateIdentity,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
ParameterUri = TemplateParameterUri,
TemplateVersion = TemplateVersion,
StorageAccountName = StorageAccountName
};
Expand Down