Skip to content

Fixes for Azure Automation module #6

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GetAzureAutomationSourceControlSyncJobOutput : AzureAutomationBaseC
public string SourceControlName { get; set; }

/// <summary>
/// Gets or sets the source contorl sync job id.
/// Gets or sets the source control sync job id.
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
HelpMessage = "The source control sync job id.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<Compile Include="Common\AutomationPSClientWebhook.cs" />
<Compile Include="Common\AutomationCmdletParameterSet.cs" />
<Compile Include="Common\AzureAutomationOperationException.cs" />
<Compile Include="Common\AzureErrorResponseMessage.cs" />
<Compile Include="Common\Constants.cs" />
<Compile Include="Common\DscNodeStatus.cs" />
<Compile Include="Common\IAutomationPSClient.cs" />
Expand Down Expand Up @@ -263,7 +264,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
</ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\..\tools\Common.Dependencies.targets" />
<Target Name="AfterBuild">
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.Rest.Azure.OData;

namespace Microsoft.Azure.Commands.Automation.Common
{
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Linq;

Expand Down Expand Up @@ -111,19 +114,51 @@ public Model.Webhook GetWebhook(string resourceGroupName, string automationAccou
{
if (string.IsNullOrEmpty(nextLink))
{
if (runbookName == null)
try
{
response = this.automationManagementClient.Webhook.ListByAutomationAccount(
resourceGroupName,
automationAccountName,
null);
if (runbookName == null)
{
response = this.automationManagementClient.Webhook.ListByAutomationAccount(
resourceGroupName,
automationAccountName,
null);
}
else
{
var filter = GetRunbookNameFilterString(runbookName);
response = this.automationManagementClient.Webhook.ListByAutomationAccount(
resourceGroupName,
automationAccountName,
new ODataQuery<Webhook>(filter));
}
}
else
catch (ErrorResponseException ex)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be common class that handles this. Is it not working?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check ExecuteCmdlet in Base class

{
response = this.automationManagementClient.Webhook.ListByAutomationAccount(
resourceGroupName,
automationAccountName,
runbookName);
if (!string.IsNullOrEmpty(ex.Response.Content))
{
AzureErrorResponseMessage responseContent;
try
{
responseContent = JsonConvert.DeserializeObject<AzureErrorResponseMessage>(ex.Response.Content);
}
catch
{
throw ex;
}

if (responseContent.Error.Code.Equals("ResourceGroupNotFound", StringComparison.InvariantCultureIgnoreCase))
{
throw new ResourceNotFoundException(typeof(Webhook), responseContent.Error.Message);
}
else
{
throw new ResourceNotFoundException(typeof(Webhook), String.Format(CultureInfo.CurrentCulture, Resources.AutomationAccountNotFound, automationAccountName));
}
}
else
{
throw ex;
}
}
}
else
Expand All @@ -132,9 +167,9 @@ public Model.Webhook GetWebhook(string resourceGroupName, string automationAccou
}

nextLink = response.NextPageLink;
return
response.Select(w => new Model.Webhook(resourceGroupName, automationAccountName, w))
.ToList();
return response
.Select(w => new Model.Webhook(resourceGroupName, automationAccountName, w))
.ToList();
}
}

Expand Down Expand Up @@ -201,5 +236,23 @@ public void DeleteWebhook(string resourceGroupName, string automationAccountName
}
}
}

private string GetRunbookNameFilterString(string runbookName)
{
string filter = null;
List<string> odataFilter = new List<string>();

if (!string.IsNullOrWhiteSpace(runbookName))
{
odataFilter.Add("properties/runbook/name eq '" + Uri.EscapeDataString(runbookName) + "'");
}

if (odataFilter.Count > 0)
{
filter = string.Join(" and ", odataFilter);
}

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

namespace Microsoft.Azure.Commands.Automation.Common
{
using Newtonsoft.Json;

/// <summary>
/// The error response message.
/// </summary>
public class AzureErrorResponseMessage
{
// Gets or sets the extended error info.
[JsonProperty(Required = Required.Always)]
public ErrorInfo Error { get; set; }

// Initializes a new instance of the class.
public AzureErrorResponseMessage(string code, string message)
{
this.Error = new ErrorInfo { Code = code, Message = message };
}

// The error information.
public class ErrorInfo
{
// Gets or sets the error code.
[JsonProperty(Required = Required.Default)]
public string Code { get; set; }

// Gets or sets the error message.
[JsonProperty(Required = Required.Default)]
public string Message { get; set; }
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public JobSchedule(string resourceGroupName, string automationAccountName, Azure
Requires.Argument("jobSchedule", jobSchedule).NotNull();
this.ResourceGroupName = resourceGroupName;
this.AutomationAccountName = automationAccountName;
this.JobScheduleId = jobSchedule.Id.ToString();
this.JobScheduleId = jobSchedule.JobScheduleId.ToString();
this.RunbookName = jobSchedule.Runbook.Name;
this.ScheduleName = jobSchedule.Schedule.Name;
this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,6 @@
<value>SourceControl '{0}' already exists.</value>
<comment>Automation</comment>
</data>
<data name="SourceControlNotFound" xml:space="preserve">
<value>SourceControl '{0}' not found.</value>
<comment>Automation</comment>
</data>
<data name="SourceControlRepoUrlCannotBeChanged" xml:space="preserve">
<value>SourceControl RepoUrl cannot be changed.</value>
<comment>Automation</comment>
Expand All @@ -501,10 +497,6 @@
<value>SourceControl SyncJob with id: '{0}' already exists.</value>
<comment>Automation</comment>
</data>
<data name="SourceControlSyncJobNotFound" xml:space="preserve">
<value>SourceControl Sync Job with id: '{0}' not found.</value>
<comment>Automation</comment>
</data>
<data name="SourceControlUpdateAction" xml:space="preserve">
<value>Updating the Azure Automation Source Control.</value>
<comment>Automation</comment>
Expand Down