Browse Source

rename hub to notifications

pull/342/head
Kyle Spearrin 7 years ago
parent
commit
80a49e53ac
  1. 2
      bitwarden-core.sln
  2. 10
      src/Notifications/AzureQueueHostedService.cs
  3. 10
      src/Notifications/Controllers/NotificationsController.cs
  4. 4
      src/Notifications/HubHelpers.cs
  5. 4
      src/Notifications/Notifications.csproj
  6. 4
      src/Notifications/NotificationsHub.cs
  7. 2
      src/Notifications/Program.cs
  8. 2
      src/Notifications/Properties/launchSettings.json
  9. 10
      src/Notifications/Startup.cs
  10. 2
      src/Notifications/SubjectUserIdProvider.cs
  11. 0
      src/Notifications/appsettings.Production.json
  12. 0
      src/Notifications/appsettings.json

2
bitwarden-core.sln

@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventsProcessor", "src\Even @@ -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

10
src/Hub/AzureQueueHostedService.cs → src/Notifications/AzureQueueHostedService.cs

@ -11,19 +11,21 @@ using Microsoft.WindowsAzure.Storage; @@ -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<SyncHub> _hubContext;
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly GlobalSettings _globalSettings;
private Task _executingTask;
private CancellationTokenSource _cts;
private CloudQueue _queue;
public AzureQueueHostedService(ILogger<AzureQueueHostedService> logger, IHubContext<SyncHub> hubContext,
public AzureQueueHostedService(
ILogger<AzureQueueHostedService> logger,
IHubContext<NotificationsHub> hubContext,
GlobalSettings globalSettings)
{
_logger = logger;
@ -56,7 +58,7 @@ namespace Bit.Hub @@ -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");

10
src/Hub/Controllers/NotificationsController.cs → src/Notifications/Controllers/NotificationsController.cs

@ -5,23 +5,23 @@ using Microsoft.AspNetCore.Authorization; @@ -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<SyncHub> _syncHubContext;
private readonly IHubContext<NotificationsHub> _hubContext;
public NotificationsController(IHubContext<SyncHub> syncHubContext)
public NotificationsController(IHubContext<NotificationsHub> hubContext)
{
_syncHubContext = syncHubContext;
_hubContext = hubContext;
}
[HttpPost("~/notifications")]
public async Task PostNotification([FromBody]PushNotificationData<object> model)
{
await HubHelpers.SendNotificationToHubAsync(model, _syncHubContext);
await HubHelpers.SendNotificationToHubAsync(model, _hubContext);
}
}
}

4
src/Hub/HubHelpers.cs → src/Notifications/HubHelpers.cs

@ -4,12 +4,12 @@ using Bit.Core.Models; @@ -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<object> notification,
IHubContext<SyncHub> hubContext, CancellationToken cancellationToken = default(CancellationToken))
IHubContext<NotificationsHub> hubContext, CancellationToken cancellationToken = default(CancellationToken))
{
switch(notification.Type)
{

4
src/Hub/Hub.csproj → src/Notifications/Notifications.csproj

@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
<PropertyGroup>
<Version>1.23.0</Version>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>Bit.Hub</RootNamespace>
<UserSecretsId>bitwarden-Hub</UserSecretsId>
<RootNamespace>Bit.Notifications</RootNamespace>
<UserSecretsId>bitwarden-Notifications</UserSecretsId>
</PropertyGroup>
<ItemGroup>

4
src/Hub/SyncHub.cs → src/Notifications/NotificationsHub.cs

@ -3,10 +3,10 @@ using System.Threading.Tasks; @@ -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()
{

2
src/Hub/Program.cs → src/Notifications/Program.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace Bit.Hub
namespace Bit.Notifications
{
public class Program
{

2
src/Hub/Properties/launchSettings.json → src/Notifications/Properties/launchSettings.json

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Bit.Hub": {
"Notifications": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",

10
src/Hub/Startup.cs → src/Notifications/Startup.cs

@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; @@ -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 @@ -61,7 +61,11 @@ namespace Bit.Hub
services.AddMvc();
// Hosted Services
services.AddHostedService<AzureQueueHostedService>();
if(!globalSettings.SelfHosted &&
CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString))
{
services.AddHostedService<AzureQueueHostedService>();
}
}
public void Configure(
@ -101,7 +105,7 @@ namespace Bit.Hub @@ -101,7 +105,7 @@ namespace Bit.Hub
// Add SignlarR
app.UseSignalR(routes =>
{
routes.MapHub<SyncHub>("/sync");
routes.MapHub<NotificationsHub>("/notifications-hub");
});
// Add MVC to the request pipeline.

2
src/Hub/SubjectUserIdProvider.cs → src/Notifications/SubjectUserIdProvider.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
using IdentityModel;
using Microsoft.AspNetCore.SignalR;
namespace Bit.Hub
namespace Bit.Notifications
{
public class SubjectUserIdProvider : IUserIdProvider
{

0
src/Hub/appsettings.Production.json → src/Notifications/appsettings.Production.json

0
src/Hub/appsettings.json → src/Notifications/appsettings.json

Loading…
Cancel
Save