Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

sunnamed434
Copy link

This new feature replaces paths and involves support for Windows, Linux, macOS

@sandermvanvliet
Copy link
Contributor

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

@sunnamed434
Copy link
Author

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

@sunnamed434
Copy link
Author

Hi @sandermvanvliet!

It's a reminder =)

Copy link
Contributor

@sandermvanvliet sandermvanvliet left a 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
Copy link
Contributor

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)

Copy link
Author

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)]
Copy link
Contributor

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.

Copy link
Author

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>();
Copy link
Contributor

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

Copy link
Author

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)]
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

@sunnamed434 sunnamed434 Mar 4, 2023

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

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

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)]
Copy link
Contributor

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.

Copy link
Author

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;
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to the _keepLastPartOfPath

@sandermvanvliet
Copy link
Contributor

@sunnamed434 thanks for the reminder 😉 Life got in the way...

@sunnamed434
Copy link
Author

sunnamed434 commented Mar 5, 2023

Merge conflicts are resolved now (from master branch)

@sunnamed434
Copy link
Author

@sandermvanvliet Hi! Can you accept PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants