Skip to content

Commit

Permalink
Merge pull request #130 from airbrake/RenameFilterParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rbalabukh authored Jul 10, 2020
2 parents bc05c28 + c3fd492 commit 9560c41
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Key features
* Support for environments<sup>[[link](#environment)]</sup>
* Support for proxying<sup>[[link](#proxy)]</sup>
* Filters support (filter out sensitive or unwanted data that shouldn't be sent
to our servers)<sup>[[link](#blacklistkeys)]</sup>
to our servers)<sup>[[link](#blocklist)]</sup>
* Ability to ignore errors from specified environments<sup>[[link](#ignoreenvironments)]</sup>
* Severity support<sup>[[link](#setting-severity)]</sup>

Expand Down Expand Up @@ -269,15 +269,15 @@ var config = new AirbrakeConfig {
};
```

#### BlacklistKeys
#### Blocklist

Specifies which keys in the payload (parameters, session data, environment data,
etc.) should be filtered. Before sending an error, filtered keys will be
substituted with the `[Filtered]` label.

```csharp
var config = new AirbrakeConfig {
BlacklistKeys = new List<string> { "password", "creditCard", "email" }
Blocklist = new List<string> { "password", "creditCard", "email" }
};

// The dashboard will display this parameter as filtered, but other values won't
Expand All @@ -288,19 +288,19 @@ var config = new AirbrakeConfig {
// creditCard: '[Filtered]' }
```

**Note:** `BlacklistKeys` has higher priority than `WhitelistKeys`. It means
**Note:** `Blocklist` has higher priority than `Allowlist`. It means
that if you set the same value into both blacklist and whitelist - that value
will be filtered out.

#### WhitelistKeys
#### Allowlist

Specifies which keys in the payload (parameters, session data, environment data,
etc.) should _not_ be filtered. All other keys will be substituted with the
`[Filtered]` label.

```csharp
var config = new AirbrakeConfig {
WhitelistKeys = new List<string> { "user", "email", "accountId" }
Allowlist = new List<string> { "user", "email", "accountId" }
};

// The dashboard will display this parameter as is, but all other values will be
Expand Down
8 changes: 4 additions & 4 deletions src/Sharpbrake.Client/AirbrakeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public class AirbrakeConfig
/// List of the parameters which will not be filtered.
/// If count of parameters is not zero - all not listed parameters will be filtered.
/// </summary>
public IList<string> WhitelistKeys { get; set; }
public IList<string> Allowlist { get; set; }

/// <summary>
/// List of the parameters which will be filtered out.
/// </summary>
public IList<string> BlacklistKeys { get; set; }
public IList<string> Blocklist { get; set; }

/// <summary>
/// Formatting information for error messages.
Expand All @@ -85,8 +85,8 @@ public class AirbrakeConfig
public AirbrakeConfig()
{
IgnoreEnvironments = new List<string>();
WhitelistKeys = new List<string>();
BlacklistKeys = new List<string>();
Allowlist = new List<string>();
Blocklist = new List<string>();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Sharpbrake.Client/NoticeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public static void SetHttpContext(this Notice notice, IHttpContext httpContext,
}
else
{
var blackListRegex = Utils.CompileRegex(config.BlacklistKeys);
var whiteListRegex = Utils.CompileRegex(config.WhitelistKeys);
var blackListRegex = Utils.CompileRegex(config.Blocklist);
var whiteListRegex = Utils.CompileRegex(config.Allowlist);

notice.Params = Utils.FilterParameters(httpContext.Parameters, blackListRegex, whiteListRegex);
notice.EnvironmentVars = Utils.FilterParameters(httpContext.EnvironmentVars, blackListRegex, whiteListRegex);
Expand Down
8 changes: 4 additions & 4 deletions src/Sharpbrake.Log4net/AirbrakeAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public class AirbrakeAppender : AppenderSkeleton
/// Comma-separated list of parameters which will not be filtered.
/// If count of parameters is not zero - all not listed parameters will be filtered.
/// </summary>
public string WhitelistKeys { get; set; }
public string Allowlist { get; set; }

/// <summary>
/// Comma-separated list of parameters which will be filtered out.
/// </summary>
public string BlacklistKeys { get; set; }
public string Blocklist { get; set; }

/// <summary>
/// Initializes the appender based on the options set.
Expand All @@ -97,8 +97,8 @@ public override void ActivateOptions()
ProxyUsername = ProxyUsername,
ProxyPassword = ProxyPassword,
IgnoreEnvironments = Utils.ParseParameter(IgnoreEnvironments),
WhitelistKeys = Utils.ParseParameter(WhitelistKeys),
BlacklistKeys = Utils.ParseParameter(BlacklistKeys)
Allowlist = Utils.ParseParameter(Allowlist),
Blocklist = Utils.ParseParameter(Blocklist)
};

Notifier = new AirbrakeNotifier(config);
Expand Down
40 changes: 20 additions & 20 deletions src/Sharpbrake.NLog/AirbrakeTarget.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using NLog;
using NLog.Config;
using NLog.Layouts;
using NLog.Layouts;
using NLog.Targets;
using Sharpbrake.Client;
using Sharpbrake.Client.Model;
Expand Down Expand Up @@ -74,16 +74,16 @@ public class AirbrakeTarget : TargetWithLayout
/// Comma-separated list of parameters which will not be filtered.
/// If count of parameters is not zero - all not listed parameters will be filtered.
/// </summary>
public string WhitelistKeys { get; set; }
public string Allowlist { get; set; }

/// <summary>
/// Comma-separated list of parameters which will be filtered out.
/// </summary>
public string BlacklistKeys { get; set; }
public string Blocklist { get; set; }

public AirbrakeTarget()
{
Layout = "${message}";
{
Layout = "${message}";
}

/// <summary>
Expand Down Expand Up @@ -132,24 +132,24 @@ protected override void InitializeTarget()
ProxyUsername = RenderSimpleLayout(ProxyUsername, nameof(ProxyUsername)),
ProxyPassword = RenderSimpleLayout(ProxyPassword, nameof(ProxyPassword)),
IgnoreEnvironments = Utils.ParseParameter(RenderSimpleLayout(IgnoreEnvironments, nameof(IgnoreEnvironments))),
WhitelistKeys = Utils.ParseParameter(RenderSimpleLayout(WhitelistKeys, nameof(WhitelistKeys))),
BlacklistKeys = Utils.ParseParameter(RenderSimpleLayout(BlacklistKeys, nameof(BlacklistKeys))),
Allowlist = Utils.ParseParameter(RenderSimpleLayout(Allowlist, nameof(Allowlist))),
Blocklist = Utils.ParseParameter(RenderSimpleLayout(Blocklist, nameof(Blocklist))),
};

Notifier = new AirbrakeNotifier(config);
}

private string RenderSimpleLayout(string simpleLayout, string propertyName)
{
try
{
return string.IsNullOrEmpty(simpleLayout) ? string.Empty : new SimpleLayout(simpleLayout).Render(LogEventInfo.CreateNullEvent());
}
catch
{
return simpleLayout;
}
}
}

private string RenderSimpleLayout(string simpleLayout, string propertyName)
{
try
{
return string.IsNullOrEmpty(simpleLayout) ? string.Empty : new SimpleLayout(simpleLayout).Render(LogEventInfo.CreateNullEvent());
}
catch
{
return simpleLayout;
}
}


/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions test/Sharpbrake.Client.Tests/AirbrakeConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public void Ctor_ShouldInitializeListBasedProperties()

Assert.NotNull(config);
Assert.NotNull(config.IgnoreEnvironments);
Assert.NotNull(config.WhitelistKeys);
Assert.NotNull(config.BlacklistKeys);
Assert.NotNull(config.Allowlist);
Assert.NotNull(config.Blocklist);
}

[Fact]
Expand All @@ -28,7 +28,7 @@ public void Load_ShouldInitializeConfigFromDictionary()
{"Airbrake:ProjectKey", "e2046ca6e4e9214b24ad252e3c99a0f6"},
{"Airbrake:Environment", "test"},
{"IgnoreEnvironments", "test,dev" },
{"BlacklistKeys", "password" },
{"Blocklist", "password" },
{"Environment", "dev"},
{"NonExistingProperty", "value"}
};
Expand All @@ -45,9 +45,9 @@ public void Load_ShouldInitializeConfigFromDictionary()
Assert.True(config.IgnoreEnvironments[0] == "test");
Assert.True(config.IgnoreEnvironments[1] == "dev");

Assert.NotNull(config.BlacklistKeys);
Assert.True(config.BlacklistKeys.Count == 1);
Assert.True(config.BlacklistKeys[0] == "password");
Assert.NotNull(config.Blocklist);
Assert.True(config.Blocklist.Count == 1);
Assert.True(config.Blocklist[0] == "password");
}
}
}

0 comments on commit 9560c41

Please sign in to comment.