Skip to content

Commit 06b8c89

Browse files
Remove Accounts update and Certificate cmdlets
1 parent 9f23916 commit 06b8c89

18 files changed

+708
-46
lines changed

src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@
9292
</ItemGroup>
9393
<ItemGroup>
9494
<Compile Include="Properties\AssemblyInfo.cs" />
95+
<Compile Include="UnitTests\GetAzureAutomationCertificateTest.cs" />
9596
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
9697
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
9798
<Compile Include="UnitTests\GetAzureAutomationRunbookDefinitionTest.cs" />
9899
<Compile Include="UnitTests\GetAzureAutomationRunbookTest.cs" />
99100
<Compile Include="UnitTests\GetAzureAutomationScheduledRunbookTest.cs" />
101+
<Compile Include="UnitTests\NewAzureAutomationCertificateTest.cs" />
100102
<Compile Include="UnitTests\NewAzureAutomationRunbookTest.cs" />
101103
<Compile Include="UnitTests\PublishAzureAutomationRunbookTest.cs" />
102104
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Automation.Cmdlet;
18+
using Microsoft.Azure.Commands.Automation.Common;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Moq;
25+
26+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
27+
{
28+
[TestClass]
29+
public class GetAzureAutomationCertificateTest : TestBase
30+
{
31+
private Mock<IAutomationClient> mockAutomationClient;
32+
33+
private MockCommandRuntime mockCommandRuntime;
34+
35+
private GetAzureAutomationCertificate cmdlet;
36+
37+
[TestInitialize]
38+
public void SetupTest()
39+
{
40+
this.mockAutomationClient = new Mock<IAutomationClient>();
41+
this.mockCommandRuntime = new MockCommandRuntime();
42+
this.cmdlet = new GetAzureAutomationCertificate
43+
{
44+
AutomationClient = this.mockAutomationClient.Object,
45+
CommandRuntime = this.mockCommandRuntime
46+
};
47+
}
48+
49+
[TestMethod]
50+
public void GetAzureAutomationCertificateByNameSuccessfull()
51+
{
52+
// Setup
53+
string accountName = "automation";
54+
string certificateName = "certificate";
55+
56+
this.mockAutomationClient.Setup(f => f.GetCertificate(accountName, certificateName));
57+
58+
// Test
59+
this.cmdlet.AutomationAccountName = accountName;
60+
this.cmdlet.Name = certificateName;
61+
this.cmdlet.SetParameterSet("ByCertificateName");
62+
this.cmdlet.ExecuteCmdlet();
63+
64+
// Assert
65+
this.mockAutomationClient.Verify(f => f.GetCertificate(accountName, certificateName), Times.Once());
66+
}
67+
68+
[TestMethod]
69+
public void GetAzureAutomationCertificateByAllSuccessfull()
70+
{
71+
// Setup
72+
string accountName = "automation";
73+
74+
this.mockAutomationClient.Setup(f => f.ListCertificates(accountName)).Returns((string a) => new List<Certificate>());
75+
76+
// Test
77+
this.cmdlet.AutomationAccountName = accountName;
78+
this.cmdlet.ExecuteCmdlet();
79+
80+
// Assert
81+
this.mockAutomationClient.Verify(f => f.ListCertificates(accountName), Times.Once());
82+
}
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.Automation.Cmdlet;
17+
using Microsoft.Azure.Commands.Automation.Common;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using Moq;
23+
using System.Management.Automation;
24+
using System.Security;
25+
using System;
26+
27+
namespace Microsoft.Azure.Commands.Automation.Test.UnitTests
28+
{
29+
[TestClass]
30+
public class NewAzureAutomationCertificateTest : TestBase
31+
{
32+
private Mock<IAutomationClient> mockAutomationClient;
33+
34+
private MockCommandRuntime mockCommandRuntime;
35+
36+
private NewAzureAutomationCertificate cmdlet;
37+
38+
[TestInitialize]
39+
public void SetupTest()
40+
{
41+
this.mockAutomationClient = new Mock<IAutomationClient>();
42+
this.mockCommandRuntime = new MockCommandRuntime();
43+
this.cmdlet = new NewAzureAutomationCertificate
44+
{
45+
AutomationClient = this.mockAutomationClient.Object,
46+
CommandRuntime = this.mockCommandRuntime
47+
};
48+
}
49+
50+
[TestMethod]
51+
public void NewAzureAutomationCertificateByNameSuccessfull()
52+
{
53+
// Setup
54+
string accountName = "automation";
55+
string certificateName = "certificate";
56+
string path = "testCert.pfx";
57+
string password = "password";
58+
string description = "desc";
59+
60+
var secureString = new SecureString();
61+
Array.ForEach(password.ToCharArray(), secureString.AppendChar);
62+
secureString.MakeReadOnly();
63+
64+
this.mockAutomationClient.Setup(
65+
f => f.CreateCertificate(accountName, certificateName, path, secureString, description, false));
66+
67+
this.cmdlet.AutomationAccountName = accountName;
68+
this.cmdlet.Name = certificateName;
69+
this.cmdlet.Description = description;
70+
this.cmdlet.Path = path;
71+
this.cmdlet.Password = secureString;
72+
this.cmdlet.ExecuteCmdlet();
73+
74+
// Assert
75+
this.mockAutomationClient.Verify(f => f.CreateCertificate(accountName, certificateName, path, secureString, description, false), Times.Once());
76+
}
77+
}
78+
}

src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationAccountTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,16 @@ public void RemoveAzureAutomationAccountByNameSuccessfull()
4848
{
4949
// Setup
5050
string accountName = "automation";
51-
string location = "location";
5251

53-
this.mockAutomationClient.Setup(f => f.DeleteAutomationAccount(accountName, location));
52+
this.mockAutomationClient.Setup(f => f.DeleteAutomationAccount(accountName));
5453

5554
// Test
56-
this.cmdlet.Location = location;
5755
this.cmdlet.Name = accountName;
5856
this.cmdlet.Force = true;
5957
this.cmdlet.ExecuteCmdlet();
6058

6159
// Assert
62-
this.mockAutomationClient.Verify(f => f.DeleteAutomationAccount(accountName, location), Times.Once());
60+
this.mockAutomationClient.Verify(f => f.DeleteAutomationAccount(accountName), Times.Once());
6361
}
6462
}
6563
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Model;
20+
using Microsoft.Azure.Commands.Automation.Common;
21+
22+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
23+
{
24+
/// <summary>
25+
/// Gets a certificate for automation.
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.Get, "AzureAutomationCertificate", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
28+
[OutputType(typeof(Certificate))]
29+
public class GetAzureAutomationCertificate : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the certificate name.
33+
/// </summary>
34+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByCertificateName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The certificate name.")]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Execute this cmdlet.
40+
/// </summary>
41+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
42+
protected override void AutomationExecuteCmdlet()
43+
{
44+
IEnumerable<Certificate> ret = null;
45+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByCertificateName)
46+
{
47+
ret = new List<Certificate>
48+
{
49+
this.AutomationClient.GetCertificate(this.AutomationAccountName, this.Name)
50+
};
51+
}
52+
else
53+
{
54+
ret = this.AutomationClient.ListCertificates(this.AutomationAccountName);
55+
}
56+
57+
this.GenerateCmdletOutput(ret);
58+
}
59+
}
60+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
using System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security;
19+
using System.Security.Permissions;
20+
using Microsoft.Azure.Commands.Automation.Model;
21+
using Microsoft.Azure.Commands.Automation.Common;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
24+
{
25+
/// <summary>
26+
/// Create a new Certificate for automation.
27+
/// </summary>
28+
[Cmdlet(VerbsCommon.New, "AzureAutomationCertificate", DefaultParameterSetName = AutomationCmdletParameterSets.ByCertificateName)]
29+
[OutputType(typeof(Certificate))]
30+
public class NewAzureAutomationCertificate : AzureAutomationBaseCmdlet
31+
{
32+
/// <summary>
33+
/// Gets or sets the certificate name.
34+
/// </summary>
35+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByCertificateName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "The certificate name.")]
37+
[ValidateNotNullOrEmpty]
38+
public string Name { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the certificate description.
42+
/// </summary>
43+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByCertificateName, ValueFromPipelineByPropertyName = true,
44+
HelpMessage = "The certificate description.")]
45+
public string Description { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the certificate password.
49+
/// </summary>
50+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByCertificateName, ValueFromPipelineByPropertyName = true,
51+
HelpMessage = "The certificate password.")]
52+
public SecureString Password { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the certificate path.
56+
/// </summary>
57+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByCertificateName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true,
58+
HelpMessage = "The certificate file path.")]
59+
public string Path { get; set; }
60+
61+
/// <summary>
62+
/// Gets or sets the certificate exportable Property.
63+
/// </summary>
64+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The exportable property of the variable.")]
65+
public SwitchParameter Exportable { get; set; }
66+
67+
/// <summary>
68+
/// Execute this cmdlet.
69+
/// </summary>
70+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
71+
protected override void AutomationExecuteCmdlet()
72+
{
73+
74+
var createdCertificate = this.AutomationClient.CreateCertificate(this.AutomationAccountName, this.Name, this.Path, this.Password, this.Description, this.Exportable.IsPresent);
75+
76+
this.WriteObject(createdCertificate);
77+
}
78+
}
79+
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class NewAzureAutomationRunbook : AzureAutomationBaseCmdlet
5555
/// Gets or sets the runbook tags.
5656
/// </summary>
5757
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook tags.")]
58+
[Alias("Tag")]
5859
public IDictionary<string, string> Tags { get; set; }
5960

6061
/// <summary>

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationAccount.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ public IAutomationClient AutomationClient
5959
[ValidateNotNullOrEmpty]
6060
public string Name { get; set; }
6161

62-
/// <summary>
63-
/// Gets or sets the location.
64-
/// </summary>
65-
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The geo region of the automation account")]
66-
public string Location { get; set; }
67-
6862
/// <summary>
6963
/// Gets or sets the switch parameter not to confirm on removing the automaiton account.
7064
/// </summary>
@@ -82,10 +76,7 @@ public override void ExecuteCmdlet()
8276
string.Format(CultureInfo.CurrentCulture, Resources.RemovingAzureAutomationResourceWarning),
8377
string.Format(CultureInfo.CurrentCulture, Resources.RemoveAzureAutomationResourceDescription),
8478
this.Name,
85-
() =>
86-
{
87-
AutomationClient.DeleteAutomationAccount(this.Name, this.Location);
88-
});
79+
() => AutomationClient.DeleteAutomationAccount(this.Name));
8980
}
9081
}
9182
}

0 commit comments

Comments
 (0)