mirror of
https://github.com/bitwarden/server
synced 2026-01-01 16:13:33 +00:00
Turn on file scoped namespaces (#2225)
This commit is contained in:
@@ -1,37 +1,36 @@
|
||||
using Azure.Storage.Queues;
|
||||
using Bit.Core.Settings;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class AzureQueueBlockIpService : IBlockIpService
|
||||
{
|
||||
private readonly QueueClient _blockIpQueueClient;
|
||||
private readonly QueueClient _unblockIpQueueClient;
|
||||
private Tuple<string, bool, DateTime> _lastBlock;
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
public AzureQueueBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
public class AzureQueueBlockIpService : IBlockIpService
|
||||
{
|
||||
private readonly QueueClient _blockIpQueueClient;
|
||||
private readonly QueueClient _unblockIpQueueClient;
|
||||
private Tuple<string, bool, DateTime> _lastBlock;
|
||||
|
||||
public AzureQueueBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
_blockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "blockip");
|
||||
_unblockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "unblockip");
|
||||
}
|
||||
|
||||
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
if (_lastBlock != null && _lastBlock.Item1 == ipAddress && _lastBlock.Item2 == permanentBlock &&
|
||||
(now - _lastBlock.Item3) < TimeSpan.FromMinutes(1))
|
||||
{
|
||||
_blockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "blockip");
|
||||
_unblockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "unblockip");
|
||||
// Already blocked this IP recently.
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
|
||||
_lastBlock = new Tuple<string, bool, DateTime>(ipAddress, permanentBlock, now);
|
||||
await _blockIpQueueClient.SendMessageAsync(ipAddress);
|
||||
if (!permanentBlock)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
if (_lastBlock != null && _lastBlock.Item1 == ipAddress && _lastBlock.Item2 == permanentBlock &&
|
||||
(now - _lastBlock.Item3) < TimeSpan.FromMinutes(1))
|
||||
{
|
||||
// Already blocked this IP recently.
|
||||
return;
|
||||
}
|
||||
|
||||
_lastBlock = new Tuple<string, bool, DateTime>(ipAddress, permanentBlock, now);
|
||||
await _blockIpQueueClient.SendMessageAsync(ipAddress);
|
||||
if (!permanentBlock)
|
||||
{
|
||||
await _unblockIpQueueClient.SendMessageAsync(ipAddress, new TimeSpan(0, 15, 0));
|
||||
}
|
||||
await _unblockIpQueueClient.SendMessageAsync(ipAddress, new TimeSpan(0, 15, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user