diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.ResourceManagement.Automation.Test.csproj b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.ResourceManagement.Automation.Test.csproj index d06f40fbb192..9e01eca03e71 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.ResourceManagement.Automation.Test.csproj +++ b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.ResourceManagement.Automation.Test.csproj @@ -111,9 +111,13 @@ + + + + diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationAccountTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationAccountTest.cs index aed901f99ef4..8bd40cb37b6b 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationAccountTest.cs +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationAccountTest.cs @@ -50,14 +50,15 @@ public void GetAzureAutomationAllAccountsSuccessfull() { // Setup string resourceGroupName = "resourceGroup"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListAutomationAccounts(resourceGroupName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListAutomationAccounts(resourceGroupName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListAutomationAccounts(null), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListAutomationAccounts(resourceGroupName, ref nextLink), Times.Once()); } [TestMethod] diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationWebhookTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationWebhookTest.cs new file mode 100644 index 000000000000..d0d3c6011b4c --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationWebhookTest.cs @@ -0,0 +1,67 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class GetAzureAutomationWebhookTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private GetAzureAutomationWebhook cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new GetAzureAutomationWebhook + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void GetAzureAutomationWebhookByNameSuccessful() + { + // Setup + string resourceGroupName = "resourceGroup"; + string accountName = "account"; + string webhookName = "webhookName"; + this.cmdlet.SetParameterSet("ByName"); + + this.mockAutomationClient.Setup(f => f.GetWebhook(resourceGroupName, accountName, webhookName)); + + // Test + this.cmdlet.ResourceGroupName = resourceGroupName; + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = webhookName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.GetWebhook(resourceGroupName, accountName, webhookName), Times.Once()); + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationWebhookTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationWebhookTest.cs new file mode 100644 index 000000000000..de06407b96d2 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationWebhookTest.cs @@ -0,0 +1,75 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class NewAzureAutomationWebhookTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private NewAzureAutomationWebhook cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new NewAzureAutomationWebhook + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void NewAzureAutomationWebhookByNameSuccessful() + { + // Setup + string resourceGroupName = "resourceGroup"; + string accountName = "account"; + string name = "webhookName"; + string runbookName = "runbookName"; + DateTimeOffset expiryTime = DateTimeOffset.Now.AddDays(1); + + this.mockAutomationClient.Setup( + f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null)); + + // Test + this.cmdlet.ResourceGroupName = resourceGroupName; + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = name; + this.cmdlet.RunbookName = runbookName; + this.cmdlet.ExpiryTime = expiryTime; + this.cmdlet.IsEnabled = true; + this.cmdlet.Parameters = null; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify( + f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null), + Times.Once()); + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationWebhookTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationWebhookTest.cs new file mode 100644 index 000000000000..469d514ca486 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationWebhookTest.cs @@ -0,0 +1,67 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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; + +namespace Microsoft.Azure.Commands.Automation.Test.UnitTests +{ + [TestClass] + public class RemoveAzureAutomationWebhookTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private RemoveAzureAutomationWebhook cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new RemoveAzureAutomationWebhook + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void RemoveAzureAutomationWebhookByNameSuccessful() + { + // Setup + string resourceGroupName = "resourceGroup"; + string accountName = "account"; + string webhookName = "webhookName"; + this.cmdlet.SetParameterSet("ByName"); + + this.mockAutomationClient.Setup(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName)); + + // Test + this.cmdlet.ResourceGroupName = resourceGroupName; + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = webhookName; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify(f => f.DeleteWebhook(resourceGroupName, accountName, webhookName), Times.Once()); + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationWebhookTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationWebhookTest.cs new file mode 100644 index 000000000000..bb837670fe6b --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/SetAzureAutomationWebhookTest.cs @@ -0,0 +1,70 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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 SetAzureAutomationWebhookTest : TestBase + { + private Mock mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private SetAzureAutomationWebhook cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + this.mockCommandRuntime = new MockCommandRuntime(); + this.cmdlet = new SetAzureAutomationWebhook + { + AutomationClient = this.mockAutomationClient.Object, + CommandRuntime = this.mockCommandRuntime + }; + } + + [TestMethod] + public void SetAzureAutomationWebhookToDisabledSuccessful() + { + // Setup + string resourceGroupName = "resourceGroup"; + string accountName = "account"; + string name = "webhookName"; + + this.mockAutomationClient.Setup( + f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false)); + + // Test + this.cmdlet.ResourceGroupName = resourceGroupName; + this.cmdlet.AutomationAccountName = accountName; + this.cmdlet.Name = name; + this.cmdlet.IsEnabled = false; + this.cmdlet.Parameters = null; + this.cmdlet.ExecuteCmdlet(); + + // Assert + this.mockAutomationClient.Verify( + f => f.UpdateWebhook(resourceGroupName, accountName, name, null, false), + Times.Once()); + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAccount.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAccount.cs index b822c8a460a2..2504887a160d 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAccount.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAccount.cs @@ -52,14 +52,14 @@ public IAutomationClient AutomationClient /// /// Gets or sets the automation account name. /// - [Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")] - [ValidateNotNullOrEmpty] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAutomationAccountName, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")] public string ResourceGroupName { get; set; } /// /// Gets or sets the automation account name. /// - [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAutomationAccountName, Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAutomationAccountName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] [Alias("AutomationAccountName")] [ValidateNotNullOrEmpty] public string Name { get; set; } @@ -77,13 +77,19 @@ public override void ExecuteCmdlet() { this.AutomationClient.GetAutomationAccount(this.ResourceGroupName, this.Name) }; + this.WriteObject(ret, true); } else { - ret = this.AutomationClient.ListAutomationAccounts(this.ResourceGroupName); - } + string nextLink = string.Empty; - this.WriteObject(ret, true); + do + { + ret = this.AutomationClient.ListAutomationAccounts(this.ResourceGroupName, ref nextLink); + this.WriteObject(ret, true); + + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs index eca0318761cc..bee591a3f790 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs @@ -48,13 +48,19 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetModule(this.ResourceGroupName, this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(ret); } else { - ret = this.AutomationClient.ListModules(this.ResourceGroupName, this.AutomationAccountName); - } + string nextLink = string.Empty; + + do + { + ret = this.AutomationClient.ListModules(this.ResourceGroupName, this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); - this.GenerateCmdletOutput(ret); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationWebhook.cs new file mode 100644 index 000000000000..8c1e3afcc215 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationWebhook.cs @@ -0,0 +1,86 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Model; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Get Webhook for automation. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationWebhook", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(Webhook))] + public class GetAzureAutomationWebhook : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the Webhook name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Webhook name.")] + [Alias("WebhookName")] + public string Name { get; set; } + + /// + /// Gets or sets the Webhook name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Runbook name.")] + public string RunbookName { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable webhooks = null; + if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) + { + var nextLink = string.Empty; + do + { + webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, null, ref nextLink); + this.GenerateCmdletOutput(webhooks); + } + while (!string.IsNullOrEmpty(nextLink)); + + } + else if (this.ParameterSetName == AutomationCmdletParameterSets.ByName) + { + webhooks = new List + { + this.AutomationClient.GetWebhook( + this.ResourceGroupName, + this.AutomationAccountName, + this.Name) + }; + this.GenerateCmdletOutput(webhooks); + } + else if (this.ParameterSetName == AutomationCmdletParameterSets.ByRunbookName) + { + var nextLink = string.Empty; + do + { + webhooks = this.AutomationClient.ListWebhooks(this.ResourceGroupName, this.AutomationAccountName, this.RunbookName, ref nextLink); + this.GenerateCmdletOutput(webhooks); + } + while (!string.IsNullOrEmpty(nextLink)); + } + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs new file mode 100644 index 000000000000..b27e5446681d --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs @@ -0,0 +1,98 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Model; +using Microsoft.Azure.Commands.Automation.Properties; +using Microsoft.WindowsAzure.Commands.Common; +using System; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Create a new Webhook for automation. + /// + [Cmdlet(VerbsCommon.New, "AzureAutomationWebhook")] + [OutputType(typeof(Webhook))] + public class NewAzureAutomationWebhook : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the module name. + /// + [Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The webhook name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the contentLink + /// + [Parameter(Position = 3, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Runbook Name associated with the webhook.")] + [ValidateNotNullOrEmpty] + public string RunbookName { get; set; } + + /// + /// Gets or sets the Enabled property of the Webhook + /// + [Parameter(Position = 4, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Enable/Disable property of the Webhook")] + [ValidateNotNullOrEmpty] + public bool IsEnabled { get; set; } + + /// + /// Gets or sets the Expiry Time + /// + [Parameter(Position = 5, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Expiry Time for webhook.")] + [ValidateNotNullOrEmpty] + public DateTimeOffset ExpiryTime { get; set; } + + /// + /// Gets or sets the Runbook parameters + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Runbook parameters name/value.")] + public IDictionary Parameters { get; set; } + + [Parameter(Mandatory = false, HelpMessage = "Skip warning message about one-time viewable webhook URL")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + this.ConfirmAction( + Force.IsPresent, + string.Format(Resources.WebhookOneTimeURL, "Webhook"), + string.Format(Resources.WebhookOneTimeURL, "Webhook"), + Name, + () => + this.WriteObject( + this.AutomationClient.CreateWebhook( + this.ResourceGroupName, + this.AutomationAccountName, + this.Name, + this.RunbookName, + this.IsEnabled, + this.ExpiryTime, + this.Parameters.ToHashtable()))); + + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationWebhook.cs new file mode 100644 index 000000000000..607fe797245f --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationWebhook.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Properties; +using System.Management.Automation; +using System.Security.Permissions; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Remove a new Webhook for automation. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationWebhook")] + public class RemoveAzureAutomationWebhook : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the Webhook name. + /// + [Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The webhook name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(Position = 3, HelpMessage = "Confirm the removal of the webhook")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + ConfirmAction( + Force.IsPresent, + string.Format(Resources.RemovingAzureAutomationResourceWarning, "Webhook"), + string.Format(Resources.RemoveAzureAutomationResourceDescription, "Webhook"), + Name, + () => this.AutomationClient.DeleteWebhook( + this.ResourceGroupName, + this.AutomationAccountName, + this.Name)); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs new file mode 100644 index 000000000000..ed80470c1f86 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.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 Microsoft.Azure.Commands.Automation.Model; +using Microsoft.WindowsAzure.Commands.Common; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Update a Webhook for automation. + /// + [Cmdlet(VerbsCommon.Set, "AzureAutomationWebhook")] + [OutputType(typeof(Webhook))] + public class SetAzureAutomationWebhook : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the Webhook name. + /// + [Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Webhook name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the IsEnabled Property + /// + [Parameter(Position = 3, Mandatory = true, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Enable/Disable property of the Webhook")] + [ValidateNotNullOrEmpty] + public bool? IsEnabled { get; set; } + + /// + /// Gets or sets the Runbook parameters + /// + [Parameter(Position = 4, Mandatory = false, ValueFromPipelineByPropertyName = true, + HelpMessage = "The Runbook parameters name/value.")] + public IDictionary Parameters { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + var updatedWebhook = this.AutomationClient.UpdateWebhook( + this.ResourceGroupName, + this.AutomationAccountName, + this.Name, + this.Parameters.ToHashtable(), + this.IsEnabled); + this.WriteObject(updatedWebhook); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index 9761d68d1ca8..41f228777e04 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -124,10 +124,16 @@ + + Code + + + + @@ -143,6 +149,7 @@ + @@ -169,6 +176,7 @@ + True diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs index 1f58bdd27613..c888728baf8e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs @@ -75,19 +75,21 @@ void SetClientIdHeader(string clientRequestId) #region Account Operations - public IEnumerable ListAutomationAccounts(string resourceGroupName) + public IEnumerable ListAutomationAccounts(string resourceGroupName, ref string nextLink) { - Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + AutomationAccountListResponse response; - return AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.AutomationAccounts.List( - resourceGroupName); - return new ResponseWithSkipToken( - response, response.AutomationAccounts); - }).Select(c => new Model.AutomationAccount(resourceGroupName, c)); + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.AutomationAccounts.List(resourceGroupName); + } + else + { + response = this.automationManagementClient.AutomationAccounts.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.AutomationAccounts.Select(c => new AutomationAccount(resourceGroupName, c)); } public AutomationAccount GetAutomationAccount(string resourceGroupName, string automationAccountName) @@ -231,18 +233,22 @@ public Module GetModule(string resourceGroupName, string automationAccountName, } } - public IEnumerable ListModules(string resourceGroupName, string automationAccountName) + public IEnumerable ListModules(string resourceGroupName, string automationAccountName, ref string nextLink) { - IList modulesModels = AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Modules.List(resourceGroupName, automationAccountName); - return new ResponseWithSkipToken( - response, response.Modules); - }); + ModuleListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Modules.List(resourceGroupName, + automationAccountName); + } + else + { + response = this.automationManagementClient.Modules.ListNext(nextLink); + } - return modulesModels.Select(c => new Module(resourceGroupName, automationAccountName, c)); + nextLink = response.NextLink; + return response.Modules.Select(c => new Module(resourceGroupName, automationAccountName, c)); } public Module UpdateModule(string resourceGroupName, string automationAccountName, string name, Uri contentLinkUri, string contentLinkVersion) diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs new file mode 100644 index 000000000000..bff062dc7152 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs @@ -0,0 +1,215 @@ +// ---------------------------------------------------------------------------------- +// +// 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 Hyak.Common; +using Microsoft.Azure.Commands.Automation.Properties; +using Microsoft.Azure.Management.Automation; +using Microsoft.Azure.Management.Automation.Models; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; + +namespace Microsoft.Azure.Commands.Automation.Common +{ + using System.Collections; + using System.Linq; + + using Microsoft.WindowsAzure.Commands.Utilities.Common; + + public partial class AutomationClient : IAutomationClient + { + public Model.Webhook CreateWebhook( + string resourceGroupName, + string automationAccountName, + string name, + string runbookName, + bool isEnabled, + DateTimeOffset expiryTime, + Hashtable runbookParameters) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + using (var request = new RequestSettings(this.automationManagementClient)) + { + var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName }; + var createOrUpdateProperties = new WebhookCreateOrUpdateProperties + { + IsEnabled = isEnabled, + ExpiryTime = expiryTime, + Runbook = rbAssociationProperty, + Uri = + this.automationManagementClient + .Webhooks.GenerateUri( + resourceGroupName, + automationAccountName).Uri + }; + if (runbookParameters != null) + { + createOrUpdateProperties.Parameters = + runbookParameters.Cast() + .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value); + } + + var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters( + name, + createOrUpdateProperties); + + var webhook = + this.automationManagementClient.Webhooks.CreateOrUpdate( + resourceGroupName, + automationAccountName, + webhookCreateOrUpdateParameters).Webhook; + + return new Model.Webhook( + resourceGroupName, + automationAccountName, + webhook, + webhookCreateOrUpdateParameters.Properties.Uri); + } + } + + public Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + using (var request = new RequestSettings(this.automationManagementClient)) + { + try + { + var webhook = + this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name) + .Webhook; + if (webhook == null) + { + throw new ResourceNotFoundException( + typeof(Webhook), + string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name)); + } + + return new Model.Webhook(resourceGroupName, automationAccountName, webhook); + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NotFound) + { + throw new ResourceNotFoundException( + typeof(Webhook), + string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name)); + } + + throw; + } + } + } + + public IEnumerable ListWebhooks(string resourceGroupName, string automationAccountName, string runbookName, ref string nextLink) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + WebhookListResponse response; + using (var request = new RequestSettings(this.automationManagementClient)) + { + if (string.IsNullOrEmpty(nextLink)) + { + if (runbookName == null) + { + response = this.automationManagementClient.Webhooks.List( + resourceGroupName, + automationAccountName, + null); + } + else + { + response = this.automationManagementClient.Webhooks.List( + resourceGroupName, + automationAccountName, + runbookName); + } + } + else + { + response = this.automationManagementClient.Webhooks.ListNext(nextLink); + } + + nextLink = response.NextLink; + return + response.Webhooks.Select(w => new Model.Webhook(resourceGroupName, automationAccountName, w)) + .ToList(); + } + } + + public Model.Webhook UpdateWebhook( + string resourceGroupName, + string automationAccountName, + string name, + Hashtable parameters, + bool? isEnabled) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + using (var request = new RequestSettings(this.automationManagementClient)) + { + var webhookModel = + this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name).Webhook; + var webhookPatchProperties = new WebhookPatchProperties(); + if (webhookModel != null) + { + if (isEnabled != null) + { + webhookPatchProperties.IsEnabled = isEnabled.Value; + } + if (parameters != null) + { + webhookPatchProperties.Parameters = + parameters.Cast() + .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value); + } + } + + var webhookPatchParameters = new WebhookPatchParameters(name) { Properties = webhookPatchProperties }; + var webhook = + this.automationManagementClient.Webhooks.Patch( + resourceGroupName, + automationAccountName, + webhookPatchParameters).Webhook; + + return new Model.Webhook(resourceGroupName, automationAccountName, webhook); + } + } + + public void DeleteWebhook(string resourceGroupName, string automationAccountName, string name) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + using (var request = new RequestSettings(this.automationManagementClient)) + { + try + { + this.automationManagementClient.Webhooks.Delete(resourceGroupName, automationAccountName, name); + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NoContent) + { + throw new ResourceNotFoundException( + typeof(Webhook), + string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name)); + } + throw; + } + } + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index e3b16d7ac57d..910b3f1e394e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -28,7 +28,7 @@ public interface IAutomationClient #region Accounts - IEnumerable ListAutomationAccounts(string resourceGroupName); + IEnumerable ListAutomationAccounts(string resourceGroupName, ref string nextLink); AutomationAccount GetAutomationAccount(string resourceGroupName, string automationAccountName); @@ -113,7 +113,7 @@ IEnumerable ListDscNodesByConfiguration( Module UpdateModule(string resourceGroupName, string automationAccountName, string name, Uri contentLink, string contentLinkVersion); - IEnumerable ListModules(string resourceGroupName, string automationAccountName); + IEnumerable ListModules(string resourceGroupName, string automationAccountName, ref string nextLink); void DeleteModule(string resourceGroupName, string automationAccountName, string name); @@ -129,5 +129,26 @@ IEnumerable ListDscNodesByConfiguration( DirectoryInfo GetDscNodeReportContent(string resourceGroupName, string automationAccountName, Guid nodeId, Guid reportId, string outputFolder, bool overwriteExistingFile); #endregion + + #region Webhooks + + Model.Webhook CreateWebhook( + string resourceGroupName, + string automationAccountName, + string name, + string runbookName, + bool isEnabled, + DateTimeOffset expiryTime, + Hashtable parameters); + + Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name); + + IEnumerable ListWebhooks(string resourceGroupName, string automationAccountName, string runbooName, ref string nextLink); + + Model.Webhook UpdateWebhook(string resourceGroupName, string automationAccountName, string name, Hashtable parameters, bool? isEnabled); + + void DeleteWebhook(string resourceGroupName, string automationAccountName, string name); + + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/AutomationAccount.cs b/src/ResourceManager/Automation/Commands.Automation/Model/AutomationAccount.cs index cf2368498084..016d4b3ca972 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/AutomationAccount.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/AutomationAccount.cs @@ -36,10 +36,18 @@ public class AutomationAccount /// public AutomationAccount(string resourceGroupName, AutomationManagement.Models.AutomationAccount automationAccount) { - Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccount", automationAccount).NotNull(); - this.ResourceGroupName = resourceGroupName; + + if (!string.IsNullOrEmpty(resourceGroupName)) + { + this.ResourceGroupName = resourceGroupName; + } + else + { + this.ResourceGroupName = automationAccount.Id.Substring(1).Split(Convert.ToChar("/"))[3]; + } + this.AutomationAccountName = automationAccount.Name; this.Location = automationAccount.Location; diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs new file mode 100644 index 000000000000..802c55f6f2cd --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs @@ -0,0 +1,97 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Properties; +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using System.Linq; + + public class Webhook + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The resource group name. + /// + /// + /// The account name. + /// + /// + /// The Webhook. + /// + /// + /// The Webhook URI + /// + public Webhook( + string resourceGroupName, + string automationAccountName, + Azure.Management.Automation.Models.Webhook webhook, + string webhookUri = "") + { + Requires.Argument("resourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("automationAccountName", automationAccountName).NotNull(); + Requires.Argument("webhook", webhook).NotNull(); + + this.ResourceGroupName = resourceGroupName; + this.AutomationAccountName = automationAccountName; + this.Name = webhook.Name; + + if (webhook.Properties == null) return; + + this.CreationTime = webhook.Properties.CreationTime.ToLocalTime(); + this.Description = webhook.Properties.Description; + this.ExpiryTime = webhook.Properties.ExpiryTime.ToLocalTime(); + this.IsEnabled = webhook.Properties.IsEnabled; + if (webhook.Properties.LastInvokedTime.HasValue) + { + this.LastInvokedTime = webhook.Properties.LastInvokedTime.Value.ToLocalTime(); + } + + this.LastModifiedTime = webhook.Properties.LastModifiedTime.ToLocalTime(); + this.Parameters = new Hashtable(webhook.Properties.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); + this.RunbookName = webhook.Properties.Runbook.Name; + this.WebhookURI = webhookUri; + } + + public string ResourceGroupName { get; set; } + + public string AutomationAccountName { get; set; } + + public string Name { get; set; } + + public DateTimeOffset CreationTime { get; set; } + + public string Description { get; set; } + + public DateTimeOffset ExpiryTime { get; set; } + + public bool? IsEnabled { get; set; } + + public DateTimeOffset LastInvokedTime { get; set; } + + public DateTimeOffset LastModifiedTime { get; set; } + + public Hashtable Parameters { get; set; } + + public string RunbookName { get; set; } + + public string WebhookURI { get; set; } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 09e07f15522f..6b6d54c8584e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18449 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -662,5 +662,23 @@ internal static string VariableNotFound { return ResourceManager.GetString("VariableNotFound", resourceCulture); } } + + /// + /// Looks up a localized string similar to The Webhook with Name: {0} was not found.. + /// + internal static string WebhookNotFound { + get { + return ResourceManager.GetString("WebhookNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to For security purposes, the URL of the created webhook will only be viewable in the output of this command. No other commands will return the webhook URL. Make sure to copy down the webhook URL from this command's output before closing your PowerShell session, and to store it securely.. + /// + internal static string WebhookOneTimeURL { + get { + return ResourceManager.GetString("WebhookOneTimeURL", resourceCulture); + } + } } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index 9ef6d499c9d4..6a7091667d81 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -384,4 +384,12 @@ The Dsc Configuration was not found. Configuration name {0}. Automation + + The Webhook with Name: {0} was not found. + Automation + + + For security purposes, the URL of the created webhook will only be viewable in the output of this command. No other commands will return the webhook URL. Make sure to copy down the webhook URL from this command's output before closing your PowerShell session, and to store it securely. + Automation + \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCertificateTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCertificateTest.cs index 16f563ebc4e6..68afb85340b7 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCertificateTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCertificateTest.cs @@ -70,15 +70,16 @@ public void GetAzureAutomationCertificateByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListCertificates(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListCertificates(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListCertificates(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListCertificates(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationConnectionTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationConnectionTest.cs index 7f45706705a3..c5bd75412e38 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationConnectionTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationConnectionTest.cs @@ -70,15 +70,16 @@ public void GetAzureAutomationConnectionByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListConnections(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListConnections(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListConnections(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListConnections(accountName, ref nextLink), Times.Once()); } [TestMethod] diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs index 90594d48ef62..58e74779d4b8 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationCredentialTest.cs @@ -68,15 +68,16 @@ public void GetAzureAutomationCredentialByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListCredentials(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListCredentials(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListCredentials(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListCredentials(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationJobTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationJobTest.cs index 71f4b5897569..2749e38c3435 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationJobTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationJobTest.cs @@ -51,8 +51,9 @@ public void GetAzureAutomationJobByRunbookNameSuccessfull() // Setup string accountName = "automation"; string runbookName = "runbook"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null)); + this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; @@ -60,7 +61,7 @@ public void GetAzureAutomationJobByRunbookNameSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, null, null, null, ref nextLink), Times.Once()); } public void GetAzureAutomationJobByRunbookNamAndStartTimeEndTimeeSuccessfull() @@ -68,10 +69,12 @@ public void GetAzureAutomationJobByRunbookNamAndStartTimeEndTimeeSuccessfull() // Setup string accountName = "automation"; string runbookName = "runbook"; + string nextLink = string.Empty; + DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0); DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0); - this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null)); + this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; @@ -79,7 +82,7 @@ public void GetAzureAutomationJobByRunbookNamAndStartTimeEndTimeeSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, null, ref nextLink), Times.Once()); } public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSuccessfull() @@ -87,11 +90,13 @@ public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSucces // Setup string accountName = "automation"; string runbookName = "runbook"; + string nextLink = string.Empty; + DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0); DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0); string status = "Completed"; - this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status)); + this.mockAutomationClient.Setup(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; @@ -100,7 +105,7 @@ public void GetAzureAutomationCompletedJobByRunbookNamAndStartTimeEndTimeeSucces this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobsByRunbookName(accountName, runbookName, startTime, endTime, status, ref nextLink), Times.Once()); } [TestMethod] @@ -108,15 +113,16 @@ public void GetAzureAutomationAllJobsSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListJobs(accountName, null, null, null)); + this.mockAutomationClient.Setup(f => f.ListJobs(accountName, null, null, null, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobs(accountName, null, null, null), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobs(accountName, null, null, null, ref nextLink), Times.Once()); } [TestMethod] @@ -124,11 +130,13 @@ public void GetAzureAutomationAllJobsBetweenStartAndEndTimeSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; + DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0); DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0); // look for jobs between 5pm to 6pm on 30th december 2014 - this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, null)); + this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, null, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; @@ -137,7 +145,7 @@ public void GetAzureAutomationAllJobsBetweenStartAndEndTimeSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, null), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, null, ref nextLink), Times.Once()); } [TestMethod] @@ -145,12 +153,14 @@ public void GetAzureAutomationAllCompletedJobsBetweenStartAndEndTimeSuccessfull( { // Setup string accountName = "automation"; + string nextLink = string.Empty; + DateTime startTime = new DateTime(2014, 12, 30, 17, 0, 0, 0); DateTime endTime = new DateTime(2014, 12, 30, 18, 0, 0, 0); string status = "Completed"; // look for jobs between 5pm to 6pm on 30th december 2014 - this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, status)); + this.mockAutomationClient.Setup(f => f.ListJobs(accountName, startTime, endTime, status, ref nextLink)); // Test this.cmdlet.AutomationAccountName = accountName; @@ -160,7 +170,7 @@ public void GetAzureAutomationAllCompletedJobsBetweenStartAndEndTimeSuccessfull( this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, status), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobs(accountName, startTime, endTime, status, ref nextLink), Times.Once()); } public void GetAzureAutomationJobByIdSuccessfull() diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs index 47133a6aa2e9..6ae958261467 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationModuleTest.cs @@ -68,15 +68,16 @@ public void GetAzureAutomationModuleByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListModules(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListModules(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListModules(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListModules(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationRunbookTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationRunbookTest.cs index 28b0ec8bcae5..426336c124a3 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationRunbookTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationRunbookTest.cs @@ -70,8 +70,9 @@ public void GetAzureAutomationRunbookByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListRunbooks(accountName)).Returns((string a) => new List()); ; + this.mockAutomationClient.Setup(f => f.ListRunbooks(accountName, ref nextLink)).Returns((string a, string b) => new List()); ; // Test this.cmdlet.AutomationAccountName = accountName; @@ -79,7 +80,7 @@ public void GetAzureAutomationRunbookByAllSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListRunbooks(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListRunbooks(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduleTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduleTest.cs index f0866f66514f..4e7590938add 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduleTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduleTest.cs @@ -70,8 +70,9 @@ public void GetAzureAutomationScheduleByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListSchedules(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListSchedules(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; @@ -79,7 +80,7 @@ public void GetAzureAutomationScheduleByAllSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListSchedules(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListSchedules(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduledRunbookTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduledRunbookTest.cs index 952486533e93..a4e1fb3092d6 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduledRunbookTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationScheduledRunbookTest.cs @@ -92,8 +92,9 @@ public void GetAzureAutomationScheduledRunbookByRunbookNameSuccessfull() // Setup string accountName = "automation"; string runbookName = "runbook"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListJobSchedulesByRunbookName(accountName, runbookName)).Returns((string a, string b) => new List()); + this.mockAutomationClient.Setup(f => f.ListJobSchedules(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; @@ -102,7 +103,7 @@ public void GetAzureAutomationScheduledRunbookByRunbookNameSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobSchedulesByRunbookName(accountName, runbookName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobSchedules(accountName, ref nextLink), Times.Once()); } [TestMethod] @@ -111,8 +112,9 @@ public void GetAzureAutomationScheduledRunbookByScheduleNameSuccessfull() // Setup string accountName = "automation"; string scheduleName = "schedule"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListJobSchedulesByScheduleName(accountName, scheduleName)).Returns((string a, string b) => new List()); + this.mockAutomationClient.Setup(f => f.ListJobSchedules(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; @@ -121,7 +123,7 @@ public void GetAzureAutomationScheduledRunbookByScheduleNameSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobSchedulesByScheduleName(accountName, scheduleName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobSchedules(accountName, ref nextLink), Times.Once()); } [TestMethod] @@ -129,8 +131,9 @@ public void GetAzureAutomationScheduledRunbookByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListJobSchedules(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListJobSchedules(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; @@ -138,7 +141,7 @@ public void GetAzureAutomationScheduledRunbookByAllSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListJobSchedules(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListJobSchedules(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs index f1bef99670f0..66acc3b7e7a3 100644 --- a/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs +++ b/src/ServiceManagement/Automation/Commands.Automation.Test/UnitTests/GetAzureAutomationVariableTest.cs @@ -70,8 +70,9 @@ public void GetAzureAutomationVariableByAllSuccessfull() { // Setup string accountName = "automation"; + string nextLink = string.Empty; - this.mockAutomationClient.Setup(f => f.ListVariables(accountName)).Returns((string a) => new List()); + this.mockAutomationClient.Setup(f => f.ListVariables(accountName, ref nextLink)).Returns((string a, string b) => new List()); // Test this.cmdlet.AutomationAccountName = accountName; @@ -79,7 +80,7 @@ public void GetAzureAutomationVariableByAllSuccessfull() this.cmdlet.ExecuteCmdlet(); // Assert - this.mockAutomationClient.Verify(f => f.ListVariables(accountName), Times.Once()); + this.mockAutomationClient.Verify(f => f.ListVariables(accountName, ref nextLink), Times.Once()); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCertificate.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCertificate.cs index 7d4254ad206e..59885c395c22 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCertificate.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCertificate.cs @@ -48,13 +48,19 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetCertificate(this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(ret); } else { - ret = this.AutomationClient.ListCertificates(this.AutomationAccountName); - } + var nextLink = string.Empty; + + do + { + ret = this.AutomationClient.ListCertificates(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); - this.GenerateCmdletOutput(ret); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConnection.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConnection.cs index 4f47be72fef7..24cd2203fd74 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConnection.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConnection.cs @@ -55,17 +55,24 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetConnection(this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(ret); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByConnectionTypeName) { ret = this.AutomationClient.ListConnectionsByType(this.AutomationAccountName, this.ConnectionTypeName); + this.GenerateCmdletOutput(ret); } else { - ret = this.AutomationClient.ListConnections(this.AutomationAccountName); - } + var nextLink = string.Empty; + + do + { + ret = this.AutomationClient.ListConnections(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); - this.GenerateCmdletOutput(ret); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs index 1155918c4b03..e553b6d88feb 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationCredential.cs @@ -48,13 +48,20 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetCredential(this.AutomationAccountName, this.Name) }; + + this.GenerateCmdletOutput(ret); } else { - ret = this.AutomationClient.ListCredentials(this.AutomationAccountName); - } + var nextLink = string.Empty; - this.GenerateCmdletOutput(ret); + do + { + ret = this.AutomationClient.ListCredentials(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); + + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs index 625f40d73de9..776182ffe8fe 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs @@ -70,25 +70,38 @@ public class GetAzureAutomationJob : AzureAutomationBaseCmdlet [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] protected override void AutomationExecuteCmdlet() { - IEnumerable jobs; + IEnumerable jobs = null; if (this.Id != null && !Guid.Empty.Equals(this.Id)) { // ByJobId - jobs = new List { this.AutomationClient.GetJob(this.AutomationAccountName, this.Id) }; + jobs = new List { this.AutomationClient.GetJob(this.AutomationAccountName, this.Id) }; + this.WriteObject(jobs, true); } else if (this.RunbookName != null) { // ByRunbookName - jobs = this.AutomationClient.ListJobsByRunbookName(this.AutomationAccountName, this.RunbookName, this.StartTime, this.EndTime, this.Status); + var nextLink = string.Empty; + + do + { + jobs = this.AutomationClient.ListJobsByRunbookName(this.AutomationAccountName, this.RunbookName, this.StartTime, this.EndTime, this.Status, ref nextLink); + this.WriteObject(jobs, true); + + } while (!string.IsNullOrEmpty(nextLink)); } else { // ByAll - jobs = this.AutomationClient.ListJobs(this.AutomationAccountName, this.StartTime, this.EndTime, this.Status); + var nextLink = string.Empty; + + do + { + jobs = this.AutomationClient.ListJobs(this.AutomationAccountName, this.StartTime, this.EndTime, this.Status, ref nextLink); + this.WriteObject(jobs, true); + + } while (!string.IsNullOrEmpty(nextLink)); } - - this.WriteObject(jobs, true); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs index d129635a3aa7..c66a96c38a16 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs @@ -47,8 +47,14 @@ public class GetAzureAutomationJobOutput : AzureAutomationBaseCmdlet [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] protected override void AutomationExecuteCmdlet() { - var ret = this.AutomationClient.GetJobStream(this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString() ); - this.GenerateCmdletOutput(ret); + var nextLink = string.Empty; + + do + { + var ret = this.AutomationClient.GetJobStream(this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString(), ref nextLink); + this.GenerateCmdletOutput(ret); + + } while (!string.IsNullOrEmpty(nextLink)); } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs index 8f1fcc65806c..80ac7d7b6d72 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationModule.cs @@ -48,13 +48,19 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetModule(this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(ret); } else { - ret = this.AutomationClient.ListModules(this.AutomationAccountName); - } + var nextLink = string.Empty; + + do + { + ret = this.AutomationClient.ListModules(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); - this.GenerateCmdletOutput(ret); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationRunbook.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationRunbook.cs index cb79cc71c67d..04db28e88c3c 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationRunbook.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationRunbook.cs @@ -49,13 +49,20 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetRunbook(this.AutomationAccountName, this.Name) }; + + this.GenerateCmdletOutput(ret); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) { - ret = this.AutomationClient.ListRunbooks(this.AutomationAccountName); - } + var nextLink = string.Empty; - this.GenerateCmdletOutput(ret); + do + { + ret = this.AutomationClient.ListRunbooks(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); + + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationSchedule.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationSchedule.cs index 48e8e2b534a4..7fc8566741a2 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationSchedule.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationSchedule.cs @@ -51,13 +51,19 @@ protected override void AutomationExecuteCmdlet() this.AutomationClient.GetSchedule( this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(schedules); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) { - schedules = this.AutomationClient.ListSchedules(this.AutomationAccountName); - } + var nextLink = string.Empty; + + do + { + schedules = this.AutomationClient.ListSchedules(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(schedules); - this.GenerateCmdletOutput(schedules); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationScheduledRunbook.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationScheduledRunbook.cs index d72d9f0e1fda..300baf4bd3c5 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationScheduledRunbook.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationScheduledRunbook.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Management.Automation; using System.Security.Permissions; using Microsoft.Azure.Commands.Automation.Common; @@ -64,6 +65,7 @@ protected override void AutomationExecuteCmdlet() this.AutomationClient.GetJobSchedule( this.AutomationAccountName, this.JobScheduleId .Value) }; + this.GenerateCmdletOutput(jobSchedules); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByRunbookNameAndScheduleName) { @@ -72,21 +74,48 @@ protected override void AutomationExecuteCmdlet() this.AutomationClient.GetJobSchedule( this.AutomationAccountName, this.RunbookName, this.ScheduleName) }; + this.GenerateCmdletOutput(jobSchedules); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByRunbookName) { - jobSchedules = this.AutomationClient.ListJobSchedulesByRunbookName(this.AutomationAccountName, this.RunbookName); + var nextLink = string.Empty; + + do + { + var schedules = this.AutomationClient.ListJobSchedules(this.AutomationAccountName, ref nextLink); + if (schedules != null) + { + this.GenerateCmdletOutput(schedules.ToList().Where(js => String.Equals(js.RunbookName, this.RunbookName, StringComparison.OrdinalIgnoreCase))); + } + + } while (!string.IsNullOrEmpty(nextLink)); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByScheduleName) { - jobSchedules = this.AutomationClient.ListJobSchedulesByScheduleName(this.AutomationAccountName, this.ScheduleName); + var nextLink = string.Empty; + + do + { + var schedules = this.AutomationClient.ListJobSchedules(this.AutomationAccountName, ref nextLink); + if (schedules != null) + { + this.GenerateCmdletOutput(schedules.ToList().Where(js => String.Equals(js.ScheduleName, this.ScheduleName, StringComparison.OrdinalIgnoreCase))); + } + + } while (!string.IsNullOrEmpty(nextLink)); + } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) { - jobSchedules = this.AutomationClient.ListJobSchedules(this.AutomationAccountName); - } + var nextLink = string.Empty; - this.GenerateCmdletOutput(jobSchedules); + do + { + jobSchedules = this.AutomationClient.ListJobSchedules(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(jobSchedules); + + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs index a20d9d05ff86..9c2d91e09cc2 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationVariable.cs @@ -48,13 +48,19 @@ protected override void AutomationExecuteCmdlet() { this.AutomationClient.GetVariable(this.AutomationAccountName, this.Name) }; + this.GenerateCmdletOutput(ret); } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) { - ret = this.AutomationClient.ListVariables(this.AutomationAccountName); - } + var nextLink = string.Empty; + + do + { + ret = this.AutomationClient.ListVariables(this.AutomationAccountName, ref nextLink); + this.GenerateCmdletOutput(ret); - this.GenerateCmdletOutput(ret); + } while (!string.IsNullOrEmpty(nextLink)); + } } } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj index f9f37360bad4..afc4350ca3ed 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj +++ b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj @@ -95,7 +95,7 @@ False - ..\..\..\packages\Microsoft.WindowsAzure.Management.Automation.1.0.2\lib\net40\Microsoft.WindowsAzure.Management.Automation.dll + ..\..\..\packages\Microsoft.WindowsAzure.Management.Automation.1.0.3\lib\net40\Microsoft.WindowsAzure.Management.Automation.dll ..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs index 41a1a2e9b26f..b8e4b3e71509 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs @@ -124,20 +124,22 @@ public Schedule GetSchedule(string automationAccountName, string scheduleName) return this.CreateScheduleFromScheduleModel(automationAccountName, scheduleModel); } - public IEnumerable ListSchedules(string automationAccountName) + public IEnumerable ListSchedules(string automationAccountName, ref string nextLink) { - IList scheduleModels = AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Schedules.List( - automationAccountName); + ScheduleListResponse response; - return new ResponseWithSkipToken( - response, response.Schedules); - }); + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Schedules.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Schedules.ListNext(nextLink); + } - return scheduleModels.Select(scheduleModel => new Schedule(automationAccountName, scheduleModel)); + nextLink = response.NextLink; + return response.Schedules.Select(c => new Schedule(automationAccountName, c)); } public Schedule UpdateSchedule(string automationAccountName, string scheduleName, bool? isEnabled, string description) @@ -165,17 +167,22 @@ public Runbook GetRunbook(string automationAccountName, string runbookName) return new Runbook(automationAccountName, runbookModel); } - public IEnumerable ListRunbooks(string automationAccountName) + public IEnumerable ListRunbooks(string automationAccountName, ref string nextLink) { - return AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Runbooks.List( - automationAccountName); - return new ResponseWithSkipToken( - response, response.Runbooks); - }).Select(c => new Runbook(automationAccountName, c)); + RunbookListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Runbooks.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Runbooks.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.Runbooks.Select(c => new Runbook(automationAccountName, c)); } public Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description, @@ -549,18 +556,22 @@ public Variable GetVariable(string automationAccountName, string name) } } - public IEnumerable ListVariables(string automationAccountName) + public IEnumerable ListVariables(string automationAccountName, ref string nextLink) { - IList variables = AutomationManagementClient.ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Variables.List( - automationAccountName); - return new ResponseWithSkipToken( - response, response.Variables); - }); + VariableListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Variables.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Variables.ListNext(nextLink); + } - return variables.Select(variable => this.CreateVariableFromVariableModel(variable, automationAccountName)).ToList(); + nextLink = response.NextLink; + return response.Variables.Select(c => new Variable(c, automationAccountName)); } #endregion @@ -635,18 +646,22 @@ private Credential CreateCredentialFromCredentialModel(AutomationManagement.Mode return new Credential(null, credential); } - public IEnumerable ListCredentials(string automationAccountName) + public IEnumerable ListCredentials(string automationAccountName, ref string nextLink) { - IList credentialModels = AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.PsCredentials.List(automationAccountName); - return new ResponseWithSkipToken( - response, response.Credentials); - }); + CredentialListResponse response; - return credentialModels.Select(c => new Credential(automationAccountName, c)); + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.PsCredentials.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.PsCredentials.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.Credentials.Select(c => new Credential(automationAccountName, c)); } public void DeleteCredential(string automationAccountName, string name) @@ -711,18 +726,22 @@ public Module GetModule(string automationAccountName, string name) } } - public IEnumerable ListModules(string automationAccountName) + public IEnumerable ListModules(string automationAccountName, ref string nextLink) { - IList modulesModels = AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Modules.List(automationAccountName); - return new ResponseWithSkipToken( - response, response.Modules); - }); + ModuleListResponse response; - return modulesModels.Select(c => new Module(automationAccountName, c)); + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Modules.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Modules.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.Modules.Select(c => new Module(automationAccountName, c)); } public Module UpdateModule(string automationAccountName, IDictionary tags, string name, Uri contentLinkUri, string contentLinkVersion) @@ -800,7 +819,7 @@ public void DeleteModule(string automationAccountName, string name) #region Jobs public IEnumerable GetJobStream(string automationAccountName, Guid jobId, DateTimeOffset? time, - string streamType) + string streamType, ref string nextLink) { var listParams = new AutomationManagement.Models.JobStreamListParameters(); @@ -814,8 +833,19 @@ public IEnumerable GetJobStream(string automationAccountName, Guid jo listParams.StreamType = streamType; } - var jobStreams = this.automationManagementClient.JobStreams.List(automationAccountName, jobId, listParams).JobStreams; - return jobStreams.Select(stream => this.CreateJobStreamFromJobStreamModel(stream, automationAccountName, jobId)).ToList(); + JobStreamListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.JobStreams.List(automationAccountName, jobId, listParams); + } + else + { + response = this.automationManagementClient.JobStreams.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.JobStreams.Select(stream => this.CreateJobStreamFromJobStreamModel(stream, automationAccountName, jobId)); } public Job GetJob(string automationAccountName, Guid Id) @@ -830,147 +860,53 @@ public Job GetJob(string automationAccountName, Guid Id) return new Job(automationAccountName, job); } - public IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus) + public IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus, ref string nextLink) { - IEnumerable jobModels; + JobListResponse response; - if (startTime.HasValue && endTime.HasValue) + if (string.IsNullOrEmpty(nextLink)) { - jobModels = AutomationManagementClient.ContinuationTokenHandler( - skipToken => + response = this.automationManagementClient.Jobs.List( + automationAccountName, + new JobListParameters { - var response = - this.automationManagementClient.Jobs.List( - automationAccountName, - new AutomationManagement.Models.JobListParameters - { - StartTime = FormatDateTime(startTime.Value), - EndTime = FormatDateTime(endTime.Value), - RunbookName = runbookName, - Status = jobStatus, - }); - 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 = FormatDateTime(startTime.Value), - RunbookName = runbookName, - Status = jobStatus, - }); - 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 = FormatDateTime(endTime.Value), - RunbookName = runbookName, - Status = jobStatus, - }); - return new ResponseWithSkipToken(response, response.Jobs); + StartTime = (startTime.HasValue) ? FormatDateTime(startTime.Value) : null, + EndTime = (endTime.HasValue) ? FormatDateTime(endTime.Value) : null, + RunbookName = runbookName, + Status = jobStatus, }); } else { - jobModels = AutomationManagementClient.ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Jobs.List( - automationAccountName, - new AutomationManagement.Models.JobListParameters - { - Status = jobStatus, - RunbookName = runbookName - }); - return new ResponseWithSkipToken(response, response.Jobs); - }); + response = this.automationManagementClient.Jobs.ListNext(nextLink); } - return jobModels.Select(jobModel => new Job(automationAccountName, jobModel)); + nextLink = response.NextLink; + return response.Jobs.Select(c => new Job(automationAccountName, c)); } - public IEnumerable ListJobs(string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus) + public IEnumerable ListJobs(string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus, ref string nextLink) { - IEnumerable jobModels; + JobListResponse response; - if (startTime.HasValue && endTime.HasValue) + if (string.IsNullOrEmpty(nextLink)) { - jobModels = AutomationManagementClient.ContinuationTokenHandler( - skipToken => - { - var response = - this.automationManagementClient.Jobs.List( - automationAccountName, - new AutomationManagement.Models.JobListParameters - { - StartTime = FormatDateTime(startTime.Value), - EndTime = FormatDateTime(endTime.Value), - Status = jobStatus, - }); - 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 = FormatDateTime(startTime.Value), - Status = jobStatus, - }); - 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 + response = this.automationManagementClient.Jobs.List( + automationAccountName, + new JobListParameters { - EndTime = FormatDateTime(endTime.Value), + StartTime = (startTime.HasValue) ? FormatDateTime(startTime.Value) : null, + EndTime = (endTime.HasValue) ? FormatDateTime(endTime.Value) : null, Status = jobStatus, }); - return new ResponseWithSkipToken(response, response.Jobs); - }); } else { - jobModels = AutomationManagementClient.ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Jobs.List( - automationAccountName, - new AutomationManagement.Models.JobListParameters { Status = jobStatus }); - return new ResponseWithSkipToken(response, response.Jobs); - }); + response = this.automationManagementClient.Jobs.ListNext(nextLink); } - return jobModels.Select(jobModel => new Job(automationAccountName, jobModel)); + nextLink = response.NextLink; + return response.Jobs.Select(c => new Job(automationAccountName, c)); } public void ResumeJob(string automationAccountName, Guid id) @@ -1157,17 +1093,22 @@ public CertificateInfo GetCertificate(string automationAccountName, string name) return new Certificate(automationAccountName, certificateModel); } - public IEnumerable ListCertificates(string automationAccountName) + public IEnumerable ListCertificates(string automationAccountName, ref string nextLink) { - return AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Certificates.List( - automationAccountName); - return new ResponseWithSkipToken( - response, response.Certificates); - }).Select(c => new CertificateInfo(automationAccountName, c)); + CertificateListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Certificates.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Certificates.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.Certificates.Select(c => new CertificateInfo(automationAccountName, c)); } public void DeleteCertificate(string automationAccountName, string name) @@ -1264,22 +1205,34 @@ public Connection GetConnection(string automationAccountName, string name) public IEnumerable ListConnectionsByType(string automationAccountName, string typeName) { - var connections = this.ListConnections(automationAccountName); + var connections = new List(); + string nextLink = string.Empty; + + do + { + connections.AddRange(this.ListConnections(automationAccountName, ref nextLink)); + + } while (!string.IsNullOrEmpty(nextLink)); return connections.Where(c => c.ConnectionTypeName.Equals(typeName, StringComparison.InvariantCultureIgnoreCase)); } - public IEnumerable ListConnections(string automationAccountName) + public IEnumerable ListConnections(string automationAccountName, ref string nextLink) { - return AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.Connections.List( - automationAccountName); - return new ResponseWithSkipToken( - response, response.Connection); - }).Select(c => new Connection(automationAccountName, c)); + ConnectionListResponse response; + + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.Connections.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.Connections.ListNext(nextLink); + } + + nextLink = response.NextLink; + return response.Connection.Select(c => new Connection(automationAccountName, c)); } public void DeleteConnection(string automationAccountName, string name) @@ -1330,65 +1283,76 @@ public JobSchedule GetJobSchedule(string automationAccountName, Guid jobSchedule public JobSchedule GetJobSchedule(string automationAccountName, string runbookName, string scheduleName) { - var jobSchedules = this.ListJobSchedules(automationAccountName); - JobSchedule jobSchedule = null; - bool jobScheduleFound = false; + const bool jobScheduleFound = false; + var nextLink = string.Empty; - foreach (var js in jobSchedules) + do { - if (String.Equals(js.RunbookName, runbookName, StringComparison.OrdinalIgnoreCase) && - String.Equals(js.ScheduleName, scheduleName, StringComparison.OrdinalIgnoreCase)) + var schedules = this.ListJobSchedules(automationAccountName, ref nextLink); + var jobSchedule = schedules.FirstOrDefault(js => String.Equals(js.RunbookName, runbookName, StringComparison.OrdinalIgnoreCase) && + String.Equals(js.ScheduleName, scheduleName, StringComparison.OrdinalIgnoreCase)); + + if (jobSchedule != null) { - jobSchedule = this.GetJobSchedule(automationAccountName, new Guid(js.JobScheduleId)); - jobScheduleFound = true; - break; + this.GetJobSchedule(automationAccountName, new Guid(jobSchedule.JobScheduleId)); + return jobSchedule; } - } + + } while (!string.IsNullOrEmpty(nextLink)); + if (!jobScheduleFound) { throw new ResourceNotFoundException(typeof(Schedule), string.Format(CultureInfo.CurrentCulture, Resources.JobScheduleNotFound, runbookName, scheduleName)); } - - return jobSchedule; } - public IEnumerable ListJobSchedules(string automationAccountName) + public IEnumerable ListJobSchedules(string automationAccountName, ref string nextLink) { - IList jobScheduleModels = AutomationManagementClient - .ContinuationTokenHandler( - skipToken => - { - var response = this.automationManagementClient.JobSchedules.List( - automationAccountName); + JobScheduleListResponse response; - return new ResponseWithSkipToken( - response, response.JobSchedules); - }); + if (string.IsNullOrEmpty(nextLink)) + { + response = this.automationManagementClient.JobSchedules.List( + automationAccountName); + } + else + { + response = this.automationManagementClient.JobSchedules.ListNext(nextLink); + } - return jobScheduleModels.Select(jobScheduleModel => new JobSchedule(automationAccountName, jobScheduleModel)); + nextLink = response.NextLink; + return response.JobSchedules.Select(c => new JobSchedule(automationAccountName, c)); } public IEnumerable ListJobSchedulesByRunbookName(string automationAccountName, string runbookName) { - var jobSchedules = this.ListJobSchedules(automationAccountName); + var jobSchedulesOfRunbook = new List(); + var nextLink = string.Empty; - IEnumerable jobSchedulesOfRunbook = new List(); + do + { + var schedules = this.ListJobSchedules(automationAccountName, ref nextLink); + jobSchedulesOfRunbook.AddRange(schedules.Where(js => String.Equals(js.RunbookName, runbookName, StringComparison.OrdinalIgnoreCase))); - jobSchedulesOfRunbook = jobSchedules.Where(js => String.Equals(js.RunbookName, runbookName, StringComparison.OrdinalIgnoreCase)); + } while (!string.IsNullOrEmpty(nextLink)); return jobSchedulesOfRunbook; } public IEnumerable ListJobSchedulesByScheduleName(string automationAccountName, string scheduleName) { - var jobSchedules = this.ListJobSchedules(automationAccountName); + var jobSchedulesOfSchedules = new List(); + var nextLink = string.Empty; - IEnumerable jobSchedulesOfSchedule = new List(); + do + { + var schedules = this.ListJobSchedules(automationAccountName, ref nextLink); + jobSchedulesOfSchedules.AddRange(schedules.Where(js => String.Equals(js.ScheduleName, scheduleName, StringComparison.OrdinalIgnoreCase))); - jobSchedulesOfSchedule = jobSchedules.Where(js => String.Equals(js.ScheduleName, scheduleName, StringComparison.OrdinalIgnoreCase)); + } while (!string.IsNullOrEmpty(nextLink)); - return jobSchedulesOfSchedule; + return jobSchedulesOfSchedules; } public JobSchedule RegisterScheduledRunbook(string automationAccountName, string runbookName, string scheduleName, IDictionary parameters) @@ -1431,19 +1395,24 @@ public void UnregisterScheduledRunbook(string automationAccountName, Guid jobSch public void UnregisterScheduledRunbook(string automationAccountName, string runbookName, string scheduleName) { - var jobSchedules = this.ListJobSchedules(automationAccountName); - bool jobScheduleFound = false; + const bool jobScheduleFound = false; + var nextLink = string.Empty; - foreach (var jobSchedule in jobSchedules) + do { - if (jobSchedule.RunbookName == runbookName && jobSchedule.ScheduleName == scheduleName) + var schedules = this.ListJobSchedules(automationAccountName, ref nextLink); + var jobSchedule = schedules.FirstOrDefault(js => String.Equals(js.RunbookName, runbookName, StringComparison.OrdinalIgnoreCase) && + String.Equals(js.ScheduleName, scheduleName, StringComparison.OrdinalIgnoreCase)); + + if (jobSchedule != null) { this.UnregisterScheduledRunbook(automationAccountName, new Guid(jobSchedule.JobScheduleId)); - jobScheduleFound = true; - break; + return; } - } - if(!jobScheduleFound) + + } while (!string.IsNullOrEmpty(nextLink)); + + if (!jobScheduleFound) { throw new ResourceNotFoundException(typeof(Schedule), string.Format(CultureInfo.CurrentCulture, Resources.JobScheduleNotFound, runbookName, scheduleName)); diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs index aa2295ed33f8..0577a4ecf255 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -27,7 +27,7 @@ public interface IAutomationClient #region JobStreams - IEnumerable GetJobStream(string automationAccountname, Guid jobId, DateTimeOffset? time, string streamType); + IEnumerable GetJobStream(string automationAccountname, Guid jobId, DateTimeOffset? time, string streamType, ref string nextLink); #endregion @@ -35,7 +35,7 @@ public interface IAutomationClient Variable GetVariable(string automationAccountName, string variableName); - IEnumerable ListVariables(string automationAccountName); + IEnumerable ListVariables(string automationAccountName, ref string nextLink); Variable CreateVariable(Variable variable); @@ -45,7 +45,7 @@ public interface IAutomationClient #endregion - #region Scedules + #region Schedules Schedule CreateSchedule(string automationAccountName, Schedule schedule); @@ -53,7 +53,7 @@ public interface IAutomationClient Schedule GetSchedule(string automationAccountName, string scheduleName); - IEnumerable ListSchedules(string automationAccountName); + IEnumerable ListSchedules(string automationAccountName, ref string nextLink); Schedule UpdateSchedule(string automationAccountName, string scheduleName, bool? isEnabled, string description); @@ -63,7 +63,7 @@ public interface IAutomationClient Runbook GetRunbook(string automationAccountName, string runbookName); - IEnumerable ListRunbooks(string automationAccountName); + IEnumerable ListRunbooks(string automationAccountName, ref string nextLink); Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description, string[] tags); @@ -91,7 +91,7 @@ public interface IAutomationClient CredentialInfo GetCredential(string automationAccountName, string name); - IEnumerable ListCredentials(string automationAccountName); + IEnumerable ListCredentials(string automationAccountName, ref string nextLink); void DeleteCredential(string automationAccountName, string name); @@ -105,7 +105,7 @@ public interface IAutomationClient Module UpdateModule(string automationAccountName, IDictionary tags, string name, Uri contentLink, string contentLinkVersion); - IEnumerable ListModules(string automationAccountName); + IEnumerable ListModules(string automationAccountName, ref string nextLink); void DeleteModule(string automationAccountName, string name); @@ -115,9 +115,9 @@ public interface IAutomationClient Job GetJob(string automationAccountName, Guid id); - IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus); + IEnumerable ListJobsByRunbookName(string automationAccountName, string runbookName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus, ref string nextLink); - IEnumerable ListJobs(string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus); + IEnumerable ListJobs(string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus, ref string nextLink); void ResumeJob(string automationAccountName, Guid id); @@ -145,7 +145,7 @@ public interface IAutomationClient CertificateInfo GetCertificate(string automationAccountName, string name); - IEnumerable ListCertificates(string automationAccountName); + IEnumerable ListCertificates(string automationAccountName, ref string nextLink); void DeleteCertificate(string automationAccountName, string name); @@ -161,7 +161,7 @@ public interface IAutomationClient IEnumerable ListConnectionsByType(string automationAccountName, string name); - IEnumerable ListConnections(string automationAccountName); + IEnumerable ListConnections(string automationAccountName, ref string nextLink); void DeleteConnection(string automationAccountName, string name); @@ -173,7 +173,7 @@ public interface IAutomationClient JobSchedule GetJobSchedule(string automationAccountName, string runbookName, string scheduleName); - IEnumerable ListJobSchedules(string automationAccountName); + IEnumerable ListJobSchedules(string automationAccountName, ref string nextLink); IEnumerable ListJobSchedulesByRunbookName(string automationAccountName, string runbookName); diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/StreamType.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/StreamType.cs index bdbaa7e80993..004861988c6c 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/StreamType.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/StreamType.cs @@ -20,6 +20,11 @@ namespace Microsoft.Azure.Commands.Automation.Common /// public enum StreamType { + /// + /// Indicates Generic stream. Used for querying all the streams regardless of the type. + /// + Any, + /// /// Indicates Progress Record streams /// @@ -48,11 +53,6 @@ public enum StreamType /// /// Indicates Verbose Record streams /// - Verbose, - - /// - /// Indicates Generic stream. Used for querying all the streams regardless of the type. - /// - Any + Verbose } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Connection.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Connection.cs index ca2d4f15af33..89c62f28f14c 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Model/Connection.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Connection.cs @@ -48,7 +48,7 @@ public Connection(string accountAcccountName, WindowsAzure.Management.Automation this.FieldDefinitionValues = new Hashtable(StringComparer.InvariantCultureIgnoreCase); foreach (var kvp in connection.Properties.FieldDefinitionValues) { - this.FieldDefinitionValues.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value)); + this.FieldDefinitionValues.Add(kvp.Key, kvp.Value.ToString()); } } diff --git a/src/ServiceManagement/Automation/Commands.Automation/packages.config b/src/ServiceManagement/Automation/Commands.Automation/packages.config index ab77a48bed25..a11f6dab4e7e 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/packages.config +++ b/src/ServiceManagement/Automation/Commands.Automation/packages.config @@ -11,6 +11,6 @@ - + \ No newline at end of file