mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00
add x-platform support with netcore 2.0
This commit is contained in:
@ -98,24 +98,50 @@ namespace Bit.Core.Services
|
||||
public async Task CleanupAsync(Guid cipherId)
|
||||
{
|
||||
await InitAsync();
|
||||
foreach(var blob in _attachmentsContainer.ListBlobs($"temp/{cipherId}", true))
|
||||
var segment = await _attachmentsContainer.ListBlobsSegmentedAsync($"temp/{cipherId}", true,
|
||||
BlobListingDetails.None, 100, null, null, null);
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(blob is CloudBlockBlob blockBlob)
|
||||
foreach(var blob in segment.Results)
|
||||
{
|
||||
await blockBlob.DeleteIfExistsAsync();
|
||||
if(blob is CloudBlockBlob blockBlob)
|
||||
{
|
||||
await blockBlob.DeleteIfExistsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
if(segment.ContinuationToken == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
segment = await _attachmentsContainer.ListBlobsSegmentedAsync(segment.ContinuationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAttachmentsForCipherAsync(Guid cipherId)
|
||||
{
|
||||
await InitAsync();
|
||||
foreach(var blob in _attachmentsContainer.ListBlobs(cipherId.ToString(), true))
|
||||
var segment = await _attachmentsContainer.ListBlobsSegmentedAsync(cipherId.ToString(), true,
|
||||
BlobListingDetails.None, 100, null, null, null);
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(blob is CloudBlockBlob blockBlob)
|
||||
foreach(var blob in segment.Results)
|
||||
{
|
||||
await blockBlob.DeleteIfExistsAsync();
|
||||
if(blob is CloudBlockBlob blockBlob)
|
||||
{
|
||||
await blockBlob.DeleteIfExistsAsync();
|
||||
}
|
||||
}
|
||||
|
||||
if(segment.ContinuationToken == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
segment = await _attachmentsContainer.ListBlobsSegmentedAsync(segment.ContinuationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
private readonly CloudQueue _blockIpQueue;
|
||||
private readonly CloudQueue _unblockIpQueue;
|
||||
private bool _didInit = false;
|
||||
|
||||
public AzureQueueBlockIpService(
|
||||
GlobalSettings globalSettings)
|
||||
@ -17,14 +18,12 @@ namespace Bit.Core.Services
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
|
||||
_blockIpQueue = queueClient.GetQueueReference("blockip");
|
||||
_blockIpQueue.CreateIfNotExists();
|
||||
|
||||
_unblockIpQueue = queueClient.GetQueueReference("unblockip");
|
||||
_unblockIpQueue.CreateIfNotExists();
|
||||
}
|
||||
|
||||
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
|
||||
{
|
||||
await InitAsync();
|
||||
var message = new CloudQueueMessage(ipAddress);
|
||||
await _blockIpQueue.AddMessageAsync(message);
|
||||
|
||||
@ -33,5 +32,17 @@ namespace Bit.Core.Services
|
||||
await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(12, 0, 0), null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task InitAsync()
|
||||
{
|
||||
if(_didInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await _blockIpQueue.CreateIfNotExistsAsync();
|
||||
await _unblockIpQueue.CreateIfNotExistsAsync();
|
||||
_didInit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if NET461
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
using Microsoft.Azure.NotificationHubs;
|
||||
@ -161,3 +162,4 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if NET461
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.NotificationHubs;
|
||||
@ -144,3 +145,4 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user