1313// ----------------------------------------------------------------------------------
1414
1515using System ;
16+ using System . Collections ;
1617using System . Collections . Generic ;
1718
1819namespace Microsoft . WindowsAzure . Commands . Common . Sanitizer
1920{
20- public class SanitizerTelemetry
21+ public class DetectedPropertiesInfo : IEnumerable < KeyValuePair < string , HashSet < string > > >
2122 {
22- public bool ShowSecretsWarning { get ; set ; } = false ;
23+ private readonly Dictionary < string , HashSet < string > > _internalProperties ;
24+
25+ public DetectedPropertiesInfo ( )
26+ {
27+ _internalProperties = new Dictionary < string , HashSet < string > > ( ) ;
28+ }
29+
30+ public bool IsEmpty => _internalProperties . Count == 0 ;
31+
32+ public IEnumerable < string > PropertyNames => _internalProperties . Keys ;
33+
34+ public void AddPropertyInfo ( string propertyName , string moniker )
35+ {
36+ if ( ! _internalProperties . TryGetValue ( propertyName , out var propertyInfo ) )
37+ {
38+ propertyInfo = new HashSet < string > ( ) ;
39+ _internalProperties [ propertyName ] = propertyInfo ;
40+ }
2341
24- public bool SecretsDetected { get ; set ; } = false ;
42+ propertyInfo . Add ( moniker ) ;
43+ }
2544
26- public HashSet < string > DetectedProperties { get ; set ; } = new HashSet < string > ( ) ;
45+ public void AddPropertyInfo ( string propertyName , HashSet < string > monikers )
46+ {
47+ if ( ! _internalProperties . TryGetValue ( propertyName , out var propertyInfo ) )
48+ {
49+ propertyInfo = new HashSet < string > ( ) ;
50+ _internalProperties [ propertyName ] = propertyInfo ;
51+ }
2752
28- public bool HasErrorInDetection { get ; set ; } = false ;
53+ propertyInfo . UnionWith ( monikers ) ;
54+ }
55+
56+ public bool ContainsProperty ( string propertyName )
57+ {
58+ return _internalProperties . ContainsKey ( propertyName ) ;
59+ }
60+
61+ public IEnumerator < KeyValuePair < string , HashSet < string > > > GetEnumerator ( )
62+ {
63+ return _internalProperties . GetEnumerator ( ) ;
64+ }
65+
66+ IEnumerator IEnumerable . GetEnumerator ( )
67+ {
68+ return GetEnumerator ( ) ;
69+ }
70+ }
71+
72+ public class SanitizerTelemetry
73+ {
74+ public bool ShowSecretsWarning { get ; set ; }
75+
76+ public bool SecretsDetected { get ; set ; }
77+
78+ public bool HasErrorInDetection { get ; set ; }
2979
3080 public Exception DetectionError { get ; set ; }
3181
3282 public TimeSpan SanitizeDuration { get ; set ; }
3383
84+ public DetectedPropertiesInfo DetectedProperties { get ; private set ; }
85+
3486 public SanitizerTelemetry ( bool showSecretsWarning )
3587 {
3688 ShowSecretsWarning = showSecretsWarning ;
89+ SecretsDetected = false ;
90+ HasErrorInDetection = false ;
91+ DetectedProperties = new DetectedPropertiesInfo ( ) ;
3792 }
3893
3994 public void Combine ( SanitizerTelemetry telemetry )
@@ -42,10 +97,13 @@ public void Combine(SanitizerTelemetry telemetry)
4297 {
4398 ShowSecretsWarning = ShowSecretsWarning || telemetry . ShowSecretsWarning ;
4499 SecretsDetected = SecretsDetected || telemetry . SecretsDetected ;
45- DetectedProperties . UnionWith ( telemetry . DetectedProperties ) ;
46100 HasErrorInDetection = HasErrorInDetection || telemetry . HasErrorInDetection ;
47101 DetectionError = DetectionError ?? telemetry . DetectionError ;
48102 SanitizeDuration += telemetry . SanitizeDuration ;
103+ foreach ( var property in telemetry . DetectedProperties )
104+ {
105+ DetectedProperties . AddPropertyInfo ( property . Key , property . Value ) ;
106+ }
49107 }
50108 }
51109 }
0 commit comments