mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
upgrade to aspnet core 3.1
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Blob;
|
||||
using Microsoft.Azure.Storage;
|
||||
using Microsoft.Azure.Storage.Blob;
|
||||
using System.IO;
|
||||
using System;
|
||||
using Bit.Core.Models.Table;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Repositories;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Queue;
|
||||
using Azure.Storage.Queues;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
@ -10,8 +8,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
public class AzureQueueEventWriteService : IEventWriteService
|
||||
{
|
||||
private readonly CloudQueue _queue;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly QueueClient _queueClient;
|
||||
|
||||
private JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
@ -19,28 +16,21 @@ namespace Bit.Core.Services
|
||||
};
|
||||
|
||||
public AzureQueueEventWriteService(
|
||||
IEventRepository eventRepository,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Events.ConnectionString);
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
|
||||
_queue = queueClient.GetQueueReference("event");
|
||||
_globalSettings = globalSettings;
|
||||
_queueClient = new QueueClient(globalSettings.Events.ConnectionString, "event");
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEvent e)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(e, _jsonSettings);
|
||||
var message = new CloudQueueMessage(json);
|
||||
await _queue.AddMessageAsync(message);
|
||||
await _queueClient.SendMessageAsync(json);
|
||||
}
|
||||
|
||||
public async Task CreateManyAsync(IList<IEvent> e)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(e, _jsonSettings);
|
||||
var message = new CloudQueueMessage(json);
|
||||
await _queue.AddMessageAsync(message);
|
||||
await _queueClient.SendMessageAsync(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Models;
|
||||
using Microsoft.WindowsAzure.Storage.Queue;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Azure.Storage.Queues;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@ -13,7 +12,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
public class AzureQueuePushNotificationService : IPushNotificationService
|
||||
{
|
||||
private readonly CloudQueue _queue;
|
||||
private readonly QueueClient _queueClient;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
@ -26,9 +25,7 @@ namespace Bit.Core.Services
|
||||
GlobalSettings globalSettings,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Notifications.ConnectionString);
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
_queue = queueClient.GetQueueReference("notifications");
|
||||
_queueClient = new QueueClient(globalSettings.Notifications.ConnectionString, "notifications");
|
||||
_globalSettings = globalSettings;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
@ -143,8 +140,7 @@ namespace Bit.Core.Services
|
||||
var contextId = GetContextIdentifier(excludeCurrentContext);
|
||||
var message = JsonConvert.SerializeObject(new PushNotificationData<T>(type, payload, contextId),
|
||||
_jsonSettings);
|
||||
var queueMessage = new CloudQueueMessage(message);
|
||||
await _queue.AddMessageAsync(queueMessage);
|
||||
await _queueClient.SendMessageAsync(message);
|
||||
}
|
||||
|
||||
private string GetContextIdentifier(bool excludeCurrentContext)
|
||||
|
@ -4,7 +4,7 @@ using Bit.Core.Repositories;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.Azure.Storage;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
Reference in New Issue
Block a user