1
0
mirror of https://github.com/bitwarden/server synced 2025-12-20 18:23:44 +00:00

upgrade to aspnet core 3.1

This commit is contained in:
Kyle Spearrin
2020-01-10 08:33:13 -05:00
parent 8026912eeb
commit 29580684a3
60 changed files with 429 additions and 420 deletions

View File

@@ -1,31 +1,24 @@
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using System;
using Bit.Core.Utilities;
using Azure.Storage.Queues;
namespace Bit.Core.Services
{
public class AzureQueueBlockIpService : IBlockIpService
{
private readonly CloudQueue _blockIpQueue;
private readonly CloudQueue _unblockIpQueue;
private bool _didInit = false;
private readonly QueueClient _blockIpQueueClient;
private readonly QueueClient _unblockIpQueueClient;
private Tuple<string, bool, DateTime> _lastBlock;
public AzureQueueBlockIpService(
GlobalSettings globalSettings)
{
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
_blockIpQueue = queueClient.GetQueueReference("blockip");
_unblockIpQueue = queueClient.GetQueueReference("unblockip");
_blockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "blockip");
_unblockIpQueueClient = new QueueClient(globalSettings.Storage.ConnectionString, "unblockip");
}
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
{
await InitAsync();
var now = DateTime.UtcNow;
if(_lastBlock != null && _lastBlock.Item1 == ipAddress && _lastBlock.Item2 == permanentBlock &&
(now - _lastBlock.Item3) < TimeSpan.FromMinutes(1))
@@ -35,24 +28,11 @@ namespace Bit.Core.Services
}
_lastBlock = new Tuple<string, bool, DateTime>(ipAddress, permanentBlock, now);
var message = new CloudQueueMessage(ipAddress);
await _blockIpQueue.AddMessageAsync(message);
await _blockIpQueueClient.SendMessageAsync(ipAddress);
if(!permanentBlock)
{
await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(0, 15, 0), null, null);
await _unblockIpQueueClient.SendMessageAsync(ipAddress, new TimeSpan(0, 15, 0));
}
}
private async Task InitAsync()
{
if(_didInit)
{
return;
}
await _blockIpQueue.CreateIfNotExistsAsync();
await _unblockIpQueue.CreateIfNotExistsAsync();
_didInit = true;
}
}
}