1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

Queue ip addresses for block whenever they exceed the rate limit too much

This commit is contained in:
Kyle Spearrin
2016-11-30 21:51:43 -05:00
parent 2d045859e7
commit b87c9c1a5a
7 changed files with 93 additions and 10 deletions

View File

@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using System;
namespace Bit.Core.Services
{
public class AzureBlockIpService : IBlockIpService
{
private CloudQueue _blockIpQueue;
private CloudQueue _unblockIpQueue;
public AzureBlockIpService(
GlobalSettings globalSettings)
{
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
_blockIpQueue = queueClient.GetQueueReference("blockip");
_blockIpQueue.CreateIfNotExists();
_unblockIpQueue = queueClient.GetQueueReference("unblockip");
_unblockIpQueue.CreateIfNotExists();
}
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
{
var message = new CloudQueueMessage(ipAddress);
await _blockIpQueue.AddMessageAsync(message);
if(!permanentBlock)
{
await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(12, 0, 0), null, null);
}
}
}
}

View File

@ -0,0 +1,10 @@
using System;
using System.Threading.Tasks;
namespace Bit.Core.Services
{
public interface IBlockIpService
{
Task BlockIpAsync(string ipAddress, bool permanentBlock);
}
}