Skip to content

Commit fc824db

Browse files
committed
[Insights] Making enabled parameter in diagnosticsettings non nullable
1 parent 397ea87 commit fc824db

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/ResourceManager/Insights/Commands.Insights.Test/Diagnostics/SetDiagnosticSettingCommandTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public void SetSomeCategories()
150150
{
151151
cmdlet.Categories = new List<string> { "TestCategory1"};
152152
cmdlet.Enabled = false;
153+
cmdlet.MyInvocation.BoundParameters[SetAzureRmDiagnosticSettingCommand.EnabledParamName] = false;
153154
cmdlet.ExecuteCmdlet();
154155

155156
ServiceDiagnosticSettingsResource expectedSettings = GetDefaultSetting();
@@ -165,6 +166,7 @@ public void SetSomeTimeGrains()
165166
{
166167
cmdlet.Timegrains = new List<string> { "PT1H" };
167168
cmdlet.Enabled = false;
169+
cmdlet.MyInvocation.BoundParameters[SetAzureRmDiagnosticSettingCommand.EnabledParamName] = false;
168170
cmdlet.ExecuteCmdlet();
169171

170172
ServiceDiagnosticSettingsResource expectedSettings = GetDefaultSetting();

src/ResourceManager/Insights/Commands.Insights/Diagnostics/SetAzureRmDiagnosticSettingCommand.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
3535
public const string StorageAccountIdParamName = "StorageAccountId";
3636
public const string ServiceBusRuleIdParamName = "ServiceBusRuleId";
3737
public const string WorkspacetIdParamName = "WorkspaceId";
38+
public const string EnabledParamName = "EnabledParamName";
3839

3940
#region Parameters declarations
4041

@@ -62,7 +63,7 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
6263
/// </summary>
6364
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The value indicating whether the diagnostics should be enabled or disabled")]
6465
[ValidateNotNullOrEmpty]
65-
public bool? Enabled { get; set; }
66+
public bool Enabled { get; set; }
6667

6768
/// <summary>
6869
/// Gets or sets the categories parameter of the cmdlet
@@ -105,18 +106,21 @@ public class SetAzureRmDiagnosticSettingCommand : ManagementCmdletBase
105106

106107
private bool isWorkspaceParamPresent;
107108

109+
private bool isEnbledParameterPresent;
110+
108111
protected override void ProcessRecordInternal()
109112
{
110113
HashSet<string> usedParams = new HashSet<string>(this.MyInvocation.BoundParameters.Keys, StringComparer.OrdinalIgnoreCase);
111114

112115
this.isStorageParamPresent = usedParams.Contains(StorageAccountIdParamName);
113116
this.isServiceBusParamPresent = usedParams.Contains(ServiceBusRuleIdParamName);
114117
this.isWorkspaceParamPresent = usedParams.Contains(WorkspacetIdParamName);
118+
this.isEnbledParameterPresent = usedParams.Contains(EnabledParamName);
115119

116120
if (!this.isStorageParamPresent &&
117121
!this.isServiceBusParamPresent &&
118122
!this.isWorkspaceParamPresent &&
119-
!this.Enabled.HasValue)
123+
!this.isEnbledParameterPresent)
120124
{
121125
throw new ArgumentException("No operation is specified");
122126
}
@@ -197,7 +201,7 @@ private void SetRetention(ServiceDiagnosticSettingsResource properties)
197201

198202
private void SetSelectedTimegrains(ServiceDiagnosticSettingsResource properties)
199203
{
200-
if (!this.Enabled.HasValue)
204+
if (!this.isEnbledParameterPresent)
201205
{
202206
throw new ArgumentException("Parameter 'Enabled' is required by 'Timegrains' parameter.");
203207
}
@@ -211,13 +215,13 @@ private void SetSelectedTimegrains(ServiceDiagnosticSettingsResource properties)
211215
{
212216
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Metric timegrain '{0}' is not available", timegrainString));
213217
}
214-
metricSettings.Enabled = this.Enabled.Value;
218+
metricSettings.Enabled = this.Enabled;
215219
}
216220
}
217221

218222
private void SetSelectedCategories(ServiceDiagnosticSettingsResource properties)
219223
{
220-
if (!this.Enabled.HasValue)
224+
if (!this.isEnbledParameterPresent)
221225
{
222226
throw new ArgumentException("Parameter 'Enabled' is required by 'Categories' parameter.");
223227
}
@@ -231,25 +235,25 @@ private void SetSelectedCategories(ServiceDiagnosticSettingsResource properties)
231235
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Log category '{0}' is not available", category));
232236
}
233237

234-
logSettings.Enabled = this.Enabled.Value;
238+
logSettings.Enabled = this.Enabled;
235239
}
236240
}
237241

238242
private void SetAllCategoriesAndTimegrains(ServiceDiagnosticSettingsResource properties)
239243
{
240-
if (!this.Enabled.HasValue)
244+
if (!this.isEnbledParameterPresent)
241245
{
242246
return;
243247
}
244248

245249
foreach (var log in properties.Logs)
246250
{
247-
log.Enabled = this.Enabled.Value;
251+
log.Enabled = this.Enabled;
248252
}
249253

250254
foreach (var metric in properties.Metrics)
251255
{
252-
metric.Enabled = this.Enabled.Value;
256+
metric.Enabled = this.Enabled;
253257
}
254258
}
255259

0 commit comments

Comments
 (0)