13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using System ;
16
+ using System . Collections ;
16
17
using System . Collections . Generic ;
17
18
18
19
namespace Microsoft . WindowsAzure . Commands . Common . Sanitizer
19
20
{
20
- public class SanitizerTelemetry
21
+ public class DetectedPropertiesInfo : IEnumerable < KeyValuePair < string , HashSet < string > > >
21
22
{
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
+ }
23
41
24
- public bool SecretsDetected { get ; set ; } = false ;
42
+ propertyInfo . Add ( moniker ) ;
43
+ }
25
44
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
+ }
27
52
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 ; }
29
79
30
80
public Exception DetectionError { get ; set ; }
31
81
32
82
public TimeSpan SanitizeDuration { get ; set ; }
33
83
84
+ public DetectedPropertiesInfo DetectedProperties { get ; private set ; }
85
+
34
86
public SanitizerTelemetry ( bool showSecretsWarning )
35
87
{
36
88
ShowSecretsWarning = showSecretsWarning ;
89
+ SecretsDetected = false ;
90
+ HasErrorInDetection = false ;
91
+ DetectedProperties = new DetectedPropertiesInfo ( ) ;
37
92
}
38
93
39
94
public void Combine ( SanitizerTelemetry telemetry )
@@ -42,10 +97,13 @@ public void Combine(SanitizerTelemetry telemetry)
42
97
{
43
98
ShowSecretsWarning = ShowSecretsWarning || telemetry . ShowSecretsWarning ;
44
99
SecretsDetected = SecretsDetected || telemetry . SecretsDetected ;
45
- DetectedProperties . UnionWith ( telemetry . DetectedProperties ) ;
46
100
HasErrorInDetection = HasErrorInDetection || telemetry . HasErrorInDetection ;
47
101
DetectionError = DetectionError ?? telemetry . DetectionError ;
48
102
SanitizeDuration += telemetry . SanitizeDuration ;
103
+ foreach ( var property in telemetry . DetectedProperties )
104
+ {
105
+ DetectedProperties . AddPropertyInfo ( property . Key , property . Value ) ;
106
+ }
49
107
}
50
108
}
51
109
}
0 commit comments