Skip to content

Commit 89c0115

Browse files
Make it work using comma separated string
1 parent fcee321 commit 89c0115

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

src/Serilog.Enrichers.Sensitive/MaskPropertyCollection.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Collections.Generic;
1+
using System.Collections;
2+
using System.Collections.Generic;
23

34
namespace Serilog.Enrichers.Sensitive;
45

5-
public class MaskPropertyCollection : List<MaskProperty>
6+
public class MaskPropertyCollection : IEnumerable<string>
67
{
78
private readonly Dictionary<string, MaskOptions> _properties = new();
89

@@ -32,4 +33,14 @@ public static MaskPropertyCollection From(IEnumerable<string> enricherOptionsMas
3233

3334
return collection;
3435
}
36+
37+
public IEnumerator<string> GetEnumerator()
38+
{
39+
return _properties.Keys.GetEnumerator();
40+
}
41+
42+
IEnumerator IEnumerable.GetEnumerator()
43+
{
44+
return GetEnumerator();
45+
}
3546
}

src/Serilog.Enrichers.Sensitive/SensitiveDataEnricher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public SensitiveDataEnricher(
3333
MaskingMode.Globally,
3434
DefaultMaskValue,
3535
DefaultOperators.Select(o => o.GetType().AssemblyQualifiedName),
36-
new List<string>(),
36+
_maskProperties != null ? string.Join(",", _maskProperties) : null,
3737
new List<string>());
3838

3939
if (options != null)

src/Serilog.Enrichers.Sensitive/SensitiveDataEnricherOptions.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public SensitiveDataEnricherOptions(
1818
MaskingMode mode = MaskingMode.Globally,
1919
string maskValue = SensitiveDataEnricher.DefaultMaskValue,
2020
IEnumerable<string>? maskingOperators = null,
21-
IEnumerable<string>? maskProperties = null,
21+
string? maskProperties = null,
2222
IEnumerable<string>? excludeProperties = null,
2323
// ReSharper disable once UnusedParameter.Local as this only exists to support JSON configuration, see the Operators property below
2424
IEnumerable<string>? operators = null)
2525
{
2626
Mode = mode;
2727
MaskValue = maskValue;
2828
MaskingOperators = maskingOperators == null ? new List<IMaskingOperator>() : ResolveMaskingOperators(maskingOperators);
29-
MaskProperties = maskProperties == null ? new MaskPropertyCollection() : MaskPropertyCollection.From(maskProperties);
29+
MaskProperties = maskProperties == null ? new MaskPropertyCollection() : MaskPropertyCollection.From(maskProperties?.Split(',') ?? []);
3030
ExcludeProperties = excludeProperties?.ToList() ?? new List<string>();
3131
}
3232

@@ -130,19 +130,4 @@ public void Apply(SensitiveDataEnricherOptions other)
130130
other.Operators = Operators;
131131
}
132132
}
133-
134-
public class MaskProperty
135-
{
136-
public MaskProperty()
137-
{
138-
}
139-
140-
public MaskProperty(string propertyName)
141-
{
142-
Name = propertyName;
143-
}
144-
145-
public string Name { get; set; }
146-
public MaskOptions Options { get; set; } = MaskOptions.Default;
147-
}
148133
}

test/Serilog.Enrichers.Sensitive.Tests.Unit/enricher-config.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"Args": {
1010
"options": {
1111
"MaskValue": "**SECRET**",
12-
"MaskProperties": [
13-
"secret"
14-
]
12+
"MaskProperties": "secret"
1513
}
1614
}
1715
}

0 commit comments

Comments
 (0)