Skip to content

Commit

Permalink
+ API Cleanup, IBlackList Interface overhaul
Browse files Browse the repository at this point in the history
+ Added EasyCaching
+ Stackexchange Redis BlackList Store fixed
  • Loading branch information
rainxh11 committed Aug 5, 2022
1 parent 06b6ad4 commit 7a186dc
Show file tree
Hide file tree
Showing 38 changed files with 746 additions and 643 deletions.
103 changes: 103 additions & 0 deletions Revoke.NET.Akavache/AkavacheBlackList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Akavache;
using Registrations = Akavache.Registrations;

namespace Revoke.NET.Akavache
{
public class AkavacheBlackList : IBlackList
{
private readonly IBlobCache _blackList;
private static TimeSpan? _defaultTtl;

private AkavacheBlackList(IBlobCache blobcache)
{
this._blackList = blobcache;
}

public static async Task<IBlackList> CreateStoreAsync(string cacheName, IBlobCache blobCache,
TimeSpan? defaultTtl = null)
{
_defaultTtl = defaultTtl;
Registrations.Start(cacheName);
await blobCache.Vacuum();
return new AkavacheBlackList(blobCache);
}


public async Task<bool> Delete(string key)
{
try
{
await _blackList.Invalidate(key);
return true;
}
catch
{
return false;
}
}

public async Task DeleteAll()
{
await _blackList.InvalidateAll();
}

public async Task<bool> IsRevoked(string key)
{
try
{
await _blackList.Vacuum();
var exist = await _blackList.Get(key);
return exist.Length > 0;
}
catch
{
return false;
}
}

public async Task<bool> Revoke(string key)
{
try
{
await _blackList.InsertObject(key, key, DateTimeOffset.Now.Add(_defaultTtl ?? TimeSpan.MaxValue));
return true;
}
catch
{
return false;
}
}

public async Task<bool> Revoke(string key, TimeSpan expireAfter)
{
try
{
await _blackList.InsertObject(key, key, DateTimeOffset.Now.Add(expireAfter));

return true;
}
catch
{
return false;
}
}

public async Task<bool> Revoke(string key, DateTime expireOn)
{
try
{
await _blackList.InsertObject(key, key, expireOn);

return true;
}
catch
{
return false;
}
}
}
}
129 changes: 0 additions & 129 deletions Revoke.NET.Akavache/AkavacheBlackListStore.cs

This file was deleted.

4 changes: 0 additions & 4 deletions Revoke.NET.Akavache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ var key = "[ID String of something to be blacklisted]";

await store.Revoke(key, TimeSpan.FromHours(24)); // Revoke access to a key for 24 hours
await store.Revoke<SomeType>(model); // Revoke an item with custom type
var item = store.Get<SomeType>(key); // Retrieve a blacklisted item, SomeType must implement interface 'IBlackListItem'
await store.IsRevoked(key); // Check if key is blacklisted
await store.Delete(key); // Delete a key from blacklist
Expand Down
12 changes: 6 additions & 6 deletions Revoke.NET.Akavache/Revoke.NET.Akavache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.6</Version>
<Version>2.0.0</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET Akavache Store Extension</Description>
Expand All @@ -24,12 +24,12 @@
</PropertyGroup>

<ItemGroup>
<None Include="assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="..\assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="akavache" Version="8.1.1" />
<PackageReference Include="akavache.sqlite3" Version="8.1.1" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
<None Include="..\LICENSE" Pack="true" PackagePath="\" />
<PackageReference Include="akavache" Version="9.0.1" />
<PackageReference Include="akavache.sqlite3" Version="9.0.1" />
<PackageReference Include="Revoke.NET" Version="2.0.1" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Revoke.NET.Akavache/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class RevokeService
public static IServiceCollection AddRevokeAkavacheSQLiteStore(this IServiceCollection services)
{
return services
.AddSingleton<IBlackListStore>(provider => AkavacheBlackListStore
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", BlobCache.LocalMachine)
.GetAwaiter()
.GetResult());
Expand All @@ -20,7 +20,7 @@ public static IServiceCollection AddRevokeAkavacheSQLiteStore(this IServiceColle
public static IServiceCollection AddRevokeAkavacheInMemoryStore(this IServiceCollection services)
{
return services
.AddSingleton<IBlackListStore>(provider => AkavacheBlackListStore
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", BlobCache.InMemory)
.GetAwaiter()
.GetResult());
Expand All @@ -30,7 +30,7 @@ public static IServiceCollection AddRevokeAkavacheStore(this IServiceCollection
Func<IServiceProvider, IBlobCache> configBlobCache)
{
return services
.AddSingleton<IBlackListStore>(provider => AkavacheBlackListStore
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", configBlobCache(provider))
.GetAwaiter()
.GetResult());
Expand Down
10 changes: 5 additions & 5 deletions Revoke.NET.AspNetCore/Revoke.NET.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.7</Version>
<Version>2.0.0</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET ASP.NET Core Extension</Description>
Expand All @@ -27,10 +27,10 @@
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Revoke.NET" Version="2.0.1" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Revoke.NET.AspNetCore/RevokeHttpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ namespace Revoke.NET.AspNetCore
{
public class RevokeHttpMiddleware : IMiddleware
{
private readonly IBlackListStore store;
private readonly IBlackList store;
private readonly Func<HttpContext, string> selector;

#nullable enable
private readonly ILogger<RevokeHttpMiddleware>? logger;
private Func<HttpResponse, Task<HttpResponse>>? responseFunc;
#nullable disable

public RevokeHttpMiddleware(IBlackListStore store, ILogger<RevokeHttpMiddleware> logger,
public RevokeHttpMiddleware(IBlackList store, ILogger<RevokeHttpMiddleware> logger,
Func<HttpContext, string> selector)
{
this.store = store;
this.logger = logger;
this.selector = selector;
}

public RevokeHttpMiddleware(IBlackListStore store, Func<HttpContext, string> selector)
public RevokeHttpMiddleware(IBlackList store, Func<HttpContext, string> selector)
{
this.store = store;
this.selector = selector;
}

public RevokeHttpMiddleware(IBlackListStore store, ILogger<RevokeHttpMiddleware> logger,
public RevokeHttpMiddleware(IBlackList store, ILogger<RevokeHttpMiddleware> logger,
Func<HttpContext, string> selector, Func<HttpResponse, Task<HttpResponse>> responseFunc)
{
this.store = store;
Expand All @@ -42,7 +42,7 @@ public RevokeHttpMiddleware(IBlackListStore store, ILogger<RevokeHttpMiddleware>
this.responseFunc = responseFunc;
}

public RevokeHttpMiddleware(IBlackListStore store, Func<HttpContext, string> selector,
public RevokeHttpMiddleware(IBlackList store, Func<HttpContext, string> selector,
Func<HttpResponse, Task<HttpResponse>> responseFunc)
{
this.store = store;
Expand Down
Loading

0 comments on commit 7a186dc

Please sign in to comment.