Skip to content

Commit 0c41047

Browse files
committed
small fixes
1 parent 957a272 commit 0c41047

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Caching.Memory;
4+
5+
namespace Nager.AuthenticationService.WebApi.Controllers
6+
{
7+
/// <summary>
8+
/// Monitoring Controller
9+
/// </summary>
10+
[ApiController]
11+
[ApiExplorerSettings(GroupName = "monitoring")]
12+
[Authorize]
13+
[Route("auth/api/v1/[controller]")]
14+
public class MonitoringController : ControllerBase
15+
{
16+
private readonly ILogger<MonitoringController> _logger;
17+
private readonly IMemoryCache _memoryCache;
18+
19+
/// <summary>
20+
/// Monitoring Controller
21+
/// </summary>
22+
/// <param name="logger"></param>
23+
/// <param name="memoryCache"></param>
24+
public MonitoringController(
25+
ILogger<MonitoringController> logger,
26+
IMemoryCache memoryCache)
27+
{
28+
this._logger = logger;
29+
this._memoryCache = memoryCache;
30+
}
31+
32+
/// <summary>
33+
/// Get Cache Keys
34+
/// </summary>
35+
/// <returns></returns>
36+
[HttpGet]
37+
[Authorize(Roles = "administrator")]
38+
[Route("Cache")]
39+
[ProducesResponseType(StatusCodes.Status200OK)]
40+
[ProducesResponseType(StatusCodes.Status204NoContent)]
41+
public async Task<ActionResult> GetAllCacheKeys(
42+
CancellationToken cancellationToken = default)
43+
{
44+
if (this._memoryCache is MemoryCache memoryCache)
45+
{
46+
var statistic = new List<string>();
47+
48+
foreach (var key in memoryCache.Keys)
49+
{
50+
this._memoryCache.TryGetValue<int>(key, out int value);
51+
52+
statistic.Add($"{key}:{value}");
53+
}
54+
55+
return StatusCode(StatusCodes.Status200OK, statistic);
56+
}
57+
58+
return StatusCode(StatusCodes.Status204NoContent);
59+
}
60+
}
61+
}

src/Backend/Nager.AuthenticationService.WebApi/Nager.AuthenticationService.WebApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageReference Include="GoogleAuthenticator" Version="3.2.0" />
1212
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
1415
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
1516
</ItemGroup>
1617

src/Backend/Nager.AuthenticationService.WebApi/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@
146146
Contact = null,
147147
Version = "v1"
148148
});
149+
150+
configuration.SwaggerDoc("monitoring", new OpenApiInfo
151+
{
152+
Title = "Monitoring Documentation",
153+
Description = "Monitoring",
154+
Contact = null,
155+
Version = "v1"
156+
});
149157
});
150158

151159
var app = builder.Build();
@@ -194,9 +202,11 @@
194202
configuration.RoutePrefix = "auth/swagger";
195203
configuration.EnableTryItOutByDefault();
196204
configuration.DisplayRequestDuration();
205+
197206
configuration.SwaggerEndpoint("authentication/swagger.json", "Authentication");
198207
configuration.SwaggerEndpoint("usermanagement/swagger.json", "UserManagement");
199208
configuration.SwaggerEndpoint("useraccount/swagger.json", "UserAccount");
209+
configuration.SwaggerEndpoint("monitoring/swagger.json", "Monitoring");
200210
});
201211
}
202212

0 commit comments

Comments
 (0)