From 80a49e53ac92261c06a18d0efe14805b0c3d3d9d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 16 Aug 2018 13:45:31 -0400 Subject: [PATCH] rename hub to notifications --- bitwarden-core.sln | 2 +- src/{Hub => Notifications}/AzureQueueHostedService.cs | 10 ++++++---- .../Controllers/NotificationsController.cs | 10 +++++----- src/{Hub => Notifications}/HubHelpers.cs | 4 ++-- .../Hub.csproj => Notifications/Notifications.csproj} | 4 ++-- .../SyncHub.cs => Notifications/NotificationsHub.cs} | 4 ++-- src/{Hub => Notifications}/Program.cs | 2 +- .../Properties/launchSettings.json | 2 +- src/{Hub => Notifications}/Startup.cs | 10 +++++++--- src/{Hub => Notifications}/SubjectUserIdProvider.cs | 2 +- src/{Hub => Notifications}/appsettings.Production.json | 0 src/{Hub => Notifications}/appsettings.json | 0 12 files changed, 28 insertions(+), 22 deletions(-) rename src/{Hub => Notifications}/AzureQueueHostedService.cs (90%) rename src/{Hub => Notifications}/Controllers/NotificationsController.cs (71%) rename src/{Hub => Notifications}/HubHelpers.cs (94%) rename src/{Hub/Hub.csproj => Notifications/Notifications.csproj} (80%) rename src/{Hub/SyncHub.cs => Notifications/NotificationsHub.cs} (91%) rename src/{Hub => Notifications}/Program.cs (93%) rename src/{Hub => Notifications}/Properties/launchSettings.json (96%) rename src/{Hub => Notifications}/Startup.cs (91%) rename src/{Hub => Notifications}/SubjectUserIdProvider.cs (91%) rename src/{Hub => Notifications}/appsettings.Production.json (100%) rename src/{Hub => Notifications}/appsettings.json (100%) diff --git a/bitwarden-core.sln b/bitwarden-core.sln index 5dc7bb0953..5ea2a1dced 100644 --- a/bitwarden-core.sln +++ b/bitwarden-core.sln @@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventsProcessor", "src\Even EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Admin", "src\Admin\Admin.csproj", "{B131CEF3-89FB-4C90-ADB0-9E9C4246EB56}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hub", "src\Hub\Hub.csproj", "{28635027-20E5-42FA-B218-B6C878DE5350}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notifications", "src\Notifications\Notifications.csproj", "{28635027-20E5-42FA-B218-B6C878DE5350}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Hub/AzureQueueHostedService.cs b/src/Notifications/AzureQueueHostedService.cs similarity index 90% rename from src/Hub/AzureQueueHostedService.cs rename to src/Notifications/AzureQueueHostedService.cs index 799b05b6bb..b44b37ab0a 100644 --- a/src/Hub/AzureQueueHostedService.cs +++ b/src/Notifications/AzureQueueHostedService.cs @@ -11,19 +11,21 @@ using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Queue; using Newtonsoft.Json; -namespace Bit.Hub +namespace Bit.Notifications { public class AzureQueueHostedService : IHostedService, IDisposable { private readonly ILogger _logger; - private readonly IHubContext _hubContext; + private readonly IHubContext _hubContext; private readonly GlobalSettings _globalSettings; private Task _executingTask; private CancellationTokenSource _cts; private CloudQueue _queue; - public AzureQueueHostedService(ILogger logger, IHubContext hubContext, + public AzureQueueHostedService( + ILogger logger, + IHubContext hubContext, GlobalSettings globalSettings) { _logger = logger; @@ -56,7 +58,7 @@ namespace Bit.Hub private async Task ExecuteAsync(CancellationToken cancellationToken) { - var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString); + var storageAccount = CloudStorageAccount.Parse(_globalSettings.Notifications.ConnectionString); var queueClient = storageAccount.CreateCloudQueueClient(); _queue = queueClient.GetQueueReference("notifications"); diff --git a/src/Hub/Controllers/NotificationsController.cs b/src/Notifications/Controllers/NotificationsController.cs similarity index 71% rename from src/Hub/Controllers/NotificationsController.cs rename to src/Notifications/Controllers/NotificationsController.cs index f31ff8be7b..1adebfffd4 100644 --- a/src/Hub/Controllers/NotificationsController.cs +++ b/src/Notifications/Controllers/NotificationsController.cs @@ -5,23 +5,23 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; -namespace Bit.Hub +namespace Bit.Notifications { [Authorize("Internal")] [SelfHosted(SelfHostedOnly = true)] public class NotificationsController : Controller { - private readonly IHubContext _syncHubContext; + private readonly IHubContext _hubContext; - public NotificationsController(IHubContext syncHubContext) + public NotificationsController(IHubContext hubContext) { - _syncHubContext = syncHubContext; + _hubContext = hubContext; } [HttpPost("~/notifications")] public async Task PostNotification([FromBody]PushNotificationData model) { - await HubHelpers.SendNotificationToHubAsync(model, _syncHubContext); + await HubHelpers.SendNotificationToHubAsync(model, _hubContext); } } } diff --git a/src/Hub/HubHelpers.cs b/src/Notifications/HubHelpers.cs similarity index 94% rename from src/Hub/HubHelpers.cs rename to src/Notifications/HubHelpers.cs index 0c265161c6..87370fc16d 100644 --- a/src/Hub/HubHelpers.cs +++ b/src/Notifications/HubHelpers.cs @@ -4,12 +4,12 @@ using Bit.Core.Models; using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json; -namespace Bit.Hub +namespace Bit.Notifications { public static class HubHelpers { public static async Task SendNotificationToHubAsync(PushNotificationData notification, - IHubContext hubContext, CancellationToken cancellationToken = default(CancellationToken)) + IHubContext hubContext, CancellationToken cancellationToken = default(CancellationToken)) { switch(notification.Type) { diff --git a/src/Hub/Hub.csproj b/src/Notifications/Notifications.csproj similarity index 80% rename from src/Hub/Hub.csproj rename to src/Notifications/Notifications.csproj index 07b015e397..e73b468b8c 100644 --- a/src/Hub/Hub.csproj +++ b/src/Notifications/Notifications.csproj @@ -3,8 +3,8 @@ 1.23.0 netcoreapp2.1 - Bit.Hub - bitwarden-Hub + Bit.Notifications + bitwarden-Notifications diff --git a/src/Hub/SyncHub.cs b/src/Notifications/NotificationsHub.cs similarity index 91% rename from src/Hub/SyncHub.cs rename to src/Notifications/NotificationsHub.cs index 758821d485..0141fa3245 100644 --- a/src/Hub/SyncHub.cs +++ b/src/Notifications/NotificationsHub.cs @@ -3,10 +3,10 @@ using System.Threading.Tasks; using Bit.Core; using Microsoft.AspNetCore.Authorization; -namespace Bit.Hub +namespace Bit.Notifications { [Authorize("Application")] - public class SyncHub : Microsoft.AspNetCore.SignalR.Hub + public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub { public override async Task OnConnectedAsync() { diff --git a/src/Hub/Program.cs b/src/Notifications/Program.cs similarity index 93% rename from src/Hub/Program.cs rename to src/Notifications/Program.cs index b3c7482d4f..f1a2db78d5 100644 --- a/src/Hub/Program.cs +++ b/src/Notifications/Program.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -namespace Bit.Hub +namespace Bit.Notifications { public class Program { diff --git a/src/Hub/Properties/launchSettings.json b/src/Notifications/Properties/launchSettings.json similarity index 96% rename from src/Hub/Properties/launchSettings.json rename to src/Notifications/Properties/launchSettings.json index c68d3d815f..60107fae38 100644 --- a/src/Hub/Properties/launchSettings.json +++ b/src/Notifications/Properties/launchSettings.json @@ -15,7 +15,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Bit.Hub": { + "Notifications": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "http://localhost:5000", diff --git a/src/Hub/Startup.cs b/src/Notifications/Startup.cs similarity index 91% rename from src/Hub/Startup.cs rename to src/Notifications/Startup.cs index 0ac22e93b8..56821d27ed 100644 --- a/src/Hub/Startup.cs +++ b/src/Notifications/Startup.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Logging; using Serilog.Events; -namespace Bit.Hub +namespace Bit.Notifications { public class Startup { @@ -61,7 +61,11 @@ namespace Bit.Hub services.AddMvc(); // Hosted Services - services.AddHostedService(); + if(!globalSettings.SelfHosted && + CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString)) + { + services.AddHostedService(); + } } public void Configure( @@ -101,7 +105,7 @@ namespace Bit.Hub // Add SignlarR app.UseSignalR(routes => { - routes.MapHub("/sync"); + routes.MapHub("/notifications-hub"); }); // Add MVC to the request pipeline. diff --git a/src/Hub/SubjectUserIdProvider.cs b/src/Notifications/SubjectUserIdProvider.cs similarity index 91% rename from src/Hub/SubjectUserIdProvider.cs rename to src/Notifications/SubjectUserIdProvider.cs index 3cd7489a35..ee6ab6be57 100644 --- a/src/Hub/SubjectUserIdProvider.cs +++ b/src/Notifications/SubjectUserIdProvider.cs @@ -1,7 +1,7 @@ using IdentityModel; using Microsoft.AspNetCore.SignalR; -namespace Bit.Hub +namespace Bit.Notifications { public class SubjectUserIdProvider : IUserIdProvider { diff --git a/src/Hub/appsettings.Production.json b/src/Notifications/appsettings.Production.json similarity index 100% rename from src/Hub/appsettings.Production.json rename to src/Notifications/appsettings.Production.json diff --git a/src/Hub/appsettings.json b/src/Notifications/appsettings.json similarity index 100% rename from src/Hub/appsettings.json rename to src/Notifications/appsettings.json