Skip to content

Commit 7469dce

Browse files
committed
Add ExcludeWartAttribute
1 parent 823a250 commit 7469dce

File tree

8 files changed

+71
-33
lines changed

8 files changed

+71
-33
lines changed

src/WART-Client/WART-Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.6" />
24+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
2525
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
2626
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
27-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
27+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
2828
</ItemGroup>
2929

3030
</Project>

src/WART-Core/Controllers/WartController.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
using Microsoft.AspNetCore.SignalR;
66
using Microsoft.Extensions.Logging;
77
using System;
8+
using System.Linq;
89
using System.Threading.Tasks;
910
using WART_Core.Entity;
11+
using WART_Core.Filters;
1012
using WART_Core.Hubs;
1113

1214
namespace WART_Core.Controllers
@@ -51,16 +53,21 @@ public override async void OnActionExecuted(ActionExecutedContext context)
5153
{
5254
if (context?.Result is ObjectResult objectResult)
5355
{
54-
// get the request objects from RouteData
55-
var request = context.RouteData.Values[RouteDataKey];
56-
var httpMethod = context.HttpContext?.Request.Method;
57-
var httpPath = context.HttpContext?.Request.Path;
58-
var remoteAddress = context.HttpContext?.Connection.RemoteIpAddress?.ToString();
59-
// get the object response
60-
var response = objectResult.Value;
61-
// create the new WartEvent and broadcast to all clients
62-
var wartEvent = new WartEvent(request, response, httpMethod, httpPath, remoteAddress);
63-
await SendToHub(wartEvent);
56+
// check for wart exclusion
57+
var exclusion = context.Filters.Any(f => f.GetType().Name == nameof(ExcludeWartAttribute));
58+
if (!exclusion)
59+
{
60+
// get the request objects from RouteData
61+
var request = context.RouteData.Values[RouteDataKey];
62+
var httpMethod = context.HttpContext?.Request.Method;
63+
var httpPath = context.HttpContext?.Request.Path;
64+
var remoteAddress = context.HttpContext?.Connection.RemoteIpAddress?.ToString();
65+
// get the object response
66+
var response = objectResult.Value;
67+
// create the new WartEvent and broadcast to all clients
68+
var wartEvent = new WartEvent(request, response, httpMethod, httpPath, remoteAddress);
69+
await SendToHub(wartEvent);
70+
}
6471
}
6572

6673
base.OnActionExecuted(context);
@@ -77,7 +84,7 @@ private async Task SendToHub(WartEvent wartEvent)
7784
{
7885
await _hubContext?.Clients.All.SendAsync("Send", wartEvent.ToString());
7986

80-
_logger?.LogInformation(message: "WartEvent", wartEvent.ToString());
87+
_logger?.LogInformation(message: nameof(WartEvent), wartEvent.ToString());
8188
}
8289
catch (Exception ex)
8390
{

src/WART-Core/Controllers/WartControllerJwt.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System;
99
using WART_Core.Entity;
1010
using WART_Core.Hubs;
11+
using System.Linq;
12+
using WART_Core.Filters;
1113

1214
namespace WART_Core.Controllers
1315
{
@@ -51,16 +53,21 @@ public override async void OnActionExecuted(ActionExecutedContext context)
5153
{
5254
if (context?.Result is ObjectResult objectResult)
5355
{
54-
// get the request objects from RouteData
55-
var request = context.RouteData.Values[RouteDataKey];
56-
var httpMethod = context.HttpContext?.Request.Method;
57-
var httpPath = context.HttpContext?.Request.Path;
58-
var remoteAddress = context.HttpContext?.Connection.RemoteIpAddress?.ToString();
59-
// get the object response
60-
var response = objectResult.Value;
61-
// create the new WartEvent and broadcast to all clients
62-
var wartEvent = new WartEvent(request, response, httpMethod, httpPath, remoteAddress);
63-
await SendToHub(wartEvent);
56+
// check for wart exclusion
57+
var exclusion = context.Filters.Any(f => f.GetType().Name == nameof(ExcludeWartAttribute));
58+
if (!exclusion)
59+
{
60+
// get the request objects from RouteData
61+
var request = context.RouteData.Values[RouteDataKey];
62+
var httpMethod = context.HttpContext?.Request.Method;
63+
var httpPath = context.HttpContext?.Request.Path;
64+
var remoteAddress = context.HttpContext?.Connection.RemoteIpAddress?.ToString();
65+
// get the object response
66+
var response = objectResult.Value;
67+
// create the new WartEvent and broadcast to all clients
68+
var wartEvent = new WartEvent(request, response, httpMethod, httpPath, remoteAddress);
69+
await SendToHub(wartEvent);
70+
}
6471
}
6572

6673
base.OnActionExecuted(context);
@@ -77,7 +84,7 @@ private async Task SendToHub(WartEvent wartEvent)
7784
{
7885
await _hubContext?.Clients.All.SendAsync("Send", wartEvent.ToString());
7986

80-
_logger?.LogInformation(message: "WartEvent", wartEvent.ToString());
87+
_logger?.LogInformation(message: nameof(WartEvent), wartEvent.ToString());
8188
}
8289
catch (Exception ex)
8390
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// (c) 2019 Francesco Del Re <francesco.delre.87@gmail.com>
2+
// This code is licensed under MIT license (see LICENSE.txt for details)
3+
using Microsoft.AspNetCore.Mvc.Filters;
4+
5+
namespace WART_Core.Filters
6+
{
7+
/// <summary>
8+
/// Exclude the API from WART events.
9+
/// </summary>
10+
public class ExcludeWartAttribute : ActionFilterAttribute
11+
{
12+
public override void OnActionExecuting(ActionExecutingContext context)
13+
{
14+
base.OnActionExecuting(context);
15+
}
16+
17+
public override void OnActionExecuted(ActionExecutedContext context)
18+
{
19+
base.OnActionExecuted(context);
20+
}
21+
}
22+
}

src/WART-Core/WART-Core.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
<PackageLicenseExpression></PackageLicenseExpression>
1515
<AssemblyVersion>4.0.0.0</AssemblyVersion>
1616
<FileVersion>4.0.0.0</FileVersion>
17-
<Version>5.3.0</Version>
17+
<Version>5.3.2</Version>
1818
<PackageIcon>icon.png</PackageIcon>
1919
</PropertyGroup>
2020

2121
<ItemGroup>
2222
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2323
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
25-
<PackageReference Include="System.Text.Json" Version="8.0.3" />
24+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
25+
<PackageReference Include="System.Text.Json" Version="8.0.4" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

src/WART-Tests/WART-Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>
18-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
20-
<PackageReference Include="Moq" Version="4.20.70" />
21-
<PackageReference Include="xunit" Version="2.8.1" />
22-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
18+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
20+
<PackageReference Include="Moq" Version="4.20.72" />
21+
<PackageReference Include="xunit" Version="2.9.0" />
22+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
2323
<PrivateAssets>all</PrivateAssets>
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>

src/WART-WebApiRealTime/Controllers/TestController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using WART_Api.Entity;
99
using WART_Core.Controllers;
10+
using WART_Core.Filters;
1011
using WART_Core.Hubs;
1112

1213
namespace WART_Api.Controllers
@@ -36,6 +37,7 @@ public IEnumerable<TestEntity> Get()
3637
}
3738

3839
[HttpGet("{id}")]
40+
[ExcludeWart]
3941
public ActionResult<TestEntity> Get(int id)
4042
{
4143
var item = Items.FirstOrDefault(x => x.Id == id);

src/WART-WebApiRealTime/WART-Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)