Skip to content

Adding Deployment Stacks cmdlet Implementations to Az.Resources #22019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ee4c24a
Squashed commit of the following:
dantedallag May 11, 2023
c255fb2
connect stacks to new checked in sdk
dantedallag May 16, 2023
4e5063a
Updates to cmdlets for bicep params and query string
dantedallag May 19, 2023
440f4f4
taking params and param sets out of set/create commands in stacks
dantedallag May 20, 2023
41b2050
refactor cmdlets to be more straightforward
dantedallag May 23, 2023
3df1745
changes for sdk
dantedallag May 23, 2023
7156df9
adding the sdk generated files for stacks
dantedallag May 26, 2023
4610ef2
reverting some unexpected changes and adding headers
dantedallag May 30, 2023
368330f
Updated session records
dantedallag Jun 7, 2023
bbdbc56
remove unused parameter
dantedallag Jun 7, 2023
2e039b5
updated changelog
dantedallag Jun 7, 2023
7c25299
Update markdown files for stack cmdlets
dantedallag Jun 8, 2023
30a4a81
updated the help documents
dantedallag Jun 14, 2023
75910d1
updates to make cmdlets preview and addressing comments
dantedallag Jun 15, 2023
91d89b6
Corrected plural parameter names and regenerated help files
Xynoclafe Jun 15, 2023
5ce09f8
Fixed satic analysis issues in help files
Xynoclafe Jun 16, 2023
47d04ca
Remove PS prompt from help examples
Xynoclafe Jun 16, 2023
156c731
Change -Name parameter to -StackName in Export cmdlets
Xynoclafe Jun 16, 2023
d92cd38
Rename Export cmdlets to Save
Xynoclafe Jun 19, 2023
e182696
Remove unnecessary changes from csproj files
Xynoclafe Jun 19, 2023
aaa7e65
Update the help files of export cmdlets to use save verbage instead o…
Xynoclafe Jun 20, 2023
3264b9a
changing 'export' method name to 'save'
dantedallag Jun 21, 2023
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
2 changes: 1 addition & 1 deletion src/Accounts/Accounts/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ResourceIdentifier

public string Subscription { get; set; }

public string ManagementGroupName { get; set; }

public ResourceIdentifier() { }

public ResourceIdentifier(string idFromServer)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Collections;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
public abstract class DeploymentStacksCmdletBase : ResourceManagerCmdletBase
{

/// <summary>
/// Deployment stacks client instance field
/// </summary>
private DeploymentStacksSdkClient deploymentStacksSdkClient;

/// <summary>
/// Gets or sets the deployment stacks sdk client
/// </summary>
public DeploymentStacksSdkClient DeploymentStacksSdkClient
{
get
{
if (this.deploymentStacksSdkClient == null)
{
this.deploymentStacksSdkClient = new DeploymentStacksSdkClient(DefaultContext);
}

this.deploymentStacksSdkClient.VerboseLogger = WriteVerboseWithTimestamp;
this.deploymentStacksSdkClient.ErrorLogger = WriteErrorWithTimestamp;
this.deploymentStacksSdkClient.WarningLogger = WriteWarningWithTimestamp;

return this.deploymentStacksSdkClient;
}

set
{
this.deploymentStacksSdkClient = value;
}
}

protected string ResolveBicepFile(string TemplateFile)
{
if (BicepUtility.IsBicepFile(TemplateFile))
{
return BicepUtility.BuildFile(this.ResolvePath(TemplateFile), this.WriteVerbose, this.WriteWarning);
}
else
return TemplateFile;

}

protected string ResolveBicepParameterFile(string TemplateParameterFile)
{
if (BicepUtility.IsBicepparamFile(TemplateParameterFile))
{
return BicepUtility.BuildParamFile(this.ResolvePath(TemplateParameterFile), this.WriteVerbose, this.WriteWarning);
}
else
return TemplateParameterFile;
}

protected Hashtable GetParameterObject(string parameterFile)
{
var parameters = new Hashtable();
string templateParameterFilePath = this.ResolvePath(parameterFile);
if (parameterFile != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
{
var parametersFromFile = TemplateUtility.ParseTemplateParameterFileContents(templateParameterFilePath);
parametersFromFile.ForEach(dp =>
{
var parameter = new Hashtable();
if (dp.Value.Value != null)
{
parameter.Add("value", dp.Value.Value);
}
if (dp.Value.Reference != null)
{
parameter.Add("reference", dp.Value.Reference);
}

parameters[dp.Key] = parameter;
});
}
return parameters;
}

protected Hashtable GetTemplateParameterObject(Hashtable templateParameterObject)
{
//create a new Hashtable so that user can re-use the templateParameterObject.
var parameterObject = new Hashtable();
foreach (var parameterKey in templateParameterObject.Keys)
{
// Let default behavior of a value parameter if not a KeyVault reference Hashtable
var hashtableParameter = templateParameterObject[parameterKey] as Hashtable;
if (hashtableParameter != null && hashtableParameter.ContainsKey("reference"))
{
parameterObject[parameterKey] = templateParameterObject[parameterKey];
}
else
{
parameterObject[parameterKey] = new Hashtable { { "value", templateParameterObject[parameterKey] } };
}
}
return parameterObject;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase
{
public class DeploymentStacksCreateCmdletBase : DeploymentStacksCmdletBase
{
#region Cmdlet Parameters and Parameter Set Definitions

protected string protectedTemplateUri;

protected DeploymentStacksCreateCmdletBase()
{
}

internal const string ParameterlessTemplateFileParameterSetName = "ByTemplateFileWithNoParameters";
internal const string ParameterlessTemplateUriParameterSetName = "ByTemplateUriWithNoParameters";
internal const string ParameterlessTemplateSpecParameterSetName = "ByTemplateSpecWithNoParameters";

internal const string ParameterFileTemplateFileParameterSetName = "ByTemplateFileWithParameterFile";
internal const string ParameterFileTemplateUriParameterSetName = "ByTemplateUriWithParameterFile";
internal const string ParameterFileTemplateSpecParameterSetName = "ByTemplateSpecWithParameterFile";

internal const string ParameterUriTemplateFileParameterSetName = "ByTemplateFileWithParameterUri";
internal const string ParameterUriTemplateUriParameterSetName = "ByTemplateUriWithParameterUri";
internal const string ParameterUriTemplateSpecParameterSetName = "ByTemplateSpecWithParameterUri";

internal const string ParameterObjectTemplateFileParameterSetName = "ByTemplateFileWithParameterObject";
internal const string ParameterObjectTemplateUriParameterSetName = "ByTemplateUriWithParameterObject";
internal const string ParameterObjectTemplateSpecParameterSetName = "ByTemplateSpecWithParameterObject";

[Parameter(ParameterSetName = ParameterFileTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterUriTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterObjectTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterlessTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack.")]
public string TemplateFile { get; set; }

[Parameter(ParameterSetName = ParameterFileTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterUriTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterObjectTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterlessTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack.")]
public string TemplateUri { get; set; }

[Parameter(ParameterSetName = ParameterFileTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterUriTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterObjectTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack.")]
[Parameter(ParameterSetName = ParameterlessTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack.")]
public string TemplateSpecId { get; set; }

[Parameter(ParameterSetName = ParameterFileTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template.")]
[Parameter(ParameterSetName = ParameterFileTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template.")]
[Parameter(ParameterSetName = ParameterFileTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template.")]
public string TemplateParameterFile { get; set; }

[Parameter(ParameterSetName = ParameterUriTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template.")]
[Parameter(ParameterSetName = ParameterUriTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template.")]
[Parameter(ParameterSetName = ParameterUriTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template.")]
public string TemplateParameterUri { get; set; }

[Parameter(ParameterSetName = ParameterObjectTemplateFileParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents the parameters.")]
[Parameter(ParameterSetName = ParameterObjectTemplateUriParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents the parameters.")]
[Parameter(ParameterSetName = ParameterObjectTemplateSpecParameterSetName,
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents the parameters.")]
public Hashtable TemplateParameterObject { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Skips the PowerShell dynamic parameter processing that checks if the provided template parameter contains all necessary parameters used by the template. " +
"This check would prompt the user to provide a value for the missing parameters, but providing the -SkipTemplateParameterPrompt will ignore this prompt and " +
"error out immediately if a parameter was found not to be bound in the template. For non-interactive scripts, -SkipTemplateParameterPrompt can be provided " +
"to provide a better error message in the case where not all required parameters are satisfied.")]
public SwitchParameter SkipTemplateParameterPrompt { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
{
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using System;
using System.Management.Automation;

[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "ManagementGroupDeploymentStack",
DefaultParameterSetName = ListByManagementGroupIdParameterSetName), OutputType(typeof(PSDeploymentStack))]
[CmdletPreview("The cmdlet is in preview and under development.")]
public class GetAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
{
#region Cmdlet Parameters and Parameter Set Definitions

internal const string GetByResourceIdParameterSetName = "GetByResourceId";
internal const string GetByManagementGroupIdAndNameParameterSetName = "GetByManagementGroupIdAndName";
internal const string ListByManagementGroupIdParameterSetName = "ListByManagmentGroupId";

[Alias("StackName")]
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByManagementGroupIdAndNameParameterSetName,
HelpMessage = "The name of the DeploymentStack to get")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Alias("Id")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSetName,
HelpMessage = "ResourceId of the DeploymentStack to get")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ListByManagementGroupIdParameterSetName,
HelpMessage = "The id of the ManagementGroup where the DeploymentStack is deployed")]
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByManagementGroupIdAndNameParameterSetName,
HelpMessage = "The id of the ManagementGroup where the DeploymentStack is deployed")]
[ValidateNotNullOrEmpty]
public string ManagementGroupId { get; set; }

#endregion

#region Cmdlet Overrides

protected override void OnProcessRecord()
{
try
{
this.GetResourcesClient();
switch (ParameterSetName)
{
case GetByResourceIdParameterSetName:
ManagementGroupId = ResourceIdUtility.GetManagementGroupId(ResourceId);
Name = ResourceIdUtility.GetDeploymentName(ResourceId);
if (ManagementGroupId == null || Name == null)
{
throw new PSArgumentException($"Provided Id '{ResourceId}' is not in correct form. Should be in form " +
"/providers/Microsoft.Management/managementGroups/<managementgroupid>/providers/Microsoft.Resources/deploymentStacks/<stackname>");
}
WriteObject(DeploymentStacksSdkClient.GetManagementGroupDeploymentStack(ManagementGroupId, Name), true);
break;
case GetByManagementGroupIdAndNameParameterSetName:
WriteObject(DeploymentStacksSdkClient.GetManagementGroupDeploymentStack(ManagementGroupId, Name, true));
break;
case ListByManagementGroupIdParameterSetName:
WriteObject(DeploymentStacksSdkClient.ListManagementGroupDeploymentStack(ManagementGroupId), true);
break;
default:
throw new PSInvalidOperationException();
}
}
catch (Exception ex)
{
WriteExceptionError(ex);
}
}

#endregion
}
}
Loading