Skip to content

Commit 5e56321

Browse files
committed
bump version to 0.2.0
enable gha building and publishing to nuget renamed to Klean.EntityFrameworkCore.DataProtection
1 parent 425fc88 commit 5e56321

22 files changed

+112
-69
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
name: Build and publish
22

33
on:
4-
workflow_dispatch:
5-
# push:
6-
# branches: [ main ]
7-
# pull_request:
8-
# branches: [ main ]
4+
release:
5+
types: [published]
96

107
env:
118
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
129
DOTNET_CLI_TELEMETRY_OPTOUT: true
1310

1411
jobs:
15-
build-library:
12+
build-and-push-on-nuget:
1613
concurrency: ci-${{ github.ref }}
1714
runs-on: ubuntu-latest
1815

@@ -47,8 +44,11 @@ jobs:
4744
- name: Restore 📦
4845
run: dotnet restore --verbosity minimal
4946

47+
- name: Build 🔧
48+
run: dotnet build --no-restore --verbosity minimal
49+
5050
- name: Test 🧪
51-
run: dotnet test --no-restore --verbosity minimal
51+
run: dotnet test --no-restore --no-build --verbosity minimal
5252

5353
- name: Pack 📦
5454
run: dotnet pack --configuration Release --output .

.github/workflows/test.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
11+
DOTNET_CLI_TELEMETRY_OPTOUT: true
12+
13+
jobs:
14+
test:
15+
concurrency: ci-${{ github.ref }}
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout 🛎️
20+
uses: actions/checkout@v4
21+
22+
- name: Setup .NET 🛠️
23+
uses: actions/setup-dotnet@v4
24+
with:
25+
dotnet-version: |
26+
6.0.x
27+
7.0.x
28+
8.0.x
29+
9.0.x
30+
31+
- name: Load cache 🔃
32+
id: nuget-cache
33+
uses: actions/cache@v4
34+
with:
35+
path: "~/.nuget/packages"
36+
key: "${{ runner.os }}-nuget-api-${{ hashFiles('**/*.csproj') }}"
37+
restore-keys: "${{ runner.os }}-nuget-api-"
38+
39+
- name: Cache status ✅
40+
run: |
41+
echo "Cache hit: ${{ steps.nuget-cache.outputs.cache-hit }}"
42+
43+
- name: Display .NET version 📚
44+
run: dotnet --version
45+
46+
- name: Restore 📦
47+
run: dotnet restore --verbosity minimal
48+
49+
- name: Build 🔧
50+
run: dotnet build --no-restore --verbosity minimal
51+
52+
- name: Test 🧪
53+
run: dotnet test --no-restore --no-build --verbosity minimal

EntityFrameworkCore.DataProtection.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "src/EntityFrameworkCore.DataProtection", "src/EntityFrameworkCore.DataProtection/EntityFrameworkCore.DataProtection.csproj", "{23817096-829D-465B-9C81-39EF87D90468}"
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Klean.EntityFrameworkCore.DataProtection", "src\Klean.EntityFrameworkCore.DataProtection\Klean.EntityFrameworkCore.DataProtection.csproj", "{23817096-829D-465B-9C81-39EF87D90468}"
44
EndProject
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{08CF6BCC-3928-4FB6-A1A0-ABF5DE162D6C}"
66
EndProject
77
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6A01C6D2-B6BE-4584-897B-60710734DC66}"
88
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFrameworkCore.DataProtection.Test", "test/EntityFrameworkCore.DataProtection.Test/EntityFrameworkCore.DataProtection.Test.csproj", "{AEACE4E1-D3F5-4A5D-8632-695AFDBDC020}"
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Klean.EntityFrameworkCore.DataProtection.Test", "test\Klean.EntityFrameworkCore.DataProtection.Test\Klean.EntityFrameworkCore.DataProtection.Test.csproj", "{AEACE4E1-D3F5-4A5D-8632-695AFDBDC020}"
1010
EndProject
1111
Global
1212
GlobalSection(SolutionConfigurationPlatforms) = preSolution

README.md

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# EntityFrameworkCore.DataProtection
1+
# Klean.EntityFrameworkCore.DataProtection
22

3-
[![.NET](https://github.com/ddjerqq/EntityFrameworkCore.DataProtection/actions/workflows/build.yml/badge.svg)](https://github.com/ddjerqq/EntityFrameworkCore.DataProtection/actions/workflows/build.yml)
4-
[![Nuget](https://img.shields.io/nuget/v/EntityFrameworkCore.DataProtection.svg)](https://www.nuget.org/packages/EntityFrameworkCore.DataProtection)
5-
[![Nuget Downloads](https://img.shields.io/nuget/dt/EntityFrameworkCore.DataProtection)](https://www.nuget.org/packages/EntityFrameworkCore.DataProtection)
3+
[![tests](https://github.com/ddjerqq/Klean.EntityFrameworkCore.DataProtection/actions/workflows/build.yml/badge.svg)](https://github.com/ddjerqq/Klean.EntityFrameworkCore.DataProtection/actions/workflows/test.yml)
4+
[![Nuget](https://img.shields.io/nuget/v/Klean.EntityFrameworkCore.DataProtection.svg)](https://www.nuget.org/packages/Klean.EntityFrameworkCore.DataProtection)
5+
[![Nuget Downloads](https://img.shields.io/nuget/dt/Klean.EntityFrameworkCore.DataProtection)](https://www.nuget.org/packages/Klean.EntityFrameworkCore.DataProtection)
66

7-
`EntityFrameworkCore.DataProtection` is a [Microsoft Entity Framework Core](https://github.com/aspnet/EntityFrameworkCore) extension which
7+
`Klean.EntityFrameworkCore.DataProtection` is a [Microsoft Entity Framework Core](https://github.com/aspnet/EntityFrameworkCore) extension which
88
adds support for data protection and querying for encrypted properties for your entities.
99

1010
# What problem does this library solve?
@@ -41,32 +41,22 @@ Keeping your encryption keys secure is your responsibility. If you lose your enc
4141
Install the package from [NuGet](https://www.nuget.org/) or from the `Package Manager Console` :
4242

4343
```powershell
44-
PM> Install-Package EntityFrameworkCore.DataProtection
44+
PM> Install-Package Klean.EntityFrameworkCore.DataProtection
4545
```
4646

4747
### Configuring Data Protection in your DbContext
4848

4949
`YourDbContext.cs`
5050

5151
```csharp
52-
// vv injected from DI
5352
public class Your(DbContextOptions<Your> options, IDataProtectionProvider dataProtectionProvider) : DbContext(options)
5453
{
5554
public DbSet<User> Users => Set<User>();
5655

5756
protected override void OnModelCreating(ModelBuilder builder)
5857
{
59-
// if you are using IEntityTypeConfiguration<T> in your project
60-
// then ApplyConfigurationsFromAssembly must come before base.OnModelCreating
61-
builder.ApplyConfigurationsFromAssembly(typeof(YourDbContext).Assembly);
62-
6358
base.OnModelCreating(builder);
64-
65-
// UseDataProtection MUST come after base.OnModelCreating
6659
builder.UseDataProtection(dataProtectionProvider);
67-
68-
// anything else you want to do with the builder must come after the call to UseDataProtection, unless you know exactly what you are doing
69-
builder.SnakeCaseRename();
7060
}
7161
}
7262
```
@@ -80,7 +70,13 @@ public class Your(DbContextOptions<Your> options, IDataProtectionProvider dataPr
8070
`Program.cs`
8171

8272
```csharp
83-
var keyDirectory = new DirectoryInfo("keys");
73+
builder.Services.AddDataProtectionServices();
74+
```
75+
76+
To persist keys in file system use the following code:
77+
78+
```csharp
79+
var keyDirectory = new DirectoryInfo("path/to/solution/.aspnet/dp/keys");
8480
builder.Services.AddDataProtectionServices()
8581
.PersistKeysToFileSystem(keyDirectory);
8682
```
@@ -95,13 +91,15 @@ builder.Services.AddDataProtectionServices()
9591
```csharp
9692
services.AddDbContext<YourDbContext>(opt => opt
9793
.AddDataProtectionInterceptors()
98-
.UseSqlite()); // or anything else
94+
/* ... */);
9995
```
10096

10197
> [!WARNING]
102-
> You **MUST** call `AddDataProtectionInterceptors` if you are using any encrypted properties marked as queryable in your entities.
98+
> You **MUST** call `AddDataProtectionInterceptors` if you are using any encrypted properties that are queryable in your entities.
10399
> If you are not using any queryable encrypted properties, you can skip this step.
104100
101+
## Usage:
102+
105103
### Marking your properties as encrypted
106104

107105
There are three ways you can mark your properties as encrypted:
@@ -110,7 +108,6 @@ Using the EncryptedAttribute:
110108
```csharp
111109
class User
112110
{
113-
// v default v default
114111
[Encrypt(IsQueryable = true, IsUnique = true)]
115112
public string SocialSecurityNumber { get; set; }
116113

@@ -136,21 +133,11 @@ protected override void OnModelCreating(ModelBuilder builder)
136133
}
137134
```
138135

139-
Creating a custom `EntityTypeConfiguration` (Recommended for DDD):
140-
```csharp
141-
class UserConfiguration : IEntityTypeConfiguration<User>
142-
{
143-
public void Configure(EntityTypeBuilder<User> builder)
144-
{
145-
builder.Property(e => e.SocialSecurityNumber).IsEncryptedQueryable();
146-
builder.Property(e => e.IdPicture).IsEncrypted();
147-
}
148-
}
149-
```
136+
The above step also applies to custom `EntityTypeConfiguration`s
150137

151138
### Querying encrypted properties
152139

153-
You can query encrypted properties that are marked as Queryable using the `QueryableExt.WherePdEquals` extension method:
140+
You can query encrypted properties that are marked as Queryable using the `IQueryable<T>.WherePdEquals` extension method:
154141

155142
```csharp
156143
var foo = await DbContext.Users
@@ -159,11 +146,14 @@ var foo = await DbContext.Users
159146
```
160147

161148
> [!WARNING]
162-
> The `QueryableExt.WherePdEquals` method is only available for properties that are marked as Queryable using the `[Encrypt(isQueryable: true)]` attribute or the
163-
> `IsEncrypted(isQueryable: true)` method.
164-
> And before using `WherePdEquals` you **MUST** call `AddDataProtectionInterceptors` in your `DbContext` configuration.
149+
> The `QueryableExt.WherePdEquals` method is only available for properties that are marked as Queryable using the `[Encrypt(IsQueryable = true)]` attribute or the
150+
> `IsEncryptedQueryable()` method.
165151
166-
> [!TIP]
152+
> [!CAUTION]
153+
> Before using `WherePdEquals` you **MUST** call `AddDataProtectionInterceptors` in your `DbContext` configuration.
154+
> There will be no error if you forget to call `AddDataProtectionInterceptors`, but the query will not work as expected.
155+
156+
> [!NOTE]
167157
> The `WherePdEquals` extension method generates an expression like this one under the hood:<br/>
168158
> `Where(e => EF.Property<string>(e, $"{propertyName}ShadowHash") == value.Sha256Hash())`
169159

src/EntityFrameworkCore.DataProtection/EncryptAttribute.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/EncryptAttribute.cs

File renamed without changes.

src/EntityFrameworkCore.DataProtection/Extensions/DbContextOptionsBuilderExt.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/Extensions/DbContextOptionsBuilderExt.cs

File renamed without changes.

src/EntityFrameworkCore.DataProtection/Extensions/ModelBuilderExt.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/Extensions/ModelBuilderExt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static class ModelBuilderExt
4747
/// </exception>
4848
public static ModelBuilder UseDataProtection(this ModelBuilder builder, IDataProtectionProvider dataProtectionProvider)
4949
{
50-
var protector = dataProtectionProvider.CreateProtector("EntityFrameworkCore.DataProtection");
50+
var protector = dataProtectionProvider.CreateProtector("Klean.EntityFrameworkCore.DataProtection");
5151

5252
var properties = (
5353
from entityType in builder.Model.GetEntityTypes()

src/EntityFrameworkCore.DataProtection/Extensions/PropertyBuilderExt.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/Extensions/PropertyBuilderExt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace EntityFrameworkCore.DataProtection.Extensions;
99
/// </summary>
1010
public static class PropertyBuilderExt
1111
{
12-
private const string IsEncryptedAnnotationName = "EntityFrameworkCore.DataProtection.IsEncrypted";
13-
private const string IsQueryableAnnotationName = "EntityFrameworkCore.DataProtection.IsQueryable";
14-
private const string IsUniqueIndexAnnotationName = "EntityFrameworkCore.DataProtection.IsUniqueIndex";
12+
private const string IsEncryptedAnnotationName = "Klean.EntityFrameworkCore.DataProtection.IsEncrypted";
13+
private const string IsQueryableAnnotationName = "Klean.EntityFrameworkCore.DataProtection.IsQueryable";
14+
private const string IsUniqueIndexAnnotationName = "Klean.EntityFrameworkCore.DataProtection.IsUniqueIndex";
1515

1616
internal static readonly InvalidOperationException InvalidTypeException =
1717
new("Only string and byte[] properties are supported for now. " +
18-
"Please open an issue on https://github.com/ddjerqq/EntityFrameworkCore.DataProtection/issues to request a new feature");
18+
"Please open an issue on https://github.com/ddjerqq/Klean.EntityFrameworkCore.DataProtection/issues to request a new feature");
1919

2020
/// <summary>
2121
/// Marks the property as encrypted.

src/EntityFrameworkCore.DataProtection/Extensions/QueryableExt.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/Extensions/QueryableExt.cs

File renamed without changes.

src/EntityFrameworkCore.DataProtection/Extensions/ServiceCollectionExt.cs renamed to src/Klean.EntityFrameworkCore.DataProtection/Extensions/ServiceCollectionExt.cs

File renamed without changes.

0 commit comments

Comments
 (0)