-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from damienbod/dev
Update .NET 8 and elastic Nuget package
- Loading branch information
Showing
108 changed files
with
75,352 additions
and
936 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 57 additions & 56 deletions
113
AspNetCoreElasticsearchNestAuditTrail.sln → AspNetCoreElasticsearchAuditTrail.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,57 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26206.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreElasticsearchNestAuditTrail", "AspNetCoreElasticsearchNestAuditTrail\AspNetCoreElasticsearchNestAuditTrail.csproj", "{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuditTrail", "AuditTrail\AuditTrail.csproj", "{C6225C51-6B38-429C-B9C3-CCE1716779AE}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00A97214-B91A-4C81-AB9D-7980AB63592C}" | ||
ProjectSection(SolutionItems) = preProject | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x64.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x86.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x64.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x64.Build.0 = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x86.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x86.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x64.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x86.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x64.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x64.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x86.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2D2223FB-A41A-4CC2-B33B-4BB37B993AD2} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.10.35201.131 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreElasticsearchAuditTrail", "AspNetCoreElasticsearchAuditTrail\AspNetCoreElasticsearchAuditTrail.csproj", "{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuditTrail", "AuditTrail\AuditTrail.csproj", "{C6225C51-6B38-429C-B9C3-CCE1716779AE}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00A97214-B91A-4C81-AB9D-7980AB63592C}" | ||
ProjectSection(SolutionItems) = preProject | ||
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x64.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Debug|x86.Build.0 = Debug|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x64.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x64.Build.0 = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x86.ActiveCfg = Release|Any CPU | ||
{EDFF2892-F9D3-45BF-BFBE-8E690FCE3C6C}.Release|x86.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x64.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Debug|x86.Build.0 = Debug|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x64.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x64.Build.0 = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x86.ActiveCfg = Release|Any CPU | ||
{C6225C51-6B38-429C-B9C3-CCE1716779AE}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2D2223FB-A41A-4CC2-B33B-4BB37B993AD2} | ||
EndGlobalSection | ||
EndGlobal |
14 changes: 14 additions & 0 deletions
14
AspNetCoreElasticsearchAuditTrail/AspNetCoreElasticsearchAuditTrail.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>55293f05-ec3d-4665-9e84-0e57a4a7b49b</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AuditTrail\AuditTrail.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
121 changes: 121 additions & 0 deletions
121
AspNetCoreElasticsearchAuditTrail/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using AspNetCoreElasticsearchAuditTrail.ViewModels; | ||
using AuditTrail; | ||
using AuditTrail.Model; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AspNetCoreElasticsearchAuditTrail.Controllers; | ||
|
||
public class HomeController(IAuditTrailProvider<CustomAuditTrailLog> auditTrailProvider) : Controller | ||
{ | ||
private readonly IAuditTrailProvider<CustomAuditTrailLog> _auditTrailProvider = auditTrailProvider; | ||
|
||
public IActionResult Index() | ||
{ | ||
var auditTrailLog = new CustomAuditTrailLog() | ||
{ | ||
User = GetUserName(), | ||
Origin = "HomeController:Index", | ||
Action = "Home GET", | ||
Log = "home page called doing something important enough to be added to the audit log.", | ||
Extra = "yep" | ||
}; | ||
|
||
_auditTrailProvider.AddLog(auditTrailLog); | ||
return View(); | ||
} | ||
|
||
public async Task<IActionResult> AuditTrailAsync() | ||
{ | ||
var auditTrailLog = new CustomAuditTrailLog() | ||
{ | ||
User = GetUserName(), | ||
Origin = "HomeController:AuditTrailAsync", | ||
Action = "AuditTrailAsync GET", | ||
Log = "user clicked the audit trail nav." | ||
}; | ||
|
||
await _auditTrailProvider.AddLog(auditTrailLog); | ||
ViewData["Message"] = "Your application description page."; | ||
|
||
var auditTrailViewModel = new AuditTrailViewModel | ||
{ | ||
AuditTrailLogs = (await _auditTrailProvider.QueryAuditLogs()).ToList(), | ||
Filter = "*", | ||
Skip = 0, | ||
Size = 10 | ||
}; | ||
return View(auditTrailViewModel); | ||
} | ||
|
||
public async Task<IActionResult> AuditTrailSearchAsync(string searchString, int skip, int amount) | ||
{ | ||
var auditTrailLog = new CustomAuditTrailLog() | ||
{ | ||
User = GetUserName(), | ||
Origin = "HomeController:AuditTrailSearchAsync", | ||
Action = "AuditTrailSearchAsync GET", | ||
Log = $"user clicked the audit trail nav. {searchString}" | ||
}; | ||
|
||
await _auditTrailProvider.AddLog(auditTrailLog); | ||
|
||
var auditTrailViewModel = new AuditTrailViewModel | ||
{ | ||
Filter = searchString, | ||
Skip = skip, | ||
Size = amount | ||
}; | ||
|
||
if (skip > 0 || amount > 0) | ||
{ | ||
var paging = new AuditTrailPaging | ||
{ | ||
Size = amount, | ||
Skip = skip | ||
}; | ||
|
||
auditTrailViewModel.AuditTrailLogs = (await _auditTrailProvider.QueryAuditLogs(searchString, paging)).ToList(); | ||
|
||
return View(auditTrailViewModel); | ||
} | ||
|
||
auditTrailViewModel.AuditTrailLogs = (await _auditTrailProvider.QueryAuditLogs(searchString)).ToList(); | ||
return View(auditTrailViewModel); | ||
} | ||
|
||
public IActionResult Contact() | ||
{ | ||
var auditTrailLog = new CustomAuditTrailLog() | ||
{ | ||
User = GetUserName(), | ||
Origin = "HomeController:Contact", | ||
Action = "Contact GET", | ||
Log = "user clicked the contact nav." | ||
}; | ||
|
||
_auditTrailProvider.AddLog(auditTrailLog); | ||
ViewData["Message"] = "Your contact page."; | ||
|
||
return View(); | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
var auditTrailLog = new CustomAuditTrailLog() | ||
{ | ||
User = GetUserName(), | ||
Origin = "HomeController:Error", | ||
Action = "Error GET", | ||
Log = "something has gone wrong" | ||
}; | ||
|
||
_auditTrailProvider.AddLog(auditTrailLog); | ||
ViewData["Message"] = "Your contact page."; | ||
return View(); | ||
} | ||
|
||
private string GetUserName() | ||
{ | ||
return User.Identity!.Name ?? "Anonymous"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AuditTrail.Model; | ||
|
||
namespace AspNetCoreElasticsearchAuditTrail; | ||
|
||
public class CustomAuditTrailLog : IAuditTrailLog | ||
{ | ||
public CustomAuditTrailLog() | ||
{ | ||
Timestamp = DateTime.UtcNow; | ||
} | ||
|
||
public DateTime Timestamp { get; set; } | ||
|
||
// TODO add elastic keyword definition for the property | ||
//[Keyword] | ||
public string Action { get; set; } = string.Empty; | ||
public string Log { get; set; } = string.Empty; | ||
public string Origin { get; set; } = string.Empty; | ||
public string User { get; set; } = string.Empty; | ||
public string Extra { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace AspNetCoreElasticsearchAuditTrail.Models; | ||
|
||
public class ErrorViewModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using AspNetCoreElasticsearchAuditTrail; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
var indexPerMonth = false; | ||
var amountOfPreviousIndicesUsedInAlias = 3; | ||
|
||
builder.Services.AddAuditTrail<CustomAuditTrailLog>(options => | ||
options.UseSettings(indexPerMonth, | ||
amountOfPreviousIndicesUsedInAlias, | ||
builder.Configuration["ElasticsearchUserName"], | ||
builder.Configuration["ElasearchPassword"], | ||
builder.Configuration["ElasearchUrl"]) | ||
); | ||
|
||
builder.Services.AddControllersWithViews(); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
app.UseHsts(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
app.UseRouting(); | ||
app.UseAuthorization(); | ||
|
||
app.MapControllerRoute( | ||
name: "default", | ||
pattern: "{controller=Home}/{action=Index}/{id?}"); | ||
|
||
app.Run(); |
52 changes: 26 additions & 26 deletions
52
...AuditTrail/Properties/launchSettings.json → ...AuditTrail/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "https://localhost:44343/", | ||
"sslPort": 44343 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"AspNetCoreElasticsearchNestAuditTrail": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:3787" | ||
} | ||
} | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "https://localhost:44343/", | ||
"sslPort": 44343 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"AspNetCoreElasticsearchAuditTrail": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:5005" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
AspNetCoreElasticsearchAuditTrail/ViewModels/AuditTrailViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
| ||
namespace AspNetCoreElasticsearchAuditTrail.ViewModels; | ||
|
||
public class AuditTrailViewModel | ||
{ | ||
public List<CustomAuditTrailLog> AuditTrailLogs { get; set; } = []; | ||
public int Size { get; set; } | ||
public int Skip { get; set; } | ||
public string Filter { get; set; } = "*"; | ||
} |
Oops, something went wrong.