Skip to content

Commit c999ef2

Browse files
committed
addressed code review comments
1 parent f1fb934 commit c999ef2

File tree

4 files changed

+122
-102
lines changed

4 files changed

+122
-102
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationWebhook.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2222
{
2323
/// <summary>
24-
/// Create a new Webhook for automation.
24+
/// Get Webhook for automation.
2525
/// </summary>
2626
[Cmdlet(VerbsCommon.Get, "AzureAutomationWebhook", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
2727
[OutputType(typeof(Webhook))]
@@ -40,7 +40,6 @@ public class GetAzureAutomationWebhook : AzureAutomationBaseCmdlet
4040
/// </summary>
4141
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, ValueFromPipelineByPropertyName = true,
4242
HelpMessage = "The Runbook name.")]
43-
[Alias("RbName")]
4443
public string RunbookName { get; set; }
4544

4645
/// <summary>

src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationWebhook.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
15+
using Microsoft.Azure.Commands.Automation.Properties;
1616
using System.Management.Automation;
1717
using System.Security.Permissions;
18-
using Microsoft.Azure.Commands.Automation.Model;
1918

2019
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2120
{
22-
using Microsoft.Azure.Commands.Automation.Properties;
23-
2421
/// <summary>
25-
/// Create a new Webhook for automation.
22+
/// Remove a new Webhook for automation.
2623
/// </summary>
2724
[Cmdlet(VerbsCommon.Remove, "AzureAutomationWebhook")]
2825
public class RemoveAzureAutomationWebhook : AzureAutomationBaseCmdlet

src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
15+
using Microsoft.Azure.Commands.Automation.Model;
16+
using Microsoft.WindowsAzure.Commands.Common;
17+
using System.Collections.Generic;
1618
using System.Management.Automation;
1719
using System.Security.Permissions;
18-
using Microsoft.Azure.Commands.Automation.Model;
1920

2021
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2122
{
22-
using System.Collections;
23-
using System.Collections.Generic;
24-
using System.Linq;
25-
26-
using Microsoft.WindowsAzure.Commands.Common;
27-
2823
/// <summary>
29-
/// Create a new Webhook for automation.
24+
/// Update a Webhook for automation.
3025
/// </summary>
3126
[Cmdlet(VerbsCommon.Set, "AzureAutomationWebhook")]
3227
[OutputType(typeof(Webhook))]

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs

Lines changed: 115 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -41,62 +41,76 @@ public Model.Webhook CreateWebhook(
4141
{
4242
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
4343
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
44-
var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName };
45-
46-
var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
47-
{
48-
IsEnabled = isEnabled,
49-
ExpiryTime = expiryTime,
50-
Runbook = rbAssociationProperty,
51-
Uri =
52-
this.automationManagementClient
53-
.Webhooks.GenerateUri(
54-
resourceGroupName,
55-
automationAccountName).Uri
56-
};
57-
if (runbookParameters != null)
44+
using (var request = new RequestSettings(this.automationManagementClient))
5845
{
59-
createOrUpdateProperties.Parameters =
60-
runbookParameters.Cast<DictionaryEntry>()
61-
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
62-
}
46+
var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName };
47+
var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
48+
{
49+
IsEnabled = isEnabled,
50+
ExpiryTime = expiryTime,
51+
Runbook = rbAssociationProperty,
52+
Uri =
53+
this.automationManagementClient
54+
.Webhooks.GenerateUri(
55+
resourceGroupName,
56+
automationAccountName).Uri
57+
};
58+
if (runbookParameters != null)
59+
{
60+
createOrUpdateProperties.Parameters =
61+
runbookParameters.Cast<DictionaryEntry>()
62+
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
63+
}
64+
65+
var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(
66+
name,
67+
createOrUpdateProperties);
6368

64-
var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(name, createOrUpdateProperties);
65-
66-
var webhook = this.automationManagementClient.Webhooks.CreateOrUpdate(
67-
resourceGroupName,
68-
automationAccountName,
69-
webhookCreateOrUpdateParameters).Webhook;
69+
var webhook =
70+
this.automationManagementClient.Webhooks.CreateOrUpdate(
71+
resourceGroupName,
72+
automationAccountName,
73+
webhookCreateOrUpdateParameters).Webhook;
7074

71-
return new Model.Webhook(resourceGroupName, automationAccountName, webhook, webhookCreateOrUpdateParameters.Properties.Uri);
75+
return new Model.Webhook(
76+
resourceGroupName,
77+
automationAccountName,
78+
webhook,
79+
webhookCreateOrUpdateParameters.Properties.Uri);
80+
}
7281
}
7382

7483
public Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name)
7584
{
7685
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
7786
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
78-
79-
try
87+
using (var request = new RequestSettings(this.automationManagementClient))
8088
{
81-
var webhook =
82-
this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name).Webhook;
83-
if (webhook == null)
89+
try
8490
{
85-
throw new ResourceNotFoundException(typeof(Webhook),
86-
string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
87-
}
91+
var webhook =
92+
this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name)
93+
.Webhook;
94+
if (webhook == null)
95+
{
96+
throw new ResourceNotFoundException(
97+
typeof(Webhook),
98+
string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
99+
}
88100

89-
return new Model.Webhook(resourceGroupName, automationAccountName, webhook);
90-
}
91-
catch (CloudException cloudException)
92-
{
93-
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
94-
{
95-
throw new ResourceNotFoundException(typeof(Webhook),
96-
string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
101+
return new Model.Webhook(resourceGroupName, automationAccountName, webhook);
97102
}
103+
catch (CloudException cloudException)
104+
{
105+
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
106+
{
107+
throw new ResourceNotFoundException(
108+
typeof(Webhook),
109+
string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
110+
}
98111

99-
throw;
112+
throw;
113+
}
100114
}
101115
}
102116

@@ -105,30 +119,35 @@ public Model.Webhook GetWebhook(string resourceGroupName, string automationAccou
105119
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
106120
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
107121
WebhookListResponse response;
108-
109-
if (string.IsNullOrEmpty(nextLink))
122+
using (var request = new RequestSettings(this.automationManagementClient))
110123
{
111-
if (runbookName == null)
124+
if (string.IsNullOrEmpty(nextLink))
112125
{
113-
response = this.automationManagementClient.Webhooks.List(
114-
resourceGroupName,
115-
automationAccountName,
116-
null);
126+
if (runbookName == null)
127+
{
128+
response = this.automationManagementClient.Webhooks.List(
129+
resourceGroupName,
130+
automationAccountName,
131+
null);
132+
}
133+
else
134+
{
135+
response = this.automationManagementClient.Webhooks.List(
136+
resourceGroupName,
137+
automationAccountName,
138+
runbookName);
139+
}
117140
}
118141
else
119142
{
120-
response = this.automationManagementClient.Webhooks.List(
121-
resourceGroupName,
122-
automationAccountName,
123-
runbookName);
143+
response = this.automationManagementClient.Webhooks.ListNext(nextLink);
124144
}
145+
146+
nextLink = response.NextLink;
147+
return
148+
response.Webhooks.Select(w => new Model.Webhook(resourceGroupName, automationAccountName, w))
149+
.ToList();
125150
}
126-
else
127-
{
128-
response = this.automationManagementClient.Webhooks.ListNext(nextLink);
129-
}
130-
nextLink = response.NextLink;
131-
return response.Webhooks.Select(w => new Model.Webhook(resourceGroupName, automationAccountName, w)).ToList();
132151
}
133152

134153
public Model.Webhook UpdateWebhook(
@@ -140,46 +159,56 @@ public Model.Webhook UpdateWebhook(
140159
{
141160
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
142161
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
143-
var webhookModel = this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name).Webhook;
144-
var webhookPatchProperties = new WebhookPatchProperties();
145-
if (webhookModel != null)
162+
using (var request = new RequestSettings(this.automationManagementClient))
146163
{
147-
if (isEnabled != null)
164+
var webhookModel =
165+
this.automationManagementClient.Webhooks.Get(resourceGroupName, automationAccountName, name).Webhook;
166+
var webhookPatchProperties = new WebhookPatchProperties();
167+
if (webhookModel != null)
148168
{
149-
webhookPatchProperties.IsEnabled = isEnabled.Value;
150-
}
151-
if (parameters != null)
152-
{
153-
webhookPatchProperties.Parameters =
154-
parameters.Cast<DictionaryEntry>()
155-
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
169+
if (isEnabled != null)
170+
{
171+
webhookPatchProperties.IsEnabled = isEnabled.Value;
172+
}
173+
if (parameters != null)
174+
{
175+
webhookPatchProperties.Parameters =
176+
parameters.Cast<DictionaryEntry>()
177+
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
178+
}
156179
}
180+
181+
var webhookPatchParameters = new WebhookPatchParameters(name) { Properties = webhookPatchProperties };
182+
var webhook =
183+
this.automationManagementClient.Webhooks.Patch(
184+
resourceGroupName,
185+
automationAccountName,
186+
webhookPatchParameters).Webhook;
187+
188+
return new Model.Webhook(resourceGroupName, automationAccountName, webhook);
157189
}
158-
159-
var webhookPatchParameters = new WebhookPatchParameters(name) { Properties = webhookPatchProperties };
160-
var webhook =
161-
this.automationManagementClient.Webhooks.Patch(
162-
resourceGroupName,
163-
automationAccountName,
164-
webhookPatchParameters).Webhook;
165-
return new Model.Webhook(resourceGroupName, automationAccountName, webhook);
166190
}
167191

168192
public void DeleteWebhook(string resourceGroupName, string automationAccountName, string name)
169193
{
170194
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
171195
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
172-
try
173-
{
174-
this.automationManagementClient.Webhooks.Delete(resourceGroupName, automationAccountName, name);
175-
}
176-
catch (CloudException cloudException)
196+
using (var request = new RequestSettings(this.automationManagementClient))
177197
{
178-
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
198+
try
199+
{
200+
this.automationManagementClient.Webhooks.Delete(resourceGroupName, automationAccountName, name);
201+
}
202+
catch (CloudException cloudException)
179203
{
180-
throw new ResourceNotFoundException(typeof(Webhook), string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
204+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
205+
{
206+
throw new ResourceNotFoundException(
207+
typeof(Webhook),
208+
string.Format(CultureInfo.CurrentCulture, Resources.WebhookNotFound, name));
209+
}
210+
throw;
181211
}
182-
throw;
183212
}
184213
}
185214
}

0 commit comments

Comments
 (0)