From 3880edfb7986bd2945cee27c534391c5c1d8d784 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 31 Jul 2017 16:58:27 -0400 Subject: [PATCH] add x-platform support with netcore 2.0 --- src/Api/Api.csproj | 2 +- src/Billing/Billing.csproj | 2 +- src/Core/Core.csproj | 10 +++-- src/Core/Identity/YubicoOtpTokenProvider.cs | 7 ++++ .../AzureAttachmentStorageService.cs | 38 ++++++++++++++++--- .../AzureQueueBlockIpService.cs | 17 +++++++-- .../NotificationHubPushNotificationService.cs | 4 +- .../NotificationHubPushRegistrationService.cs | 4 +- src/Core/Utilities/CoreHelpers.cs | 6 +-- .../Utilities/ServiceCollectionExtensions.cs | 9 ++++- src/Identity/Identity.csproj | 2 +- util/Mail/Mail.csproj | 4 +- 12 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj index 5097f6b15..72a4f8022 100644 --- a/src/Api/Api.csproj +++ b/src/Api/Api.csproj @@ -2,7 +2,7 @@ 1.8.2 - net461 + netcoreapp2.0;net461 Api Bit.Api bitwarden-Api diff --git a/src/Billing/Billing.csproj b/src/Billing/Billing.csproj index 05b4efdcd..e2d119fba 100644 --- a/src/Billing/Billing.csproj +++ b/src/Billing/Billing.csproj @@ -2,7 +2,7 @@ 1.8.2 - net461 + netcoreapp2.0;net461 Billing Bit.Billing bitwarden-Billing diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index caf4e69e2..6d2022c99 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -1,7 +1,7 @@  - net461 + netcoreapp2.0;net461 Core Bit.Core @@ -44,7 +44,6 @@ - @@ -57,7 +56,6 @@ - @@ -65,6 +63,12 @@ + + + + + + diff --git a/src/Core/Identity/YubicoOtpTokenProvider.cs b/src/Core/Identity/YubicoOtpTokenProvider.cs index 319c1d905..98156d6fa 100644 --- a/src/Core/Identity/YubicoOtpTokenProvider.cs +++ b/src/Core/Identity/YubicoOtpTokenProvider.cs @@ -2,7 +2,9 @@ using Microsoft.AspNetCore.Identity; using Bit.Core.Models.Table; using Bit.Core.Enums; +#if NET461 using YubicoDotNetClient; +#endif using System.Linq; namespace Bit.Core.Identity @@ -55,9 +57,14 @@ namespace Bit.Core.Identity return Task.FromResult(false); } + +#if NET461 var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key); var response = client.Verify(token); return Task.FromResult(response.Status == YubicoResponseStatus.Ok); +#else + return Task.FromResult(false); +#endif } } } diff --git a/src/Core/Services/Implementations/AzureAttachmentStorageService.cs b/src/Core/Services/Implementations/AzureAttachmentStorageService.cs index 7887840f7..f5843c991 100644 --- a/src/Core/Services/Implementations/AzureAttachmentStorageService.cs +++ b/src/Core/Services/Implementations/AzureAttachmentStorageService.cs @@ -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); } } diff --git a/src/Core/Services/Implementations/AzureQueueBlockIpService.cs b/src/Core/Services/Implementations/AzureQueueBlockIpService.cs index 439a890a7..01fa2699f 100644 --- a/src/Core/Services/Implementations/AzureQueueBlockIpService.cs +++ b/src/Core/Services/Implementations/AzureQueueBlockIpService.cs @@ -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; + } } } diff --git a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs index 83abc916b..4b335953d 100644 --- a/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushNotificationService.cs @@ -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 diff --git a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs index 2ea47ac7d..81f249f26 100644 --- a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs @@ -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 diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index 6f99a8fc4..c94232489 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -57,9 +57,8 @@ namespace Bit.Core.Utilities public static DataTable ToArrayTVP(this IEnumerable values, string columnName) { - var table = new DataTable(); + var table = new DataTable($"{columnName}Array", "dbo"); table.Columns.Add(columnName, typeof(T)); - table.SetTypeName($"[dbo].[{columnName}Array]"); if(values != null) { @@ -74,8 +73,7 @@ namespace Bit.Core.Utilities public static DataTable ToArrayTVP(this IEnumerable values) { - var table = new DataTable(); - table.SetTypeName("[dbo].[SelectionReadOnlyArray]"); + var table = new DataTable("SelectionReadOnlyArray", "dbo"); var idColumn = new DataColumn("Id", typeof(Guid)); table.Columns.Add(idColumn); diff --git a/src/Core/Utilities/ServiceCollectionExtensions.cs b/src/Core/Utilities/ServiceCollectionExtensions.cs index 9ab5624eb..e723a5a0f 100644 --- a/src/Core/Utilities/ServiceCollectionExtensions.cs +++ b/src/Core/Utilities/ServiceCollectionExtensions.cs @@ -52,9 +52,14 @@ namespace Bit.Core.Utilities { services.AddSingleton(); services.AddSingleton(); +#if NET461 services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); +#else + services.AddSingleton(); + services.AddSingleton(); +#endif + services.AddSingleton(); services.AddSingleton(); } @@ -154,6 +159,7 @@ namespace Bit.Core.Utilities public static void AddCustomDataProtectionServices( this IServiceCollection services, IHostingEnvironment env, GlobalSettings globalSettings) { +#if NET461 if(!env.IsDevelopment()) { var dataProtectionCert = CoreHelpers.GetCertificate(globalSettings.DataProtection.CertificateThumbprint); @@ -162,6 +168,7 @@ namespace Bit.Core.Utilities .PersistKeysToAzureBlobStorage(storageAccount, "aspnet-dataprotection/keys.xml") .ProtectKeysWithCertificate(dataProtectionCert); } +#endif } public static GlobalSettings AddGlobalSettingsServices(this IServiceCollection services, diff --git a/src/Identity/Identity.csproj b/src/Identity/Identity.csproj index 3a381e9a2..b3252d517 100644 --- a/src/Identity/Identity.csproj +++ b/src/Identity/Identity.csproj @@ -2,7 +2,7 @@ 1.8.2 - net461 + netcoreapp2.0;net461 Identity Bit.Identity bitwarden-Identity diff --git a/util/Mail/Mail.csproj b/util/Mail/Mail.csproj index 7f5115edf..561573df1 100644 --- a/util/Mail/Mail.csproj +++ b/util/Mail/Mail.csproj @@ -1,10 +1,8 @@  - netcoreapp1.1 + netcoreapp2.0 Mail - 1.1.1 - $(PackageTargetFallback);dotnet5.6;portable-net45+win8 Bit.Mail