@@ -349,56 +349,64 @@ private IEnumerable<PolicyData> GetPolicyStatusesHelper(PolicySetDefinition[] po
349
349
// Get all gcrp assignments for the initiative - for policy definitions of category "Guest Configuration", effectType "AuditIfNotExists" or "Audit"
350
350
foreach ( var policyDef in policyDefinitionsForTheInitiative )
351
351
{
352
- var policyRule = JObject . Parse ( policyDef . PolicyRule . ToString ( ) ) ;
353
- var policyRuleDictionary = policyRule . ToObject < Dictionary < string , object > > ( ) ;
352
+ try
353
+ {
354
+ var policyRule = JObject . Parse ( policyDef . PolicyRule . ToString ( ) ) ;
355
+ var policyRuleDictionary = policyRule . ToObject < Dictionary < string , object > > ( ) ;
354
356
355
- var policyRuleThen = JObject . Parse ( policyRuleDictionary [ "then" ] . ToString ( ) ) ;
356
- var policyRuleThenDictionary = policyRuleThen . ToObject < Dictionary < string , object > > ( ) ;
357
+ var policyRuleThen = JObject . Parse ( policyRuleDictionary [ "then" ] . ToString ( ) ) ;
358
+ var policyRuleThenDictionary = policyRuleThen . ToObject < Dictionary < string , object > > ( ) ;
357
359
358
- var effectType = policyRuleThenDictionary [ "effect" ] . ToString ( ) ;
359
- var effectTypeLower = effectType . ToLower ( ) ;
360
+ var effectType = policyRuleThenDictionary [ "effect" ] . ToString ( ) ;
361
+ var effectTypeLower = effectType . ToLower ( ) ;
360
362
361
- if ( Constants . AuditIfNotExists != effectTypeLower && Constants . Audit != effectTypeLower )
362
- {
363
- continue ;
364
- }
363
+ if ( Constants . AuditIfNotExists != effectTypeLower && Constants . Audit != effectTypeLower )
364
+ {
365
+ continue ;
366
+ }
365
367
366
- var policyMetadata = JObject . Parse ( policyDef . Metadata . ToString ( ) ) ;
367
- var policyMetadataDictionary = policyMetadata . ToObject < Dictionary < string , object > > ( ) ;
368
- var policyCategory = policyMetadataDictionary [ "category" ] . ToString ( ) . ToLower ( ) ;
369
- if ( Constants . GuestConfigurationCategory != policyCategory )
370
- {
371
- continue ;
372
- }
368
+ var policyMetadata = JObject . Parse ( policyDef . Metadata . ToString ( ) ) ;
369
+ var policyMetadataDictionary = policyMetadata . ToObject < Dictionary < string , object > > ( ) ;
370
+ var policyCategory = policyMetadataDictionary [ "category" ] . ToString ( ) . ToLower ( ) ;
371
+ if ( Constants . GuestConfigurationCategory != policyCategory )
372
+ {
373
+ continue ;
374
+ }
373
375
374
- string guestConfigurationAssignmentNameInPolicy = null ;
376
+ string guestConfigurationAssignmentNameInPolicy = null ;
375
377
376
- if ( Constants . AuditIfNotExists == effectTypeLower )
377
- {
378
- var policyRuleThenDetails = JObject . Parse ( policyRuleThenDictionary [ "details" ] . ToString ( ) ) ;
379
- var policyRuleDetailsDictionary = policyRuleThenDetails . ToObject < Dictionary < string , object > > ( ) ;
380
- guestConfigurationAssignmentNameInPolicy = policyRuleDetailsDictionary [ "name" ] . ToString ( ) ;
381
- }
382
- else if ( Constants . Audit == effectTypeLower )
383
- {
384
- var policyRuleIf = JObject . Parse ( policyRuleDictionary [ "if" ] . ToString ( ) ) ;
385
- var policyRuleIfDictionary = policyRuleIf . ToObject < Dictionary < string , object > > ( ) ;
386
- var policyRuleIfAllOf = policyRuleIfDictionary [ "allOf" ] ;
387
- var policyRuleIfAllOfJArray = JArray . FromObject ( policyRuleIfAllOf ) ;
388
- var guestConfigurationAssignmentNameInPolicyArray = policyRuleIfAllOfJArray . Single (
389
- x => x . Value < string > ( "field" ) == "name"
390
- ) ;
391
- guestConfigurationAssignmentNameInPolicy = guestConfigurationAssignmentNameInPolicyArray . Value < string > ( "equals" ) ;
392
- }
378
+ if ( Constants . AuditIfNotExists == effectTypeLower )
379
+ {
380
+ var policyRuleThenDetails = JObject . Parse ( policyRuleThenDictionary [ "details" ] . ToString ( ) ) ;
381
+ var policyRuleDetailsDictionary = policyRuleThenDetails . ToObject < Dictionary < string , object > > ( ) ;
382
+ guestConfigurationAssignmentNameInPolicy = policyRuleDetailsDictionary [ "name" ] . ToString ( ) ;
383
+ }
384
+ else if ( Constants . Audit == effectTypeLower )
385
+ {
386
+ var policyRuleIf = JObject . Parse ( policyRuleDictionary [ "if" ] . ToString ( ) ) ;
387
+ var policyRuleIfDictionary = policyRuleIf . ToObject < Dictionary < string , object > > ( ) ;
388
+ var policyRuleIfAllOf = policyRuleIfDictionary [ "allOf" ] ;
389
+ var policyRuleIfAllOfJArray = JArray . FromObject ( policyRuleIfAllOf ) ;
390
+ var guestConfigurationAssignmentNameInPolicyArray = policyRuleIfAllOfJArray . Single (
391
+ x => x . Value < string > ( "field" ) == "name"
392
+ ) ;
393
+ guestConfigurationAssignmentNameInPolicy = guestConfigurationAssignmentNameInPolicyArray . Value < string > ( "equals" ) ;
394
+ }
393
395
394
- if ( ! string . IsNullOrEmpty ( guestConfigurationAssignmentNameInPolicy ) && gcrp_AssignmentName_Assignment_Map . ContainsKey ( guestConfigurationAssignmentNameInPolicy ) )
395
- {
396
- var gcrpAsgnment = gcrp_AssignmentName_Assignment_Map [ guestConfigurationAssignmentNameInPolicy ] ;
397
- if ( gcrpAsgnment != null )
396
+ if ( ! string . IsNullOrEmpty ( guestConfigurationAssignmentNameInPolicy ) && gcrp_AssignmentName_Assignment_Map . ContainsKey ( guestConfigurationAssignmentNameInPolicy ) )
398
397
{
399
- gcPolicyAssignmentsList . Add ( new PolicyData ( gcrpAsgnment , policyDef . DisplayName ) ) ;
398
+ var gcrpAsgnment = gcrp_AssignmentName_Assignment_Map [ guestConfigurationAssignmentNameInPolicy ] ;
399
+ if ( gcrpAsgnment != null )
400
+ {
401
+ gcPolicyAssignmentsList . Add ( new PolicyData ( gcrpAsgnment , policyDef . DisplayName ) ) ;
402
+ }
400
403
}
401
404
}
405
+ catch ( Exception )
406
+ {
407
+ this . WriteWarning ( string . Format ( StringResources . InvalidPolicyDefinition , policyDef . DisplayName ) ) ;
408
+ continue ;
409
+ }
402
410
}
403
411
}
404
412
return gcPolicyAssignmentsList ;
0 commit comments