-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature pathmask #27
base: master
Are you sure you want to change the base?
Feature pathmask #27
Conversation
Hi @sunnamed434! Thank you for your PR 👍 Just to manage expectations: I’ll review it soon but can’t promise it’ll be tomorrow 😉 Feel free to remind me if you haven’t heard from me in a few days |
Hi, Yes, sure, I'll remind |
Hi @sandermvanvliet! It's a reminder =) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this extra operator and I suspect there will be many folks that find it useful.
I've added a few comments, overall it looks good but there are some tweaks to make it better 👍
@@ -102,6 +102,7 @@ By default the enricher uses the following masking operators: | |||
- EmailAddressMaskingOperator | |||
- IbanMaskingOperator | |||
- CreditCardMaskingOperator | |||
- PathMaskingOperator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the default operators when I built this library was a bit of a mistake.
Could you remove it from the docs here? (I see you didn't actually add it to the list of default operators)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the default list of operators
|
||
namespace Serilog.Enrichers.Sensitive.Tests.Benchmark; | ||
|
||
[SimpleJob(RunStrategy.Throughput, warmupCount: 1)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing benchmark for regexes already proves a compiled regex is faster so adding another benchmark to prove it again isn't necessary.
You can remove this class altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class removed
@@ -9,6 +9,7 @@ private static void Main(string[] args) | |||
BenchmarkRunner.Run<BenchmarkCompiledEmailRegex>(); | |||
BenchmarkRunner.Run<BenchmarkCompiledIbanRegex>(); | |||
BenchmarkRunner.Run<CreditCardMarkingBenchmarks>(); | |||
BenchmarkRunner.Run<PathMaskingOperatorBenchmarks>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed also
[InlineData(@"C:\Users\Admin\Secret\Hidden", @"***\Hidden", true)] | ||
[InlineData(@"C:\Users\Admin\Secret", @"***\Secret", true)] | ||
[InlineData(@"C:\Users\", @"***\Users", true)] | ||
[InlineData(@"/home/i_use_arch_linux_btw", @"***\i_use_arch_linux_btw", true)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me laugh 😄
|
||
namespace Serilog.Enrichers.Sensitive; | ||
|
||
public class PathWrapper : IPathWrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly recommend to remove this abstraction, it's not adding any value right now as there is no other implementation of IPathWrapper
and the methods you are using do not actually depend on the filesystem being available.
So I'd prefer that where you're calling _pathWrapper.GetDirectoryName()
, just call Path.GetDIrectoryName
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I made such abstraction, cuz I thought if there's a specific when some of the OS unable to get the path properly, then developer might make it own implementation. In case if this feature with abstraction would be removed and If I were such developer, I'd just delete the package and go cry. Let me know if this is still should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, Path.GetDIrectoryName works weird, sometimes It's unable to get the directory name correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand where you're coming from, however you may expect from the runtime to handle this for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now path wrapper removed
/// <summary> | ||
/// Initializes a new instance of the <see cref="PathMaskingOperator"/> class. | ||
/// </summary> | ||
public PathMaskingOperator() : this(combineMaskWithPath: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor isn't necessary as the one you are calling has a default value for the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty ctor removed
/// </summary> | ||
/// <param name="pathWrapper">The path wrapper.</param> | ||
/// <param name="combineMaskWithPath">This means if set to <see langword="true"/> then the mask will combine with the file name or its directory name.</param> | ||
public PathMaskingOperator(IPathWrapper pathWrapper, bool combineMaskWithPath = true) : base(PathPattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the IPathWrapper
abstraction isn't necessary (see my other comment below) you can simplify this constructor after inlining the Path.*
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now path wrapper removed
private const string Mask = @"***\"; | ||
|
||
[Theory] | ||
[InlineData(@"C:\Users\Admin\Secret\File.dll", @"***\", false)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this to be only the mask in the expected output. Right now it looks like you're keeping the directory separator which seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't really understand what do you mean
public class PathMaskingOperator : RegexMaskingOperator | ||
{ | ||
private readonly IPathWrapper _pathWrapper; | ||
private readonly bool _combineMaskWithPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to figure out exactly what this meant. Perhaps changing it to _keepLastPartOfPath
or _doNotMaskLastPartOfPath
would be more descriptive and easier to understand for consumers of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to the _keepLastPartOfPath
@sunnamed434 thanks for the reminder 😉 Life got in the way... |
Merge conflicts are resolved now (from master branch) |
@sandermvanvliet Hi! Can you accept PR? |
This new feature replaces paths and involves support for Windows, Linux, macOS