Skip to content

Commit

Permalink
.net8
Browse files Browse the repository at this point in the history
  • Loading branch information
vicosanz committed May 24, 2024
1 parent 0affc26 commit badd1ab
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 117 deletions.
55 changes: 13 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,27 @@ on:
branches:
- master # Default release branch
jobs:
publish:
name: build, pack & publish
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4.1.1

- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore

# Publish
- name: publish on version change Infoware.EntityFrameworkCore.AuditEntity
id: publish_nuget_infoware_entityframeworkcore_auditentity
uses: vicosanz/publish-nuget@v2.5.7
with:
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: Infoware.EntityFrameworkCore.AuditEntity/Infoware.EntityFrameworkCore.AuditEntity.csproj

# NuGet package id, used for version detection & defaults to project name
# PACKAGE_NAME: Core

# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props

# Regex pattern to extract version info in a capturing group
# VERSION_REGEX: ^\s*<Version>(.*)<\/Version>\s*$

# Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX
# VERSION_STATIC: 1.0.0

# Flag to toggle git tagging, enabled by default
# TAG_COMMIT: true

# Format of the git tag, [*] gets replaced with actual version
# TAG_FORMAT: v*
TAG_FORMAT: '*'

# API key to authenticate with NuGet server
# NUGET_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
- name: Build
run: dotnet build ci.slnf --configuration Release

- name: Test
run: dotnet test

# NuGet server uri hosting the packages, defaults to https://api.nuget.org
NUGET_SOURCE: https://api.nuget.org
- name: Pack
run: dotnet pack ci.slnf --include-symbols -property:SymbolPackageFormat=snupkg -property:NuspecFile= --configuration Release --no-build --no-restore --output .

# Flag to toggle pushing symbols along with nuget package to the server, disabled by default
INCLUDE_SYMBOLS: true

- name: Push to Nuget
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
3 changes: 2 additions & 1 deletion Infoware.EntityFrameworkCore.AuditEntity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infoware.EntityFrameworkCor
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C9B060E1-E66D-4062-A7D0-E8EA78CDA3B2}"
ProjectSection(SolutionItems) = preProject
ci.slnf = ci.slnf
.github\workflows\main.yml = .github\workflows\main.yml
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{B13051FA-BBD1-41A5-A7FB-C9C08733C4DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{B13051FA-BBD1-41A5-A7FB-C9C08733C4DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
42 changes: 12 additions & 30 deletions Infoware.EntityFrameworkCore.AuditEntity/BaseAuditInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

namespace Infoware.EntityFrameworkCore.AuditEntity
{
public abstract class BaseAuditInterceptor : SaveChangesInterceptor
{
private readonly ILogJsonSerializer _logJsonSerializer;
private List<EntityEntry<IAuditable>> addeds = new();
private List<EntityEntry<IAuditable>> addeds = [];

public BaseAuditInterceptor(ILogJsonSerializer logJsonSerializer)
{
_logJsonSerializer = logJsonSerializer;
}
public BaseAuditInterceptor(ILogJsonSerializer logJsonSerializer) => _logJsonSerializer = logJsonSerializer;

public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData,
InterceptionResult<int> result,
Expand Down Expand Up @@ -113,7 +104,7 @@ private void WriteHistoryAddedState(IBaseAudit audit, EntityEntry entry)
{
continue;
}
((IDictionary<string, object?>)json)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : prop.CurrentValue;
((IDictionary<string, object?>)json)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : prop.CurrentValue;
}
}

Expand All @@ -137,21 +128,21 @@ private void WriteHistoryModifiedState(IBaseAudit audit, EntityEntry entry)
{
if (!prop.OriginalValue.Equals(prop.CurrentValue))
{
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : prop.OriginalValue;
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : prop.OriginalValue;
}
else
{
databaseValues ??= entry.GetDatabaseValues();
var originalValue = databaseValues!.GetValue<object>(prop.Metadata.Name);
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : originalValue;
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : originalValue;
}
}
else
{
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : default;
((IDictionary<string, object?>)bef)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : default;
}

((IDictionary<string, object?>)aft)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : prop.CurrentValue!;
((IDictionary<string, object?>)aft)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : prop.CurrentValue!;
}
}

Expand All @@ -169,28 +160,19 @@ private void WriteHistoryDeletedState(IBaseAudit audit, EntityEntry entry)

foreach (var prop in entry.Properties)
{
((IDictionary<string, object?>)json)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? "**SensitiveData**" : prop.OriginalValue;
((IDictionary<string, object?>)json)[prop.Metadata.Name] = IfEntryPropertySensitive(prop, sensitives) ? Constants.SensitiveDataLegend : prop.OriginalValue;
}
audit.Operation = EntityState.Deleted.ToString();
audit.Details = _logJsonSerializer.SerializeObject(json);
}

private static IEnumerable<string> GetSensitiveProperties(EntityEntry entry)
{
return entry.Metadata.ClrType.GetProperties()
private static IEnumerable<string> GetSensitiveProperties(EntityEntry entry) =>
entry.Metadata.ClrType.GetProperties()
.Where(p => p.GetCustomAttributes<SensitiveDataAttribute>(true).Any())
.Select(p => p.Name);
}

private static bool IfEntryPropertySensitive(PropertyEntry prop, IEnumerable<string> sensitives)
{
return sensitives.Contains(prop.Metadata.Name);
}
private static bool IfEntryPropertySensitive(PropertyEntry prop, IEnumerable<string> sensitives) => sensitives.Contains(prop.Metadata.Name);

public virtual Task<IBaseAudit?> InitAuditObject(Type entityAuditType)
{
var result = (IBaseAudit?)Activator.CreateInstance(entityAuditType);
return Task.FromResult(result);
}
public virtual Task<IBaseAudit?> InitAuditObject(Type entityAuditType) => Task.FromResult((IBaseAudit?)Activator.CreateInstance(entityAuditType));
}
}
8 changes: 2 additions & 6 deletions Infoware.EntityFrameworkCore.AuditEntity/IAuditable.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
namespace Infoware.EntityFrameworkCore.AuditEntity
{
public interface IAuditable
{
}
public interface IAuditable;

public interface IAuditable<T> : IAuditable
{
}
public interface IAuditable<T> : IAuditable;
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Authors>Victor Sanchez</Authors>
<Company>Infoware Soluciones</Company>
<Description>Create an individual AuditEntity for selected tables to register changes</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/vicosanz/Infoware.EntityFrameworkCore.AuditEntity</RepositoryUrl>
<Version>1.0.3</Version>
<Version>1.0.5</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Infoware.SensitiveDataLogger" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.24" />
<PackageReference Include="Infoware.SensitiveDataLogger" Version="1.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
</ItemGroup>

</Project>
12 changes: 1 addition & 11 deletions WebApplication1/AuditInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
using Infoware.EntityFrameworkCore.AuditEntity;
using Infoware.SensitiveDataLogger.Attributes;
using Infoware.SensitiveDataLogger.JsonSerializer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WebApplication1.Models;

namespace WebApplication1
{
public class AuditInterceptor : BaseAuditInterceptor
{
public AuditInterceptor(ILogJsonSerializer logJsonSerializer): base(logJsonSerializer) { }
public AuditInterceptor(ILogJsonSerializer logJsonSerializer) : base(logJsonSerializer) { }

public override async Task<IBaseAudit?> InitAuditObject(Type entityAuditType)
{
Expand Down
2 changes: 1 addition & 1 deletion WebApplication1/CustomDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ServiceCollectionExtensions
public static IServiceCollection AddCustomDbContext(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<BlogContext>(
(serviceProvider, options) =>
(serviceProvider, options) =>
{
options.UseSqlServer(configuration["ConnectionStrings:DocumentosElectronicosSRI"], sqlOptions =>
{
Expand Down
3 changes: 1 addition & 2 deletions WebApplication1/Migrations/20231105041501_InitialCreate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

Expand Down
4 changes: 1 addition & 3 deletions WebApplication1/Models/BlogAudit.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Infoware.EntityFrameworkCore.AuditEntity;

namespace WebApplication1.Models
namespace WebApplication1.Models
{
public class BlogAudit : ExtendedBaseAudit<Blog, long>
{
Expand Down
5 changes: 0 additions & 5 deletions WebApplication1/Models/ExtendedBaseAudit.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Infoware.EntityFrameworkCore.AuditEntity;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebApplication1.Models
{
Expand Down
8 changes: 3 additions & 5 deletions WebApplication1/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore;
using WebApplication1.Models;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace WebApplication1.Pages
{
Expand All @@ -26,7 +24,7 @@ public async void OnGet()
Name = "Test",
});

var blog = _blogContext.Blogs.Single(x=> x.Id == 1);
var blog = _blogContext.Blogs.Single(x => x.Id == 1);
if (blog != null)
{
blog.Name = "Test2";
Expand Down
3 changes: 1 addition & 2 deletions WebApplication1/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace WebApplication1.Pages
{
Expand Down
10 changes: 5 additions & 5 deletions WebApplication1/WebApplication1.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Infoware.SensitiveDataLogger" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.24" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.24">
<PackageReference Include="Infoware.SensitiveDataLogger" Version="1.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 8 additions & 0 deletions ci.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"solution": {
"path": "Infoware.EntityFrameworkCore.AuditEntity.sln",
"projects": [
"Infoware.EntityFrameworkCore.AuditEntity\\Infoware.EntityFrameworkCore.AuditEntity.csproj"
]
}
}

0 comments on commit badd1ab

Please sign in to comment.