diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj b/src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj index 8d1089b05e0a..4b0fcf267acd 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj @@ -92,10 +92,20 @@ + + + + + + + + + + diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs new file mode 100644 index 000000000000..03d1c06011cb --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs @@ -0,0 +1,82 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class GetAzureAutomationCredentialTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private GetAzureAutomationCredential cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new GetAzureAutomationCredential + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void GetAzureAutomationCredentialByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string credentialName = "credential"; + + this.mockAutomationClient.Setup(f => f.GetCredential(accountName, credentialName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = credentialName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.GetCredential(accountName, credentialName), Times.Once()); + } + + [TestMethod] + public void GetAzureAutomationCredentialByAllSuccessfull() + { + // Setup + string accountName = "automation"; + + this.mockAutomationClient.Setup(f => f.ListCredentials(accountName)).Returns((string a) => new List()); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.ListCredentials(accountName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs new file mode 100644 index 000000000000..47133a6aa2e9 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs @@ -0,0 +1,82 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class GetAzureAutomationModuleTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private GetAzureAutomationModule cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new GetAzureAutomationModule + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void GetAzureAutomationModuleByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string moduleName = "module"; + + this.mockAutomationClient.Setup(f => f.GetModule(accountName, moduleName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = moduleName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.GetModule(accountName, moduleName), Times.Once()); + } + + [TestMethod] + public void GetAzureAutomationModuleByAllSuccessfull() + { + // Setup + string accountName = "automation"; + + this.mockAutomationClient.Setup(f => f.ListModules(accountName)).Returns((string a) => new List()); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.ListModules(accountName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs new file mode 100644 index 000000000000..59c3566927c5 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs @@ -0,0 +1,82 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class GetAzureAutomationVariableTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private GetAzureAutomationVariable cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new GetAzureAutomationVariable + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void GetAzureAutomationVariableByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string variableName = "variable"; + + this.mockAutomationClient.Setup(f => f.GetVariable(accountName, variableName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = variableName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.GetVariable(accountName, variableName), Times.Once()); + } + + [TestMethod] + public void GetAzureAutomationVariableByAllSuccessfull() + { + // Setup + string accountName = "automation"; + + this.mockAutomationClient.Setup(f => f.ListVariables(accountName)).Returns((string a) => new List()); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.ListVariables(accountName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationCredentialTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationCredentialTest.cs new file mode 100644 index 000000000000..b36ba048387a --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationCredentialTest.cs @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Moq; +using System.Management.Automation; +using System.Security; +using System; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class NewAzureAutomationCredentialTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private NewAzureAutomationCredential cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new NewAzureAutomationCredential + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void NewAzureAutomationCredentialByPathSuccessfull() + { + // Setup + string accountName = "automation"; + string credentialName = "credential"; + string username = "testUser"; + string password = "password"; + string description = "desc"; + + var secureString = new SecureString(); + Array.ForEach(password.ToCharArray(), secureString.AppendChar); + secureString.MakeReadOnly(); + + var value = new PSCredential(username, secureString); + + this.mockAutomationClient.Setup( + f => f.CreateCredential(accountName, credentialName, username, password, description)); + + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = credentialName; + this.cmdlet.Description = description; + this.cmdlet.Value = value; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.CreateCredential(accountName, credentialName, username, password, description), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationModuleTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationModuleTest.cs new file mode 100644 index 000000000000..86b9e7257e67 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationModuleTest.cs @@ -0,0 +1,73 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Moq; +using System.Management.Automation; +using System.Security; +using System; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class NewAzureAutomationModuleTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private NewAzureAutomationModule cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new NewAzureAutomationModule + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void NewAzureAutomationModuleSuccessfull() + { + // Setup + string accountName = "automation"; + string moduleName = "credential"; + Uri contentLink = new Uri("http://www.example.com"); + var tags = new Dictionary(); + tags.Add("tag1", "tags2"); + + this.mockAutomationClient.Setup( + f => f.CreateModule(accountName, contentLink, moduleName, tags)); + + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = moduleName; + this.cmdlet.ContentLink = contentLink; + this.cmdlet.Tags = tags; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.CreateModule(accountName, contentLink, moduleName, tags), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationVariableTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationVariableTest.cs new file mode 100644 index 000000000000..b2bc93ddcafc --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationVariableTest.cs @@ -0,0 +1,80 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Moq; +using System.Management.Automation; +using System.Security; +using System; +using Microsoft.Azure.Commands.Automation.Model; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class NewAzureAutomationVariableTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private NewAzureAutomationVariable cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new NewAzureAutomationVariable + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void NewAzureAutomationVariableByPathSuccessfull() + { + // Setup + string accountName = "automation"; + string variableName = "variable"; + string value = "value"; + string description = "desc"; + + var variable = new Variable(); + variable.Name = variableName; + variable.Value = value; + variable.Description = description; + variable.Encrypted = true; + + this.mockAutomationClient.Setup( + f => f.CreateVariable(accountName, variable)); + + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = variableName; + this.cmdlet.Description = description; + this.cmdlet.Value = value; + this.cmdlet.Encrypted = true; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.CreateVariable(accountName, variable), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationCredentialTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationCredentialTest.cs new file mode 100644 index 000000000000..e49226437030 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationCredentialTest.cs @@ -0,0 +1,65 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class RemoveAzureAutomationCredentialTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private RemoveAzureAutomationCredential cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new RemoveAzureAutomationCredential + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void RemoveAzureAutomationCredentialByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string credentialName = "credential"; + + this.mockAutomationClient.Setup(f => f.DeleteCredential(accountName, credentialName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = credentialName; + this.cmdlet.Force = true; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.DeleteCredential(accountName, credentialName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationModuleTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationModuleTest.cs new file mode 100644 index 000000000000..3c5e593edb73 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationModuleTest.cs @@ -0,0 +1,65 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class RemoveAzureAutomationModuleTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private RemoveAzureAutomationModule cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new RemoveAzureAutomationModule + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void RemoveAzureAutomationModuleByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string moduleName = "module"; + + this.mockAutomationClient.Setup(f => f.DeleteModule(accountName, moduleName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = moduleName; + this.cmdlet.Force = true; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.DeleteModule(accountName, moduleName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationVariableTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationVariableTest.cs new file mode 100644 index 000000000000..89f4ea97f004 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationVariableTest.cs @@ -0,0 +1,65 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class RemoveAzureAutomationVariableTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private RemoveAzureAutomationVariable cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new RemoveAzureAutomationVariable + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void RemoveAzureAutomationVariableByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string variableName = "variable"; + + this.mockAutomationClient.Setup(f => f.DeleteVariable(accountName, variableName)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = variableName; + this.cmdlet.Force = true; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.DeleteVariable(accountName, variableName), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationCredentialTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationCredentialTest.cs new file mode 100644 index 000000000000..f07136bd71a0 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationCredentialTest.cs @@ -0,0 +1,96 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using Microsoft.Azure.Commands.Automation.Cmdlet; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Moq; +using System.Security; +using System.Management.Automation; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class SetAzureAutomationCredentialTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private SetAzureAutomationCredential cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new SetAzureAutomationCredential + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void SetAzureAutomationCredentialByNameSuccessfull() + { + // Setup + string accountName = "automation"; + string credentialName = "credential"; + + this.mockAutomationClient.Setup(f => f.UpdateCredential(accountName, credentialName, null, null, null)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = credentialName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.UpdateCredential(accountName, credentialName, null, null, null), Times.Once()); + } + + [TestMethod] + public void SetAzureAutomationCredentialByNameWithParametersSuccessfull() + { + // Setup + string accountName = "automation"; + string credentialName = "credential"; + string username = "testUser"; + string password = "password"; + string description = "desc"; + + var secureString = new SecureString(); + Array.ForEach(password.ToCharArray(), secureString.AppendChar); + secureString.MakeReadOnly(); + + var value = new PSCredential(username, secureString); + + this.mockAutomationClient.Setup(f => f.UpdateCredential(accountName, credentialName, username, password, description)); + + // Test + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = credentialName; + this.cmdlet.Description = description; + this.cmdlet.Value = value; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.UpdateCredential(accountName, credentialName, username, password, description), Times.Once()); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs index e822cd734119..771106716384 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs @@ -93,6 +93,22 @@ public override void ExecuteCmdlet() } } + protected bool GenerateCmdletOutput(object result) + { + var ret = true; + + try + { + WriteObject(result); + } + catch (PipelineStoppedException) + { + ret = false; + } + + return ret; + } + protected bool GenerateCmdletOutput(IEnumerable results) { var ret = true; diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs new file mode 100644 index 000000000000..3120bb960664 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Credential for automation. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationCredential", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(PSCredential))] + public class GetAzureAutomationCredential : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the credential name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The credential name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable ret = null; + if (!string.IsNullOrEmpty(this.Name)) + { + ret = new List + { + this.AutomationClient.GetCredential(this.AutomationAccountName, this.Name) + }; + } + else + { + ret = this.AutomationClient.ListCredentials(this.AutomationAccountName); + } + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs new file mode 100644 index 000000000000..998e472e7a86 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs @@ -0,0 +1,85 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Credential for automation. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(Microsoft.Azure.Commands.Automation.Model.Job))] + public class GetAzureAutomationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByJobId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The job id.")] + [Alias("JobId")] + public Guid? Id { get; set; } + + /// + /// Gets or sets the runbook name of the job. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, HelpMessage = "The runbook name of the job.")] + public string RunbookName { get; set; } + + /// + /// Gets or sets the start time filter. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = false, HelpMessage = "Filter jobs so that job start time >= StartTime.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job start time >= StartTime.")] + public DateTime? StartTime { get; set; } + + /// + /// Gets or sets the end time filter. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = false, HelpMessage = "Filter jobs so that job end time <= EndTime.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job end time <= EndTime.")] + public DateTime? EndTime { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable jobs; + + if (this.Id.HasValue) + { + // ByJobId + jobs = new List { this.AutomationClient.GetJob(this.AutomationAccountName, this.Id.Value) }; + } + else if (this.RunbookName != null) + { + // ByRunbookName + jobs = this.AutomationClient.ListJobsByRunbookName(this.AutomationAccountName, this.RunbookName, this.StartTime, this.EndTime); + } + else + { + // ByAll + jobs = this.AutomationClient.ListJobs(this.AutomationAccountName, this.StartTime, this.EndTime); + } + + this.WriteObject(jobs, true); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs new file mode 100644 index 000000000000..4ff5f8d4d1bb --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs @@ -0,0 +1,53 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets azure automation variables for a given account. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationJobOutput")] + [OutputType(typeof(Variable))] + public class GetAzureAutomationJobOutput : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id + /// + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The job id")] + public Guid Id { get; set; } + + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type")] + public string Stream { get; set; } + + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The start time filter for job output")] + public DateTime? StartTime { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + var ret = this.AutomationClient.GetJobStream(this.AutomationAccountName, this.Id, this.StartTime, this.Stream ); + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs new file mode 100644 index 000000000000..8f1fcc65806c --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Module for automation. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationModule", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(Module))] + public class GetAzureAutomationModule : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the module name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The module name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable ret = null; + if (!string.IsNullOrEmpty(this.Name)) + { + ret = new List + { + this.AutomationClient.GetModule(this.AutomationAccountName, this.Name) + }; + } + else + { + ret = this.AutomationClient.ListModules(this.AutomationAccountName); + } + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs new file mode 100644 index 000000000000..a20d9d05ff86 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets azure automation variables for a given account. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationVariable", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(Variable))] + public class GetAzureAutomationVariable : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the variable name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable ret = null; + if (this.ParameterSetName == AutomationCmdletParameterSets.ByName) + { + ret = new List + { + this.AutomationClient.GetVariable(this.AutomationAccountName, this.Name) + }; + } + else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) + { + ret = this.AutomationClient.ListVariables(this.AutomationAccountName); + } + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationCredential.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationCredential.cs new file mode 100644 index 000000000000..aa1b504abb29 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationCredential.cs @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Create a new Credential for automation. + /// + [Cmdlet(VerbsCommon.New, "AzureAutomationCredential", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + [OutputType(typeof(PSCredential))] + public class NewAzureAutomationCredential : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the credential name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the credential name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential description.")] + public string Description { get; set; } + + /// + /// Gets or sets the credential UserName. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential value.")] + public PSCredential Value { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + string userName = null, password = null; + + if (Value != null) + { + userName = Value.UserName; + password = Value.GetNetworkCredential().Password; + } + + var createdCredential = this.AutomationClient.CreateCredential(this.AutomationAccountName, Name, userName, password, Description); + + this.WriteObject(createdCredential); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationModule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationModule.cs new file mode 100644 index 000000000000..2106d5d7be43 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationModule.cs @@ -0,0 +1,63 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Create a new Module for automation. + /// + [Cmdlet(VerbsCommon.New, "AzureAutomationModule")] + [OutputType(typeof(Module))] + public class NewAzureAutomationModule : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the module name. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, + HelpMessage = "The module name.")] + public string Name { get; set; } + + /// + /// Gets or sets the contentLink + /// + [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The ContentLink.")] + [ValidateNotNullOrEmpty] + public Uri ContentLink { get; set; } + + /// + /// Gets or sets the module tags. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The module tags.")] + public IDictionary Tags { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + var createdModule = this.AutomationClient.CreateModule(this.AutomationAccountName, ContentLink, Name, Tags); + + this.WriteObject(createdModule); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationVariable.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationVariable.cs new file mode 100644 index 000000000000..4a5aa1478e20 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/NewAzureAutomationVariable.cs @@ -0,0 +1,76 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets azure automation variables for a given account. + /// + [Cmdlet(VerbsCommon.New, "AzureAutomationVariable")] + [OutputType(typeof(Variable))] + public class NewAzureAutomationVariable : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the variable name. + /// + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the variable IsEncrypted Property. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The IsEncrypted property of the variable.")] + [ValidateNotNull] + public SwitchParameter Encrypted { get; set; } + + /// + /// Gets or sets the variable description. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the variable.")] + public string Description { get; set; } + + /// + /// Gets or sets the variable value. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The value of the variable.")] + public string Value { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + Variable variable = new Variable() + { + Name = this.Name, + Encrypted = this.Encrypted.IsPresent, + Description = this.Description, + Value = this.Value + }; + + var ret = this.AutomationClient.CreateVariable(this.AutomationAccountName, variable); + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationCredential.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationCredential.cs new file mode 100644 index 000000000000..ffa1d671123a --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationCredential.cs @@ -0,0 +1,58 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Removes a Credential for automation. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationCredential", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + public class RemoveAzureAutomationCredential : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the credential name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The credential name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, HelpMessage = "Confirm the removal of the credential")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + ConfirmAction( + Force.IsPresent, + string.Format(Resources.RemovingAzureAutomationResourceWarning, "Credential"), + string.Format(Resources.RemoveAzureAutomationResourceDescription, "Credential"), + Name, + () => + { + this.AutomationClient.DeleteCredential(this.AutomationAccountName, Name); + }); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationModule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationModule.cs new file mode 100644 index 000000000000..065184aee55e --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationModule.cs @@ -0,0 +1,58 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Remove a Module for automation. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationModule", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + public class RemoveAzureAutomationModule : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the module name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The module name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, HelpMessage = "Confirm the removal of the module")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + ConfirmAction( + Force.IsPresent, + string.Format(Resources.RemovingAzureAutomationResourceWarning, "Module"), + string.Format(Resources.RemoveAzureAutomationResourceDescription, "Module"), + Name, + () => + { + this.AutomationClient.DeleteModule(this.AutomationAccountName, Name); + }); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationVariable.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationVariable.cs new file mode 100644 index 000000000000..57b67d68777d --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationVariable.cs @@ -0,0 +1,59 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Properties; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets azure automation variables for a given account. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationVariable")] + [OutputType(typeof(Variable))] + public class RemoveAzureAutomationVariable : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the variable name. + /// + [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(Position = 2, HelpMessage = "Confirm the removal of the variable")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + ConfirmAction( + Force.IsPresent, + string.Format(Resources.RemovingAzureAutomationResourceWarning, "Module"), + string.Format(Resources.RemoveAzureAutomationResourceDescription, "Module"), + Name, + () => + { + this.AutomationClient.DeleteVariable(this.AutomationAccountName, this.Name); + }); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/ResumeAzureAutomationJob.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/ResumeAzureAutomationJob.cs new file mode 100644 index 000000000000..4ec36ac8045a --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/ResumeAzureAutomationJob.cs @@ -0,0 +1,47 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Credential for automation. + /// + [Cmdlet(VerbsLifecycle.Resume, "AzureAutomationJob")] + public class ResumeAzureAutomationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The job id.")] + [Alias("JobId")] + public Guid Id { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + this.AutomationClient.ResumeJob(this.AutomationAccountName, this.Id); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationCredential.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationCredential.cs new file mode 100644 index 000000000000..3e992034e93c --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationCredential.cs @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Sets a Credential for automation. + /// + [Cmdlet(VerbsCommon.Set, "AzureAutomationCredential", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + [OutputType(typeof(PSCredential))] + public class SetAzureAutomationCredential : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the credential name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the credential description. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential description.")] + public string Description { get; set; } + + /// + /// Gets or sets the credential Value. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The credential value.")] + public PSCredential Value { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + string userName = null, password = null; + + if(Value != null) + { + userName = Value.UserName; + password = Value.GetNetworkCredential().Password; + } + + var updatedCredential = this.AutomationClient.UpdateCredential(this.AutomationAccountName, Name, userName, password, Description); + + this.WriteObject(updatedCredential); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationModule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationModule.cs new file mode 100644 index 000000000000..b92445d7d9bf --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationModule.cs @@ -0,0 +1,64 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Sets a Module for automation. + /// + [Cmdlet(VerbsCommon.Set, "AzureAutomationModule", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + [OutputType(typeof(Module))] + public class SetAzureAutomationModule : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the module name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, + HelpMessage = "The module name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the module tags. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The module tags.")] + [ValidateNotNullOrEmpty] + public IDictionary Tags { get; set; } + + /// + /// Gets or sets the contentLink + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, + HelpMessage = "The ContentLink.")] + public Uri ContentLink { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + var updatedModule = this.AutomationClient.UpdateModule(this.AutomationAccountName, Tags, Name, ContentLink); + + this.WriteObject(updatedModule); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationVariable.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationVariable.cs new file mode 100644 index 000000000000..637ce5937de2 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAzureAutomationVariable.cs @@ -0,0 +1,68 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets azure automation variables for a given account. + /// + [Cmdlet(VerbsCommon.Set, "AzureAutomationVariable")] + [OutputType(typeof(Variable))] + public class SetAzureAutomationVariable : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the variable name. + /// + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The variable name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the variable description. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the variable.")] + public string Description { get; set; } + + /// + /// Gets or sets the variable value. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The value of the variable.")] + public string Value { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + Variable variable = new Variable() + { + Name = this.Name, + Description = this.Description, + Value = this.Value + }; + + var ret = this.AutomationClient.UpdateVariable(this.AutomationAccountName, variable); + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/StopAzureAutomationJob.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/StopAzureAutomationJob.cs new file mode 100644 index 000000000000..9dfff694a25e --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/StopAzureAutomationJob.cs @@ -0,0 +1,47 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Credential for automation. + /// + [Cmdlet(VerbsLifecycle.Stop, "AzureAutomationJob")] + public class StopAzureAutomationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The job id.")] + [Alias("JobId")] + public Guid Id { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + this.AutomationClient.StopJob(this.AutomationAccountName, this.Id); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SuspendAzureAutomationJob.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SuspendAzureAutomationJob.cs new file mode 100644 index 000000000000..2bc84f706217 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SuspendAzureAutomationJob.cs @@ -0,0 +1,47 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets a Credential for automation. + /// + [Cmdlet(VerbsLifecycle.Suspend, "AzureAutomationJob")] + public class SuspendAzureAutomationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The job id.")] + [Alias("JobId")] + public Guid Id { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + this.AutomationClient.SuspendJob(this.AutomationAccountName, this.Id); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj index 7801bc338453..609373155e63 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj +++ b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj @@ -100,13 +100,31 @@ - + + + + + + + + + + + + + + + + + + + @@ -115,9 +133,14 @@ + + + + + True @@ -143,8 +166,8 @@ ResXFileCodeGenerator - Resources.Designer.cs Designer + Resources.Designer.cs diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs index db4a8dd7517b..8ccc9e76bd78 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs @@ -110,8 +110,8 @@ public IEnumerable ListSchedules(string automationAccountName) IList scheduleModels = AutomationManagementClient.ContinuationTokenHandler( skipToken => { - var response = this.automationManagementClient.Schedules.List( - automationAccountName, skipToken); + var response = this.automationManagementClient.Schedules.List(automationAccountName, skipToken); + return new ResponseWithSkipToken( response, response.Schedules); }); @@ -140,6 +140,196 @@ public Runbook GetRunbook(string automationAccountName, string name) return new Runbook(sdkRunbook); } + public IEnumerable GetJobStream(string automationAccountName, Guid jobId, DateTime? time, string streamType) + { + var listParams = new AutomationManagement.Models.JobStreamListParameters(); + + if (time.HasValue) + { + listParams.Time = time.Value.ToUniversalTime().ToString(); + } + + if (streamType != null) + { + listParams.StreamType = streamType; + } + + var jobStreams = this.automationManagementClient.JobStreams.List(automationAccountName, jobId, listParams).JobStreams; + + return jobStreams.Select(this.CreateJobStreamFromJobStreamModel); + } + + public Variable CreateVariable(string automationAccountName, Variable variable) + { + bool variableExists = true; + + try + { + this.GetVariable(automationAccountName, variable.Name); + } + catch (ResourceNotFoundException) + { + variableExists = false; + } + + if (variableExists) + { + throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture, Resources.VariableAlreadyExists, variable.Name)); + } + + if (variable.Encrypted) + { + var createParams = new AutomationManagement.Models.EncryptedVariableCreateParameters() + { + Name = variable.Name, + Properties = new AutomationManagement.Models.EncryptedVariableCreateProperties() + { + Value = variable.Value, + Description = variable.Description + } + }; + + var sdkCreatedVariable = this.automationManagementClient.EncryptedVariables.Create(automationAccountName, createParams).EncryptedVariable; + + return new Variable(sdkCreatedVariable, automationAccountName); + } + else + { + var createParams = new AutomationManagement.Models.VariableCreateParameters() + { + Name = variable.Name, + Properties = new AutomationManagement.Models.VariableCreateProperties() + { + Value = variable.Value, + Description = variable.Description + } + }; + + var sdkCreatedVariable = this.automationManagementClient.Variables.Create(automationAccountName, createParams).Variable; + + return new Variable(sdkCreatedVariable, automationAccountName); + } + } + + public void DeleteVariable(string automationAccountName, string variableName) + { + try + { + var existingVarible = this.GetVariable(automationAccountName, variableName); + + if (existingVarible.Encrypted) + { + this.automationManagementClient.EncryptedVariables.Delete(automationAccountName, variableName); + } + else + { + this.automationManagementClient.Variables.Delete(automationAccountName, variableName); + } + } + catch (ResourceNotFoundException) + { + // the variable does not exists or already deleted. Do nothing. Return. + return; + } + } + public Variable UpdateVariable(string automationAccountName, Variable variable) + { + var existingVarible = this.GetVariable(automationAccountName, variable.Name); + variable.Encrypted = existingVarible.Encrypted; + + if (variable.Encrypted) + { + var updateParams = new AutomationManagement.Models.EncryptedVariableUpdateParameters() + { + Name = variable.Name, + Properties = new AutomationManagement.Models.EncryptedVariableUpdateProperties() + { + Value = variable.Value, + Description = variable.Description + } + }; + + this.automationManagementClient.EncryptedVariables.Update(automationAccountName, updateParams); + } + else + { + var updateParams = new AutomationManagement.Models.VariableUpdateParameters() + { + Name = variable.Name, + Properties = new AutomationManagement.Models.VariableUpdateProperties() + { + Value = variable.Value, + Description = variable.Description + } + }; + + this.automationManagementClient.Variables.Update(automationAccountName, updateParams); + } + + return this.GetVariable(automationAccountName, variable.Name); + } + + public Variable GetVariable(string automationAccountName, string name) + { + try + { + var sdkEncryptedVariable = this.automationManagementClient.EncryptedVariables.Get( + automationAccountName, name).EncryptedVariable; + + if (sdkEncryptedVariable != null) + { + return new Variable(sdkEncryptedVariable, automationAccountName); + } + } + catch (CloudException) + { + // do nothing + } + + try + { + var sdkVarible = this.automationManagementClient.Variables.Get(automationAccountName, name).Variable; + + if (sdkVarible != null) + { + return new Variable(sdkVarible, automationAccountName); + } + } + catch (CloudException) + { + // do nothing + } + + throw new ResourceNotFoundException(typeof(Variable), string.Format(CultureInfo.CurrentCulture, Resources.VariableNotFound, name)); + } + + public IEnumerable ListVariables(string automationAccountName) + { + IList variables = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Variables.List( + automationAccountName, skipToken); + return new ResponseWithSkipToken( + response, response.Variables); + }); + + var result = variables.Select((variable, autoamtionAccountName) => this.CreateVariableFromVariableModel(variable, automationAccountName)).ToList(); + + IList encryptedVariables = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.EncryptedVariables.List( + automationAccountName, skipToken); + return new ResponseWithSkipToken( + response, response.EncryptedVariables); + }); + + result.AddRange(encryptedVariables.Select((variable, autoamtionAccountName) => this.CreateVariableFromVariableModel(variable, automationAccountName)).ToList()); + + return result; + } + public IEnumerable ListRunbooks(string automationAccountName) { return AutomationManagementClient @@ -154,6 +344,26 @@ public IEnumerable ListRunbooks(string automationAccountName) } #region Private Methods + private JobStream CreateJobStreamFromJobStreamModel(AutomationManagement.Models.JobStream jobStream) + { + Requires.Argument("jobStream", jobStream).NotNull(); + return new JobStream(jobStream); + } + + private Variable CreateVariableFromVariableModel(AutomationManagement.Models.Variable variable, string automationAccountName) + { + Requires.Argument("variable", variable).NotNull(); + + return new Variable(variable, automationAccountName); + } + + private Variable CreateVariableFromVariableModel(AutomationManagement.Models.EncryptedVariable variable, string automationAccountName) + { + Requires.Argument("variable", variable).NotNull(); + + return new Variable(variable, automationAccountName); + } + private Schedule CreateScheduleFromScheduleModel(AutomationManagement.Models.Schedule schedule) { @@ -222,5 +432,311 @@ private Schedule UpdateScheduleHelper(string automationAccountName, AutomationMa } #endregion + + public Credential CreateCredential(string automationAccountName, string name, string userName, string password, string description) + { + var credentialCreateParams = new AutomationManagement.Models.CredentialCreateParameters(); + credentialCreateParams.Name = name; + credentialCreateParams.Properties = new AutomationManagement.Models.CredentialCreateProperties(); + if (description != null) credentialCreateParams.Properties.Description = description; + + if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) + { + new AzureAutomationOperationException(string.Format(Resources.ParameterEmpty, "Username or Password")); + } + + credentialCreateParams.Properties.UserName = userName; + credentialCreateParams.Properties.Password = password; + + var createdCredential = this.automationManagementClient.PsCredentials.Create(automationAccountName, credentialCreateParams); + + if (createdCredential == null || createdCredential.StatusCode != HttpStatusCode.Created) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Create", "credential", name, automationAccountName)); + } + return new Credential(automationAccountName, createdCredential.Credential); + } + + public Credential UpdateCredential(string automationAccountName, string name, string userName, string password, string description) + { + var credentialUpdateParams = new AutomationManagement.Models.CredentialUpdateParameters(); + credentialUpdateParams.Name = name; + credentialUpdateParams.Properties = new AutomationManagement.Models.CredentialUpdateProperties(); + if (description != null) credentialUpdateParams.Properties.Description = description; + + if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)) + { + new AzureAutomationOperationException(string.Format(Resources.ParameterEmpty, "Username or Password")); + } + + credentialUpdateParams.Properties.UserName = userName; + credentialUpdateParams.Properties.Password = password; + + var credential = this.automationManagementClient.PsCredentials.Update(automationAccountName, credentialUpdateParams); + + if (credential == null || credential.StatusCode != HttpStatusCode.OK) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Update", "credential", name, automationAccountName)); + } + + var updatedCredential = this.GetCredential(automationAccountName, name); + + return updatedCredential; + } + + public Credential GetCredential(string automationAccountName, string name) + { + var credential = this.automationManagementClient.PsCredentials.Get(automationAccountName, name).Credential; + if (credential == null) + { + throw new ResourceNotFoundException(typeof(Credential), string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, name)); + } + + return new Credential(automationAccountName, credential); + } + + private Credential CreateCredentialFromCredentialModel(AutomationManagement.Models.Credential credential) + { + Requires.Argument("credential", credential).NotNull(); + + return new Credential(null, credential); + } + + public IEnumerable ListCredentials(string automationAccountName) + { + IList credentialModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.PsCredentials.List(automationAccountName, skipToken); + return new ResponseWithSkipToken( + response, response.Credentials); + }); + + return credentialModels.Select(c => new Credential(automationAccountName, c)); + } + + public void DeleteCredential(string automationAccountName, string name) + { + var credential = this.automationManagementClient.PsCredentials.Delete(automationAccountName, name); + if (credential != null && credential.StatusCode != HttpStatusCode.OK) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Delete", "Credential", name, automationAccountName)); + } + } + + public Module CreateModule(string automationAccountName, Uri contentLink, string moduleName, IDictionary Tags) + { + var createdModule = this.automationManagementClient.Modules.Create(automationAccountName, new AutomationManagement.Models.ModuleCreateParameters() + { + Name = moduleName, + Tags = Tags, + Properties = new AutomationManagement.Models.ModuleCreateProperties() + { + ContentLink = new AutomationManagement.Models.ContentLink() + { + Uri = contentLink, + ContentHash = null, + Version = null + } + }, + }); + + if (createdModule == null || createdModule.StatusCode != HttpStatusCode.Created) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Create", "Module", moduleName, automationAccountName)); + } + + return new Module(automationAccountName, createdModule.Module); + } + + public Module GetModule(string automationAccountName, string name) + { + var module = this.automationManagementClient.Modules.Get(automationAccountName, name).Module; + if (module == null) + { + throw new ResourceNotFoundException(typeof(Module), string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, name)); + } + + return new Module(automationAccountName, module); + } + + public IEnumerable ListModules(string automationAccountName) + { + IList modulesModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Modules.List(automationAccountName, skipToken); + return new ResponseWithSkipToken( + response, response.Modules); + }); + + return modulesModels.Select(c => new Module(automationAccountName, c)); + } + + public Module UpdateModule(string automationAccountName, IDictionary tags, string name, Uri contentLink) + { + var existingModule = this.GetModule(automationAccountName, name); + + var moduleUpdateParameters = new AutomationManagement.Models.ModuleUpdateParameters(); + moduleUpdateParameters.Name = name; + if (tags != null) moduleUpdateParameters.Tags = tags; + moduleUpdateParameters.Location = existingModule.Location; + moduleUpdateParameters.Properties = new AutomationManagement.Models.ModuleUpdateProperties() + { + ContentLink = new AutomationManagement.Models.ContentLink() + }; + + if (contentLink != null) moduleUpdateParameters.Properties.ContentLink.Uri = contentLink; + + var updatedModule = this.automationManagementClient.Modules.Update(automationAccountName, moduleUpdateParameters); + + if (updatedModule == null || updatedModule.StatusCode != HttpStatusCode.OK) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Update", "Module", name, automationAccountName)); + } + + return new Module(automationAccountName, updatedModule.Module); + } + + public void DeleteModule(string automationAccountName, string name) + { + var module = this.automationManagementClient.Modules.Delete(automationAccountName, name); + if (module != null && module.StatusCode != HttpStatusCode.OK) + { + new AzureAutomationOperationException(string.Format(Resources.AutomationOperationFailed, "Delete", "Module", name, automationAccountName)); + } + } + + + + + public Job GetJob(string automationAccountName, Guid Id) + { + var job = this.automationManagementClient.Jobs.Get(automationAccountName, Id).Job; + if (job == null) + { + throw new ResourceNotFoundException(typeof(Job), string.Format(CultureInfo.CurrentCulture, Resources.JobNotFound, Id)); + } + + return new Job(automationAccountName, job); + } + + public IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTime? startTime, DateTime? endTime) + { + IEnumerable jobModels; + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.Jobs.List( + automationAccountName, + new AutomationManagement.Models.JobListParameters + { + StartTime = this.FormatDateTime(startTime.Value), + EndTime = this.FormatDateTime(endTime.Value), + SkipToken = skipToken, + RunbookName = runbookName + }); + return new ResponseWithSkipToken(response, response.Jobs); + }); + + return jobModels.Select(jobModel => new Job(automationAccountName, jobModel)); + } + + public IEnumerable ListJobs(string automationAccountName, DateTime? startTime, DateTime? endTime) + { + + // Assume local time if DateTimeKind.Unspecified + if (startTime.HasValue && startTime.Value.Kind == DateTimeKind.Unspecified) + { + startTime = DateTime.SpecifyKind(startTime.Value, DateTimeKind.Local); + } + + + if (endTime.HasValue && endTime.Value.Kind == DateTimeKind.Unspecified) + { + endTime = DateTime.SpecifyKind(endTime.Value, DateTimeKind.Local); + } + + IEnumerable jobModels; + + if (startTime.HasValue && endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.Jobs.List( + automationAccountName, + new AutomationManagement.Models.JobListParameters + { + StartTime = this.FormatDateTime(startTime.Value), + EndTime = this.FormatDateTime(endTime.Value), + SkipToken = skipToken + }); + return new ResponseWithSkipToken(response, response.Jobs); + }); + } + else if (startTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.Jobs.List( + automationAccountName, + new AutomationManagement.Models.JobListParameters + { + StartTime = this.FormatDateTime(startTime.Value), + SkipToken = skipToken + }); + return new ResponseWithSkipToken(response, response.Jobs); + }); + } + else if (endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.Jobs.List( + automationAccountName, + new AutomationManagement.Models.JobListParameters + { + EndTime = this.FormatDateTime(endTime.Value), + SkipToken = skipToken + }); + return new ResponseWithSkipToken(response, response.Jobs); + }); + } + else + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Jobs.List( + automationAccountName, + new AutomationManagement.Models.JobListParameters { SkipToken = skipToken, }); + return new ResponseWithSkipToken(response, response.Jobs); + }); + } + + return jobModels.Select(jobModel => new Job(automationAccountName, jobModel)); + } + + public void ResumeJob(string automationAccountName, Guid id) + { + this.automationManagementClient.Jobs.Resume(automationAccountName, id); + } + + public void StopJob(string automationAccountName, Guid id) + { + this.automationManagementClient.Jobs.Stop(automationAccountName, id); + } + + public void SuspendJob(string automationAccountName, Guid id) + { + this.automationManagementClient.Jobs.Suspend(automationAccountName, id); + } } } \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs index 224e6a94fc2f..37879c7a6866 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs @@ -46,5 +46,15 @@ internal static class AutomationCmdletParameterSets /// The hourly schedule parameter set. /// internal const string ByHourly = "ByHourly"; + + /// + /// The Job Id parameter set. + /// + internal const string ByJobId = "ByJobId"; + + /// + /// The Runbook name parameter set. + /// + internal const string ByRunbookName = "ByRunbookName"; } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/AzureAutomationOperationException.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/AzureAutomationOperationException.cs new file mode 100644 index 000000000000..6dee5601c5e4 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/AzureAutomationOperationException.cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------- +// +// 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; + +namespace Microsoft.Azure.Commands.Automation.Common +{ + [Serializable] + public class AzureAutomationOperationException : Exception + { + public AzureAutomationOperationException(string message) + : base(message) + { + + } + + public AzureAutomationOperationException(string message, Exception exception) + : base(message, exception) + { + + } + } +} \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs index b05daed27572..81158e11fb8e 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -24,6 +24,18 @@ public interface IAutomationClient { AzureSubscription Subscription { get; } + IEnumerable GetJobStream(string automationAccountname, Guid jobId, DateTime? time, string streamType); + + Variable GetVariable(string automationAccountName, string variableName); + + IEnumerable ListVariables(string automationAccountName); + + Variable CreateVariable(string automationAccountName, Variable variable); + + void DeleteVariable(string automationAccountName, string variableName); + + Variable UpdateVariable(string automationAccountName, Variable variable); + Schedule CreateSchedule(string automationAccountName, Schedule schedule); void DeleteSchedule(string automationAccountName, string scheduleName); @@ -37,5 +49,37 @@ public interface IAutomationClient Runbook GetRunbook(string automationAccountName, string runbookName); IEnumerable ListRunbooks(string automationAccountName); + + Credential CreateCredential(string automationAccountName, string name, string userName, string password, string description); + + Credential UpdateCredential(string automationAccountName, string name, string userName, string password, string description); + + Credential GetCredential(string automationAccountName, string name); + + IEnumerable ListCredentials(string automationAccountName); + + void DeleteCredential(string automationAccountName, string name); + + Module CreateModule(string automationAccountName, Uri contentLink, string moduleName, IDictionary tags); + + Module GetModule(string automationAccountName, string name); + + Module UpdateModule(string automationAccountName, IDictionary tags, string name, Uri contentLink); + + IEnumerable ListModules(string automationAccountName); + + void DeleteModule(string automationAccountName, string name); + + Job GetJob(string automationAccountName, Guid id); + + IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTime? startTime, DateTime? endTime); + + IEnumerable ListJobs(string automationAccountName, DateTime? startTime, DateTime? endTime); + + void ResumeJob(string automationAccountName, Guid id); + + void StopJob(string automationAccountName, Guid id); + + void SuspendJob(string automationAccountName, Guid id); } } \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Credential.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Credential.cs new file mode 100644 index 000000000000..cfd84c1b76b3 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Credential.cs @@ -0,0 +1,63 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; +using System; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + public class Credential + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The Credential. + /// + public Credential(string accountAcccountName, Azure.Management.Automation.Models.Credential credential) + { + Requires.Argument("credential", credential).NotNull(); + this.AutomationAccountName = accountAcccountName; + this.Name = credential.Name; + + if (credential.Properties == null) return; + + this.Description = credential.Properties.Description; + this.CreationTime = credential.Properties.CreationTime.ToLocalTime(); + this.LastModifiedTime = credential.Properties.LastModifiedTime.ToLocalTime(); + this.UserName = credential.Properties.UserName; + } + + /// + /// Initializes a new instance of the class. + /// + public Credential() + { + } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + public string Name { get; set; } + public string UserName { get; set; } + + public string Description { get; set; } + + public DateTimeOffset CreationTime { get; set; } + + public DateTimeOffset LastModifiedTime { get; set; } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Job.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Job.cs new file mode 100644 index 000000000000..d5b27d3cb7d1 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Job.cs @@ -0,0 +1,149 @@ +// 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.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + /// + /// The Job object. + /// + public class Job + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The account name. + /// + /// + /// The Job. + /// + /// + /// + public Job(string accountName, Azure.Management.Automation.Models.Job job) + { + Requires.Argument("job", job).NotNull(); + Requires.Argument("accountName", accountName).NotNull(); + + this.AutomationAccountName = accountName; + this.Name = job.Name; + this.Location = job.Location; + this.Type = job.Type; + this.Tags = job.Tags ?? new Dictionary(); + this.Id = job.Id; + + if (job.Properties == null) return; + + this.CreationTime = job.Properties.CreationTime.ToLocalTime(); + this.LastModifiedTime = job.Properties.LastModifiedTime.ToLocalTime(); + this.StartTime = job.Properties.StartTime; + this.Status = job.Properties.Status; + this.StatusDetails = job.Properties.StatusDetails; + this.RunbookName = job.Properties.Runbook.Name; + this.Exception = job.Properties.Exception; + this.EndTime = job.Properties.EndTime; + this.LastStatusModifiedTime = job.Properties.LastStatusModifiedTime; + this.Parameters = job.Properties.Parameters ?? new Dictionary(); + } + + /// + /// Initializes a new instance of the class. + /// + public Job() + { + } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the tags. + /// + public string Id { get; set; } + + /// + /// Gets or sets the name. + /// + public string Name { get; set; } + + /// + /// Gets or sets the location. + /// + public string Location { get; set; } + + /// + /// Gets or sets the type. + /// + public string Type { get; set; } + + /// + /// Gets or sets the tags. + /// + public IDictionary Tags { get; set; } + + /// + /// Gets or sets the tags. + /// + public DateTimeOffset CreationTime { get; set; } + + /// + /// Gets or sets the status of the job. + /// + public string Status { get; set; } + + /// + /// Gets or sets the status details of the job. + /// + public string StatusDetails { get; set; } + + /// + /// Gets or sets the start time of the job. + /// + public DateTimeOffset StartTime { get; set; } + + /// + /// Gets or sets the end time of the job. + /// + public DateTimeOffset EndTime { get; set; } + + /// + /// Gets or sets the exception of the job. + /// + public string Exception { get; set; } + + /// + /// Gets or sets the last modified time of the job. + /// + public DateTimeOffset LastModifiedTime { get; set; } + + /// + /// Gets or sets the last status modified time of the job." + /// + public DateTimeOffset LastStatusModifiedTime { get; set; } + + /// + /// Gets or sets the parameters of the job. + /// + public IDictionary Parameters { get; set; } + + /// + /// Gets or sets the runbook. + /// + public string RunbookName { get; set; } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/JobStream.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/JobStream.cs new file mode 100644 index 000000000000..f1fe361f8b7d --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/JobStream.cs @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using AutomationManagement = Management.Automation; + + /// + /// The Job Stream. + /// + public class JobStream + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The job stream. + /// + /// + /// + public JobStream(AutomationManagement.Models.JobStream jobStream) + { + Requires.Argument("jobStream", jobStream).NotNull(); + + this.StreamId = jobStream.Properties.StreamId; + this.StreamType = jobStream.Properties.StreamType; + this.Summary = jobStream.Properties.Summary; + this.Time = jobStream.Properties.Time.ToLocalTime(); + } + + /// + /// Initializes a new instance of the class. + /// + public JobStream() + { + } + + /// + /// Gets or sets the stream id + /// + public string StreamId { get; set; } + + /// + /// Gets or sets the stream time. + /// + public DateTimeOffset Time { get; set; } + + /// + /// Gets or sets the stream summary. + /// + public string Summary { get; set; } + + /// + /// Gets or sets the stream Type. + /// + public string StreamType { get; set; } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Module.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Module.cs new file mode 100644 index 000000000000..d7468165a682 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Module.cs @@ -0,0 +1,117 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + public class Module + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The Module. + /// + public Module(string automationAccountName, Azure.Management.Automation.Models.Module module) + { + Requires.Argument("module", module).NotNull(); + this.AutomationAccountName = automationAccountName; + this.Name = module.Name; + this.Location = module.Location; + this.Type = module.Type; + this.Tags = module.Tags ?? new Dictionary(); + + if (module.Properties == null) return; + + this.CreationTime = module.Properties.CreationTime.ToLocalTime(); + this.LastPublishTime = module.Properties.LastPublishTime.ToLocalTime(); + this.IsGlobal = module.Properties.IsGlobal; + this.Version = module.Properties.Version; + this.ProvisioningState = module.Properties.ProvisioningState.ToString(); + this.ActivityCount = module.Properties.ActivityCount; + this.SizeInBytes = module.Properties.SizeInBytes; + } + + /// + /// Initializes a new instance of the class. + /// + public Module() + { + } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the name. + /// + public string Name { get; set; } + + /// + /// Gets or sets the location. + /// + public string Location { get; set; } + + /// + /// Gets or sets the type. + /// + public string Type { get; set; } + + /// + /// Gets or sets the tags. + /// + public IDictionary Tags { get; set; } + + /// + /// Gets or sets the IsGlobal. + /// + public bool IsGlobal { get; set; } + + /// + /// Gets or sets the Version. + /// + public string Version { get; set; } + + /// + /// Gets or sets the SizeInBytes. + /// + public long SizeInBytes { get; set; } + + /// + /// Gets or sets the ActivityCount. + /// + public int ActivityCount { get; set; } + + /// + /// Gets or sets the CreationTime. + /// + public DateTimeOffset CreationTime { get; set; } + + /// + /// Gets or sets the LastPublishTime. + /// + public DateTimeOffset LastPublishTime { get; set; } + + /// + /// Gets or sets the ProvisioningState. + /// + public string ProvisioningState { get; set; } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs new file mode 100644 index 000000000000..aa51b3712966 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs @@ -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; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using AutomationManagement = Management.Automation; + + /// + /// The Variable. + /// + public class Variable + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The varaiable. + /// + /// + /// + public Variable(AutomationManagement.Models.Variable variable, string automationAccoutName) + { + Requires.Argument("variable", variable).NotNull(); + + this.Name = variable.Name; + this.CreationTime = variable.Properties.CreationTime.ToLocalTime(); + this.LastModifiedTime = variable.Properties.LastModifiedTime.ToLocalTime(); + this.Value = variable.Properties.Value; + this.Description = variable.Properties.Description; + this.Encrypted = false; + this.AutomationAccountName = automationAccoutName; + } + + // + /// Initializes a new instance of the class. + /// + /// + /// The variable. + /// + /// + /// + public Variable(AutomationManagement.Models.EncryptedVariable variable, string automationAccountName) + { + Requires.Argument("variable", variable).NotNull(); + + this.Name = variable.Name; + this.CreationTime = variable.Properties.CreationTime.ToLocalTime(); + this.LastModifiedTime = variable.Properties.LastModifiedTime.ToLocalTime(); + this.Value = null; + this.Description = variable.Properties.Description; + this.Encrypted = true; + this.AutomationAccountName = automationAccountName; + } + + /// + /// Initializes a new instance of the class. + /// + public Variable() + { + } + + /// + /// Gets or sets the name. + /// + public string Name { get; set; } + + /// + /// Gets or sets the creation time. + /// + public DateTimeOffset CreationTime { get; set; } + + /// + /// Gets or sets the last modified time. + /// + public DateTimeOffset LastModifiedTime { get; set; } + + /// + /// Gets or sets the value. + /// + public string Value { get; set; } + + /// + /// Gets or sets the description. + /// + public string Description { get; set; } + + /// + /// Gets or sets the description. + /// + public bool Encrypted { get; set; } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs index e125407d9033..9e7c05ec0a8e 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -69,6 +69,42 @@ internal static string AutomationAccountNotFound { } } + /// + /// Looks up a localized string similar to {0} {1} operation failed for object name: {2) under AutomationAccount: {3}. + /// + internal static string AutomationOperationFailed { + get { + return ResourceManager.GetString("AutomationOperationFailed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The Job having Id: {0} was not found.. + /// + internal static string JobNotFound { + get { + return ResourceManager.GetString("JobNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} is empty.. + /// + internal static string ParameterEmpty { + get { + return ResourceManager.GetString("ParameterEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removing the Azure Automation {0}.. + /// + internal static string RemoveAzureAutomationResourceDescription { + get { + return ResourceManager.GetString("RemoveAzureAutomationResourceDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removing the Azure Automation schedule.. /// @@ -87,6 +123,15 @@ internal static string RemoveAzureAutomationScheduleWarning { } } + /// + /// Looks up a localized string similar to Are you sure you want to remove the Azure Automation {0} ?. + /// + internal static string RemovingAzureAutomationResourceWarning { + get { + return ResourceManager.GetString("RemovingAzureAutomationResourceWarning", resourceCulture); + } + } + /// /// Looks up a localized string similar to The Runbook was not found. Runbook name: {0}.. /// @@ -113,5 +158,23 @@ internal static string ScheduleNotFound { return ResourceManager.GetString("ScheduleNotFound", resourceCulture); } } + + /// + /// Looks up a localized string similar to The variable already exists. Variable name {0}.. + /// + internal static string VariableAlreadyExists { + get { + return ResourceManager.GetString("VariableAlreadyExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The varaible was not found. Variable name {0}.. + /// + internal static string VariableNotFound { + get { + return ResourceManager.GetString("VariableNotFound", resourceCulture); + } + } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx index 94e85485fdb4..ec70e8128f1c 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx @@ -121,6 +121,22 @@ The Automation account was not found. Automation + + {0} {1} operation failed for object name: {2) under AutomationAccount: {3} + Automation + + + The Job having Id: {0} was not found. + Automation + + + {0} is empty. + Automation + + + Removing the Azure Automation {0}. + Automation + Removing the Azure Automation schedule. Automation @@ -129,6 +145,10 @@ Are you sure you want to remove the Azure Automation schedule? Automation + + Are you sure you want to remove the Azure Automation {0} ? + Automation + The Runbook was not found. Runbook name: {0}. Autmation @@ -141,4 +161,11 @@ The schedule was not found. Schedule name: {0}. Automation + + The variable already exists. Variable name {0}. + + + The varaible was not found. Variable name {0}. + Automation + \ No newline at end of file