Skip to content

Commit

Permalink
fixed non-XML comment related errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffward01 committed Oct 13, 2022
1 parent 966fba4 commit 2ae0880
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 136 deletions.
4 changes: 2 additions & 2 deletions Revoke.NET.Akavache/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public static class RevokeService
public static IServiceCollection AddRevokeAkavacheSQLiteStore(this IServiceCollection services)
{
return services.AddSingleton(
provider => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.LocalMachine)
_ => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.LocalMachine)
.GetAwaiter()
.GetResult());
}

public static IServiceCollection AddRevokeAkavacheInMemoryStore(this IServiceCollection services)
{
return services.AddSingleton(
provider => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.InMemory)
_ => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.InMemory)
.GetAwaiter()
.GetResult());
}
Expand Down
44 changes: 22 additions & 22 deletions Revoke.NET.AspNetCore/RevokeHttpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,63 @@

public class RevokeHttpMiddleware : IMiddleware
{
private readonly IBlackList store;
private readonly Func<HttpContext, string> selector;
private readonly IBlackList _store;
private readonly Func<HttpContext, string> _selector;

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

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

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

public RevokeHttpMiddleware(
IBlackList store, ILogger<RevokeHttpMiddleware> logger, Func<HttpContext, string> selector,
Func<HttpResponse, Task<HttpResponse>> responseFunc)
{
this.store = store;
this.logger = logger;
this.selector = selector;
this.responseFunc = responseFunc;
this._store = store;
this._logger = logger;
this._selector = selector;
this._responseFunc = responseFunc;
}

public RevokeHttpMiddleware(IBlackList store, Func<HttpContext, string> selector, Func<HttpResponse, Task<HttpResponse>> responseFunc)
{
this.store = store;
this.selector = selector;
this.responseFunc = responseFunc;
this._store = store;
this._selector = selector;
this._responseFunc = responseFunc;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{
var revokeKey = this.selector(context);
var revokeKey = this._selector(context);
if (revokeKey != null)
{
if (await this.store.IsRevoked(revokeKey))
if (await this._store.IsRevoked(revokeKey))
{
if (this.responseFunc != null)
if (this._responseFunc != null)
{
await this.responseFunc(context.Response);
await this._responseFunc(context.Response);
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
}

this.logger.LogInformation($"[Revoke.NET] Revoked Access to key: '{revokeKey}'");
this._logger?.LogInformation("[Revoke.NET] Revoked Access to key: \'{RevokeKey}\'", revokeKey);
}
else
{
Expand All @@ -78,7 +78,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
}
catch (Exception ex)
{
this.logger?.LogError(ex.Message);
this._logger?.LogError("{ErrorMessage}",ex.Message);
await next(context);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Revoke.NET.AspNetCore/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static IServiceCollection AddJWTBearerTokenRevokeMiddleware(this IService
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddIPRevokeMiddleware(this IServiceCollection services)
public static IServiceCollection AddIpRevokeMiddleware(this IServiceCollection services)
{
var ipSelector = new Func<HttpContext, string>(context => context.Request.Host.Host);

Expand All @@ -136,7 +136,7 @@ public static IServiceCollection AddIPRevokeMiddleware(this IServiceCollection s
/// <param name="services"></param>
/// <param name="responseFunc">custom response function</param>
/// <returns></returns>
public static IServiceCollection AddIPRevokeMiddleware(this IServiceCollection services, Func<HttpResponse, Task<HttpResponse>> responseFunc)
public static IServiceCollection AddIpRevokeMiddleware(this IServiceCollection services, Func<HttpResponse, Task<HttpResponse>> responseFunc)
{
var ipSelector = new Func<HttpContext, string>(context => context.Request.Host.Host);

Expand Down
1 change: 1 addition & 0 deletions Revoke.NET.EasyCaching/EasyCachingBlackList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public async Task DeleteAll()
}
catch
{
// ignored
}
}

Expand Down
2 changes: 1 addition & 1 deletion Revoke.NET.EasyCaching/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class RevokeService
{
public static IServiceCollection AddRevokeEasyCaching(this IServiceCollection services, IEasyCachingProvider easyCachingProvider, TimeSpan? defaultTtl = null)
{
return services.AddSingleton<IBlackList, EasyCachingBlackList>(provider => new EasyCachingBlackList(easyCachingProvider, defaultTtl));
return services.AddSingleton<IBlackList, EasyCachingBlackList>(_ => new EasyCachingBlackList(easyCachingProvider, defaultTtl));
}

public static IServiceCollection AddRevokeEasyCaching(this IServiceCollection services, Func<IEasyCachingProviderFactory, IEasyCachingProvider> easyCachingConfig, TimeSpan? defaultTtl = null)
Expand Down
1 change: 1 addition & 0 deletions Revoke.NET.MongoDB/MongoBlackList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public async Task DeleteAll()
}
catch
{
// ignored
}
}

Expand Down
4 changes: 2 additions & 2 deletions Revoke.NET.MongoDB/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public static class RevokeService
public static IServiceCollection AddRevokeMongoStore(this IServiceCollection services)
{
return services.AddSingleton(
provider => MongoBlackList.CreateStoreAsync("RevokeStore", MongoClientSettings.FromConnectionString("mongodb://127.0.0.1:27017/RevokeStore"))
_ => MongoBlackList.CreateStoreAsync("RevokeStore", MongoClientSettings.FromConnectionString("mongodb://127.0.0.1:27017/RevokeStore"))
.GetAwaiter()
.GetResult());
}

public static IServiceCollection AddRevokeMongoStore(this IServiceCollection services, string dbName, MongoClientSettings settings)
{
return services.AddSingleton(
provider => MongoBlackList.CreateStoreAsync(dbName, settings)
_ => MongoBlackList.CreateStoreAsync(dbName, settings)
.GetAwaiter()
.GetResult());
}
Expand Down
4 changes: 2 additions & 2 deletions Revoke.NET.Redis/RevokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public static class RevokeService
public static IServiceCollection AddRevokeRedisStore(this IServiceCollection services)
{
return services.AddSingleton(
provider => RedisBlackList.CreateStoreAsync("127.0.0.1:6379")
_ => RedisBlackList.CreateStoreAsync("127.0.0.1:6379")
.GetAwaiter()
.GetResult());
}

public static IServiceCollection AddRevokeRedisStore(this IServiceCollection services, string connectionString)
{
return services.AddSingleton(
provider => RedisBlackList.CreateStoreAsync(connectionString)
_ => RedisBlackList.CreateStoreAsync(connectionString)
.GetAwaiter()
.GetResult());
}
Expand Down
3 changes: 3 additions & 0 deletions Revoke.NET.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JWT/@EntryIndexedValue">JWT</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQ/@EntryIndexedValue">SQ</s:String></wpf:ResourceDictionary>
108 changes: 4 additions & 104 deletions Revoke.NET/MemoryBlackList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,16 @@

using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Primitives;

public class MemoryCacheBlackList : IBlackList
{
private static CancellationTokenSource _resetCacheToken = new();
private readonly TimeSpan? _defaultTtl;
private readonly IMemoryCache _memoryCache;

public MemoryCacheBlackList(IMemoryCache memoryCache, TimeSpan? defaultTtl = null)
{
this._defaultTtl = defaultTtl;
this._memoryCache = memoryCache;
}

public Task<bool> Revoke(string key)
{
var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.Normal)
.SetAbsoluteExpiration(this._defaultTtl ?? TimeSpan.MaxValue);
options.AddExpirationToken(new CancellationChangeToken(_resetCacheToken.Token));
try
{
this._memoryCache.Set(key, key, options);

return Task.FromResult(true);
}
catch
{
return Task.FromResult(false);
}
}

public Task<bool> Delete(string key)
{
try
{
this._memoryCache.Remove(key);

return Task.FromResult(true);
}
catch
{
return Task.FromResult(false);
}
}

public Task DeleteAll()
{
if (_resetCacheToken != null && !_resetCacheToken.IsCancellationRequested && _resetCacheToken.Token.CanBeCanceled)
{
_resetCacheToken.Cancel();
_resetCacheToken.Dispose();
}

_resetCacheToken = new CancellationTokenSource();

return Task.CompletedTask;
}

public Task<bool> IsRevoked(string key)
{
return Task.FromResult(this._memoryCache.TryGetValue(key, out _));
}

public Task<bool> Revoke(string key, TimeSpan expireAfter)
{
var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.Normal)
.SetAbsoluteExpiration(expireAfter);
options.AddExpirationToken(new CancellationChangeToken(_resetCacheToken.Token));
try
{
this._memoryCache.Set(key, key, options);

return Task.FromResult(true);
}
catch
{
return Task.FromResult(false);
}
}

public Task<bool> Revoke(string key, DateTime expireOn)
{
var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.Normal)
.SetAbsoluteExpiration(expireOn);
options.AddExpirationToken(new CancellationChangeToken(_resetCacheToken.Token));

try
{
this._memoryCache.Set(key, key, options);

return Task.FromResult(true);
}
catch
{
return Task.FromResult(false);
}
}
}

public class MemoryBlackList : IBlackList
{
private readonly TimeSpan? defaultTtl;
private readonly ConcurrentDictionary<string, DateTime> _blackList;
private readonly TimeSpan? _defaultTtl;

private MemoryBlackList(TimeSpan? defaultTtl)
{
this.defaultTtl = defaultTtl;
this._defaultTtl = defaultTtl;
this._blackList = new ConcurrentDictionary<string, DateTime>();
}

Expand Down Expand Up @@ -154,12 +54,12 @@ public Task<bool> IsRevoked(string key)

public Task<bool> Revoke(string key)
{
if (DateTime.Now.Add(this.defaultTtl ?? TimeSpan.MaxValue) < DateTime.Now)
if (DateTime.Now.Add(this._defaultTtl ?? TimeSpan.MaxValue) < DateTime.Now)
{
return Task.FromResult(false);
}

return Task.FromResult(this._blackList.TryAdd(key, DateTime.Now.Add(this.defaultTtl ?? TimeSpan.MaxValue)));
return Task.FromResult(this._blackList.TryAdd(key, DateTime.Now.Add(this._defaultTtl ?? TimeSpan.MaxValue)));
}

public static MemoryBlackList CreateStore(TimeSpan? defaultExpirationDuration = null)
Expand Down
Loading

0 comments on commit 2ae0880

Please sign in to comment.