mirror of
https://github.com/bitwarden/server
synced 2025-12-25 12:43:14 +00:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a.
This commit is contained in:
@@ -1,36 +1,37 @@
|
||||
using Azure.Storage.Queues;
|
||||
using Bit.Core.Settings;
|
||||
|
||||
namespace Bit.Core.Services;
|
||||
|
||||
public class AzureQueueBlockIpService : IBlockIpService
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
private readonly QueueClient _blockIpQueueClient;
|
||||
private readonly QueueClient _unblockIpQueueClient;
|
||||
private Tuple<string, bool, DateTime> _lastBlock;
|
||||
|
||||
public AzureQueueBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
public class AzureQueueBlockIpService : IBlockIpService
|
||||
{
|
||||
_blockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "blockip");
|
||||
_unblockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "unblockip");
|
||||
}
|
||||
private readonly QueueClient _blockIpQueueClient;
|
||||
private readonly QueueClient _unblockIpQueueClient;
|
||||
private Tuple<string, bool, DateTime> _lastBlock;
|
||||
|
||||
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))
|
||||
public AzureQueueBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
// Already blocked this IP recently.
|
||||
return;
|
||||
_blockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "blockip");
|
||||
_unblockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "unblockip");
|
||||
}
|
||||
|
||||
_lastBlock = new Tuple<string, bool, DateTime>(ipAddress, permanentBlock, now);
|
||||
await _blockIpQueueClient.SendMessageAsync(ipAddress);
|
||||
if (!permanentBlock)
|
||||
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
|
||||
{
|
||||
await _unblockIpQueueClient.SendMessageAsync(ipAddress, new TimeSpan(0, 15, 0));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user