1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

rename hub to notifications

This commit is contained in:
Kyle Spearrin 2018-08-16 13:45:31 -04:00
parent 42d3a2d8e3
commit 80a49e53ac
12 changed files with 28 additions and 22 deletions

View File

@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventsProcessor", "src\Even
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Admin", "src\Admin\Admin.csproj", "{B131CEF3-89FB-4C90-ADB0-9E9C4246EB56}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Admin", "src\Admin\Admin.csproj", "{B131CEF3-89FB-4C90-ADB0-9E9C4246EB56}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -11,19 +11,21 @@ using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue; using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Bit.Hub namespace Bit.Notifications
{ {
public class AzureQueueHostedService : IHostedService, IDisposable public class AzureQueueHostedService : IHostedService, IDisposable
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IHubContext<SyncHub> _hubContext; private readonly IHubContext<NotificationsHub> _hubContext;
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
private Task _executingTask; private Task _executingTask;
private CancellationTokenSource _cts; private CancellationTokenSource _cts;
private CloudQueue _queue; private CloudQueue _queue;
public AzureQueueHostedService(ILogger<AzureQueueHostedService> logger, IHubContext<SyncHub> hubContext, public AzureQueueHostedService(
ILogger<AzureQueueHostedService> logger,
IHubContext<NotificationsHub> hubContext,
GlobalSettings globalSettings) GlobalSettings globalSettings)
{ {
_logger = logger; _logger = logger;
@ -56,7 +58,7 @@ namespace Bit.Hub
private async Task ExecuteAsync(CancellationToken cancellationToken) private async Task ExecuteAsync(CancellationToken cancellationToken)
{ {
var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString); var storageAccount = CloudStorageAccount.Parse(_globalSettings.Notifications.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient(); var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("notifications"); _queue = queueClient.GetQueueReference("notifications");

View File

@ -5,23 +5,23 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
namespace Bit.Hub namespace Bit.Notifications
{ {
[Authorize("Internal")] [Authorize("Internal")]
[SelfHosted(SelfHostedOnly = true)] [SelfHosted(SelfHostedOnly = true)]
public class NotificationsController : Controller 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")] [HttpPost("~/notifications")]
public async Task PostNotification([FromBody]PushNotificationData<object> model) public async Task PostNotification([FromBody]PushNotificationData<object> model)
{ {
await HubHelpers.SendNotificationToHubAsync(model, _syncHubContext); await HubHelpers.SendNotificationToHubAsync(model, _hubContext);
} }
} }
} }

View File

@ -4,12 +4,12 @@ using Bit.Core.Models;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Bit.Hub namespace Bit.Notifications
{ {
public static class HubHelpers public static class HubHelpers
{ {
public static async Task SendNotificationToHubAsync(PushNotificationData<object> notification, 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) switch(notification.Type)
{ {

View File

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

View File

@ -3,10 +3,10 @@ using System.Threading.Tasks;
using Bit.Core; using Bit.Core;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
namespace Bit.Hub namespace Bit.Notifications
{ {
[Authorize("Application")] [Authorize("Application")]
public class SyncHub : Microsoft.AspNetCore.SignalR.Hub public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub
{ {
public override async Task OnConnectedAsync() public override async Task OnConnectedAsync()
{ {

View File

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

View File

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

View File

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

View File

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