21
21
using System . Management . Automation ;
22
22
using MNM = Microsoft . Azure . Management . Network . Models ;
23
23
using Microsoft . Azure . Management . OperationalInsights ;
24
- using ResourceGroups . Tests ;
25
24
26
25
namespace Microsoft . Azure . Commands . Network
27
26
{
@@ -34,6 +33,9 @@ public class SetAzureNetworkWatcherConfigFlowLogCommand : NetworkWatcherBaseCmdl
34
33
private const string SetByNameWithTAByResource = "SetByNameWithTAByResource" ;
35
34
private const string SetByNameWithTAByDetails = "SetByNameWithTAByDetails" ;
36
35
private const string SetByNameWithoutTA = "SetByNameWithoutTA" ;
36
+ private const string SetByResource = "SetByResource" ;
37
+ private const string WithTA = "WithTA" ;
38
+ private const string TAByDetails = "TAByDetails" ;
37
39
38
40
[ Parameter (
39
41
Mandatory = true ,
@@ -201,7 +203,7 @@ public class SetAzureNetworkWatcherConfigFlowLogCommand : NetworkWatcherBaseCmdl
201
203
ParameterSetName = SetByResourceWithTAByResource ) ]
202
204
[ Parameter (
203
205
Mandatory = true ,
204
- ValueFromPipelineByPropertyName = true ,
206
+ ValueFromPipeline = true ,
205
207
HelpMessage = "The WS object which is used to store the traffic analytics data." ,
206
208
ParameterSetName = SetByNameWithTAByResource ) ]
207
209
[ ValidateNotNull ]
@@ -212,8 +214,11 @@ public override void Execute()
212
214
base . Execute ( ) ;
213
215
string resourceGroupName ;
214
216
string name ;
217
+ string WorkspaceResourceId ;
218
+ string WorkspaceGUId ;
219
+ string WorkspaceLocation ;
215
220
216
- if ( ParameterSetName . Contains ( " SetByResource" ) )
221
+ if ( ParameterSetName . Contains ( SetByResource ) )
217
222
{
218
223
resourceGroupName = this . NetworkWatcher . ResourceGroupName ;
219
224
name = this . NetworkWatcher . Name ;
@@ -241,68 +246,50 @@ public override void Execute()
241
246
parameters . RetentionPolicy . Days = this . RetentionInDays ;
242
247
}
243
248
244
- if ( this . EnableTrafficAnalytics == true || this . EnableTrafficAnalytics == false )
249
+ if ( ParameterSetName . Contains ( WithTA ) )
245
250
{
246
251
parameters . FlowAnalyticsConfiguration = new MNM . TrafficAnalyticsProperties ( ) ;
247
252
parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration = new MNM . TrafficAnalyticsConfigurationProperties ( ) ;
248
253
249
- parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . Enabled = this . EnableTrafficAnalytics ;
254
+ parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . Enabled = this . EnableTrafficAnalytics . IsPresent ;
250
255
251
- string [ ] workspaceDetailsComponents = this . WorkspaceResourceId . Split ( '/' ) ;
252
- string worksapceResourceGroup = "" , workspaceName = "" ;
256
+
253
257
254
- //Expected format : /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-
255
- if ( workspaceDetailsComponents . Length == 9 )
256
- {
257
- worksapceResourceGroup = workspaceDetailsComponents [ 4 ] ;
258
- workspaceName = workspaceDetailsComponents [ 8 ] ;
259
-
260
- }
261
- else
262
- {
263
- throw new System . ArgumentException ( "The given workspace resource id is not in format of: /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-." ) ;
264
- }
265
-
266
- if ( Workspace == null )
258
+ if ( ParameterSetName . Contains ( TAByDetails ) )
267
259
{
268
260
if ( this . WorkspaceResourceId == null || this . WorkspaceGUId == null || this . WorkspaceLocation == null )
269
261
{
270
262
throw new System . ArgumentException ( "Either the Workspace parameter or all of WorkspaceResourceId,WorkspaceGUId,WorkspaceLocation must be provided" ) ;
271
263
}
264
+
265
+ string [ ] workspaceDetailsComponents = this . WorkspaceResourceId . Split ( '/' ) ;
266
+
267
+ //Expected format : /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-
268
+ if ( workspaceDetailsComponents . Length != 9 )
269
+ {
270
+ throw new System . ArgumentException ( "The given workspace resource id is not in format of: /subscriptions/-WorkspaceSubscriptionId-/resourcegroups/-WorkspaceResourceGroup-/providers/microsoft.operationalinsights/workspaces/-this.WorkspaceName-." ) ;
271
+ }
272
+
273
+ WorkspaceResourceId = this . WorkspaceResourceId ;
274
+ WorkspaceGUId = this . WorkspaceGUId ;
275
+ WorkspaceLocation = this . WorkspaceLocation ;
272
276
}
273
277
else
274
278
{
275
- if ( this . WorkspaceResourceId == null )
276
- {
277
- this . WorkspaceResourceId = this . Workspace . Id ;
278
- }
279
- else if ( this . WorkspaceResourceId != this . Workspace . Id )
279
+ if ( this . Workspace == null )
280
280
{
281
- throw new System . ArgumentException ( "The Workspace parameter and the WorkspaceResourceId poarameters are conflicting " ) ;
281
+ throw new System . ArgumentException ( "Either the Workspace parameter or all of WorkspaceResourceId,WorkspaceGUId,WorkspaceLocation must be provided " ) ;
282
282
}
283
283
284
- if ( this . WorkspaceGUId == null )
285
- {
286
- this . WorkspaceGUId = this . Workspace . CustomerId ;
287
- }
288
- else if ( this . WorkspaceGUId != this . Workspace . CustomerId )
289
- {
290
- throw new System . ArgumentException ( "The Workspace parameter and the WorkspaceGUId poarameters are conflicting" ) ;
291
- }
284
+ WorkspaceResourceId = this . Workspace . Id ;
285
+ WorkspaceGUId = this . Workspace . CustomerId ;
286
+ WorkspaceLocation = this . Workspace . Location ;
292
287
293
- if ( this . WorkspaceLocation == null )
294
- {
295
- this . WorkspaceLocation = this . Workspace . Location ;
296
- }
297
- else if ( this . WorkspaceLocation != this . Workspace . Location )
298
- {
299
- throw new System . ArgumentException ( "The Workspace parameter and the WorkspaceLocation poarameters are conflicting" ) ;
300
- }
301
288
}
302
289
303
- parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceId = this . WorkspaceGUId ;
304
- parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceRegion = this . WorkspaceLocation ;
305
- parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceResourceId = this . WorkspaceResourceId ;
290
+ parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceResourceId = WorkspaceResourceId ;
291
+ parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceId = WorkspaceGUId ;
292
+ parameters . FlowAnalyticsConfiguration . NetworkWatcherFlowAnalyticsConfiguration . WorkspaceRegion = WorkspaceLocation ;
306
293
}
307
294
308
295
PSFlowLog flowLog = new PSFlowLog ( ) ;
@@ -319,10 +306,5 @@ public PSFlowLog SetFlowLogConfig(string resourceGroupName, string name, MNM.Flo
319
306
return psFlowLog ;
320
307
}
321
308
322
- //public static OperationalInsightsManagementClient GetOperationalInsightsManagementClientWithHandler(MockContext context, RecordedDelegatingHandler handler)
323
- //{
324
- // var client = context.GetServiceClient<OperationalInsightsManagementClient>(handlers: handler);
325
- // return client;
326
- //}
327
309
}
328
310
}
0 commit comments