mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
rename hub to notifications
This commit is contained in:
parent
42d3a2d8e3
commit
80a49e53ac
@ -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
|
||||
|
@ -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
|
||||
|
||||
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");
|
||||
|
@ -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,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)
|
||||
{
|
@ -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>
|
@ -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()
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Bit.Hub
|
||||
namespace Bit.Notifications
|
||||
{
|
||||
public class Program
|
||||
{
|
@ -15,7 +15,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Bit.Hub": {
|
||||
"Notifications": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5000",
|
@ -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<AzureQueueHostedService>();
|
||||
if(!globalSettings.SelfHosted &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString))
|
||||
{
|
||||
services.AddHostedService<AzureQueueHostedService>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Configure(
|
||||
@ -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.
|
@ -1,7 +1,7 @@
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Bit.Hub
|
||||
namespace Bit.Notifications
|
||||
{
|
||||
public class SubjectUserIdProvider : IUserIdProvider
|
||||
{
|
Loading…
Reference in New Issue
Block a user