Skip to content

Commit ea8e8b3

Browse files
committed
stacks initial commit
1 parent 388e6a3 commit ea8e8b3

File tree

8 files changed

+362
-3
lines changed

8 files changed

+362
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
2+
using Microsoft.Azure.Commands.ResourceManager.Common;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
8+
{
9+
public class DeploymentStacksCmdletBase : AzureRMCmdlet
10+
{
11+
/// <summary>
12+
/// Deployment stacks client instance field
13+
/// </summary>
14+
private DeploymentStacksSdkClient deploymentStacksSdkClient;
15+
16+
/// <summary>
17+
/// Gets or sets the deployment stacks sdk client
18+
/// </summary>
19+
public DeploymentStacksSdkClient DeploymentStacksSdkClient
20+
{
21+
get
22+
{
23+
if (this.deploymentStacksSdkClient == null)
24+
{
25+
this.deploymentStacksSdkClient = new DeploymentStacksSdkClient(DefaultContext);
26+
}
27+
return this.deploymentStacksSdkClient;
28+
}
29+
30+
set
31+
{
32+
this.deploymentStacksSdkClient = value;
33+
}
34+
}
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.DeploymentStacks
16+
{
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Management.Automation;
20+
using System.Text;
21+
22+
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
23+
DefaultParameterSetName = GetAzDeploymentStack.ListDeploymentStack), OutputType(typeof(PSDeploymentStack))]
24+
public class GetAzDeploymentStack : DeploymentStacksCmdletBase
25+
{
26+
#region Cmdlet Parameters and Parameter Set Definitions
27+
28+
internal const string ListDeploymentStack = "ListDeploymentStack";
29+
30+
31+
#endregion
32+
33+
}
34+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2+
{
3+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Management.Automation;
7+
using System.Text;
8+
9+
[Cmdlet("New", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
10+
SupportsShouldProcess = true, DefaultParameterSetName = NewAzDeploymentStack.ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSDeploymentStack))]
11+
public class NewAzDeploymentStack : DeploymentStacksCmdletBase
12+
{
13+
14+
#region Cmdlet Parameters and Parameter Set Definitions
15+
16+
internal const string ParameterlessTemplateFileParameterSetName = "ByTemplateFileWithNoParameters";
17+
internal const string ParameterlessTemplateUriParameterSetName = "ByTemplateUriWithNoParameters";
18+
internal const string ParameterlessTemplateSpecParameterSetName = "ByTemplateSpecWithNoParameters";
19+
20+
internal const string ParameterFileTemplateFileParameterSetName = "ByTemplateFileWithParameterFile";
21+
internal const string ParameterFileTemplateUriParameterSetName = "ByTemplateUriWithParameterFile";
22+
internal const string ParameterFileTemplateSpecParameterSetName = "ByTemplateSpecWithParameterFile";
23+
24+
internal const string ParameterUriTemplateFileParameterSetName = "ByTemplateFileWithParameterUri";
25+
internal const string ParameterUriTemplateUriParameterSetName = "ByTemplateUriWithParameterUri";
26+
internal const string ParameterUriTemplateSpecParameterSetName = "ByTemplateSpecWithParameterUri";
27+
28+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
29+
HelpMessage = "The name of the deploymentStack to create")]
30+
[ValidateNotNullOrEmpty]
31+
public string Name { get; set; }
32+
33+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
34+
HelpMessage = "The name of the ResourceGroup to be used")]
35+
[ResourceGroupCompleter]
36+
[ValidateNotNullOrEmpty]
37+
public string ResourceGroupName { get; set; }
38+
39+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateFileParameterSetName,
40+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
41+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateFileParameterSetName,
42+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
43+
[Parameter(Position = 2, ParameterSetName = ParameterlessTemplateFileParameterSetName,
44+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "TemplateFile to be used to create the stack")]
45+
public string TemplateFile { get; set; }
46+
47+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateUriParameterSetName,
48+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
49+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateUriParameterSetName,
50+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
51+
[Parameter(Position = 2, ParameterSetName = ParameterlessTemplateUriParameterSetName,
52+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Template to be used to create the stack")]
53+
public string TemplateUri { get; set; }
54+
55+
[Parameter(Position = 2, ParameterSetName = ParameterFileTemplateSpecParameterSetName,
56+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
57+
[Parameter(Position = 2, ParameterSetName = ParameterUriTemplateSpecParameterSetName,
58+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
59+
[Parameter(Position = 2, ParameterSetName = ParameterlessTemplateSpecParameterSetName,
60+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "ResourceId of the TemplateSpec to be used to create the stack")]
61+
public string TemplateSpec { get; set; }
62+
63+
[Parameter(Position = 3, ParameterSetName = ParameterFileTemplateFileParameterSetName,
64+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
65+
[Parameter(Position = 3, ParameterSetName = ParameterFileTemplateUriParameterSetName,
66+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
67+
[Parameter(Position = 3, ParameterSetName = ParameterFileTemplateSpecParameterSetName,
68+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Parameter file to use for the template")]
69+
public string ParameterFile { get; set; }
70+
71+
[Parameter(Position = 3, ParameterSetName = ParameterUriTemplateFileParameterSetName,
72+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
73+
[Parameter(Position = 3, ParameterSetName = ParameterUriTemplateUriParameterSetName,
74+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
75+
[Parameter(Position = 3, ParameterSetName = ParameterUriTemplateSpecParameterSetName,
76+
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Location of the Parameter file to use for the template")]
77+
public string ParameterUri { get; set; }
78+
79+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
80+
HelpMessage = "Description for the stack")]
81+
public string Description { get; set; }
82+
83+
#endregion
84+
85+
#region Cmdlet Overrides
86+
87+
public override void ExecuteCmdlet()
88+
{
89+
try
90+
{
91+
switch (ParameterSetName)
92+
{
93+
default:
94+
throw new PSNotSupportedException();
95+
}
96+
}
97+
catch
98+
{
99+
100+
}
101+
}
102+
103+
#endregion
104+
105+
}
106+
}

src/Resources/ResourceManager/ResourceManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="AutoMapper" Version="6.2.2" />
16-
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.13.1-preview" />
16+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
1717
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
1818
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
1919
</ItemGroup>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using Microsoft.Azure.Commands.Common.Authentication;
6+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
7+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
8+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
9+
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
10+
using Microsoft.WindowsAzure.Commands.Common;
11+
using Microsoft.Azure.Management.ResourceManager;
12+
using Microsoft.Azure.Management.ResourceManager.Models;
13+
using Newtonsoft.Json.Linq;
14+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
15+
16+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
17+
{
18+
public class DeploymentStacksSdkClient
19+
{
20+
public IDeploymentStacksClient DeploymentStacksClient { get; set; }
21+
22+
private IAzureContext azureContext;
23+
24+
public DeploymentStacksSdkClient(IDeploymentStacksClient deploymentStacksClient)
25+
{
26+
this.DeploymentStacksClient = deploymentStacksClient;
27+
}
28+
29+
// <summary>
30+
/// Parameter-less constructor for mocking
31+
/// </summary>
32+
public DeploymentStacksSdkClient()
33+
{
34+
}
35+
36+
public DeploymentStacksSdkClient(IAzureContext context)
37+
: this(
38+
AzureSession.Instance.ClientFactory.CreateArmClient<DeploymentStacksClient>(context,
39+
AzureEnvironment.Endpoint.ResourceManager))
40+
{
41+
this.azureContext = context;
42+
}
43+
44+
public PSDeploymentStack GetDeploymentStack(string subscriptionName,
45+
string resourceGroupName,
46+
string deploymentStackName = null)
47+
{
48+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.GetAtResourceGroup(subscriptionName, resourceGroupName, deploymentStackName);
49+
50+
return new PSDeploymentStack(deploymentStack);
51+
}
52+
53+
public PSDeploymentStack ResourceGroupCreateOrUpdateDeploymentStack(
54+
string deploymentStackName,
55+
string resourceGroupName,
56+
string templateUri,
57+
string templateSpec,
58+
string parameterUri,
59+
Hashtable parameters,
60+
string description
61+
)
62+
{
63+
var deploymentStackModel = new DeploymentStack
64+
{
65+
Description = description
66+
};
67+
68+
DeploymentStacksTemplateLink templateLink = new DeploymentStacksTemplateLink();
69+
if(templateSpec != null)
70+
{
71+
templateLink.Id = templateSpec;
72+
deploymentStackModel.TemplateLink = templateLink;
73+
}
74+
else if(Uri.IsWellFormedUriString(templateUri, UriKind.Absolute))
75+
{
76+
templateLink.Uri = templateUri;
77+
deploymentStackModel.TemplateLink = templateLink;
78+
}
79+
else
80+
{
81+
deploymentStackModel.Template = JObject.Parse(FileUtilities.DataStore.ReadFileAsText(templateUri));
82+
}
83+
84+
if(Uri.IsWellFormedUriString(parameterUri, UriKind.Absolute))
85+
{
86+
DeploymentStacksParametersLink parametersLink = new DeploymentStacksParametersLink();
87+
parametersLink.Uri = parameterUri;
88+
deploymentStackModel.ParametersLink = parametersLink;
89+
}
90+
91+
else if(parameters != null)
92+
{
93+
Dictionary<string, object> parametersDictionary = parameters?.ToDictionary(false);
94+
string parametersContent = parametersDictionary != null
95+
? PSJsonSerializer.Serialize(parametersDictionary)
96+
: null;
97+
deploymentStackModel.Parameters = !string.IsNullOrEmpty(parametersContent)
98+
? JObject.Parse(parametersContent)
99+
: null;
100+
}
101+
102+
var deploymentStack = DeploymentStacksClient.DeploymentStacks.BeginCreateOrUpdateAtResourceGroup("subId", resourceGroupName, deploymentStackName, deploymentStackModel);
103+
return new PSDeploymentStack(deploymentStack);
104+
}
105+
}
106+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.Azure.Management.ResourceManager.Models;
2+
using Microsoft.Rest;
3+
using Microsoft.Rest.Serialization;
4+
using Newtonsoft.Json;
5+
using System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
10+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets
11+
{
12+
public class PSDeploymentStack
13+
{
14+
public string updateBehavior { get; set; }
15+
16+
public string id { get; set; }
17+
18+
public string name { get; set; }
19+
20+
public string type { get; set; }
21+
22+
public DateTime? creationTime { get; set; }
23+
24+
public string location { get; set; }
25+
26+
public object template { get; set; }
27+
28+
public DeploymentStacksTemplateLink templateLink { get; set; }
29+
30+
public object parameters { get; set; }
31+
32+
public DeploymentStacksParametersLink parametersLink { get; set; }
33+
34+
public DeploymentStacksDebugSetting debugSetting { get; set; }
35+
36+
public string provisioningState { get; set; }
37+
38+
public string deploymentScope { get; set; }
39+
40+
public string description { get; set; }
41+
42+
public IList<ResourceReference> managedResources { get; set; }
43+
44+
public string deploymentId { get; set; }
45+
46+
public LockSettings locks { get; set; }
47+
48+
public ErrorResponse error { get; set; }
49+
50+
public string snapshotId { get; set; }
51+
52+
public PSDeploymentStack() { }
53+
54+
internal PSDeploymentStack(DeploymentStack deploymentStack)
55+
{
56+
this.id = deploymentStack.Id;
57+
this.name = deploymentStack.Name;
58+
this.type = deploymentStack.Type;
59+
this.creationTime = deploymentStack.SystemData.CreatedAt;
60+
this.location = deploymentStack.Location;
61+
this.template = deploymentStack.Template;
62+
this.templateLink = deploymentStack.TemplateLink;
63+
this.parameters = deploymentStack.Parameters;
64+
this.parametersLink = deploymentStack.ParametersLink;
65+
this.debugSetting = deploymentStack.DebugSetting;
66+
this.provisioningState = deploymentStack.ProvisioningState;
67+
this.deploymentScope = deploymentStack.DeploymentScope;
68+
this.description = deploymentStack.DeploymentScope;
69+
this.managedResources = deploymentStack.ManagedResources;
70+
this.deploymentId = deploymentStack.DeploymentId;
71+
this.locks = deploymentStack.Locks;
72+
this.error = deploymentStack.Error;
73+
this.snapshotId = deploymentStack.SnapshotId;
74+
}
75+
76+
}
77+
}

src/Resources/Resources.Test/Resources.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<PackageReference Update="Microsoft.Azure.Management.ResourceManager" Version="3.13.1-preview" />
35+
<PackageReference Update="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
3636
</ItemGroup>
3737
<ItemGroup>
3838
<PackageReference Include="FluentAssertions" Version="5.9.0" />

src/Resources/Resources/Resources.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.8.0-preview" />
1515
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.12.0-preview" />
1616
<PackageReference Include="Microsoft.Azure.Management.ManagementGroups" Version="1.1.1-preview" />
17-
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.13.1-preview" />
17+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.14.0-stacks" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)