mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
hub configurations
This commit is contained in:
parent
030f85278c
commit
42d3a2d8e3
@ -19,6 +19,7 @@ namespace Bit.Core
|
||||
public virtual MailSettings Mail { get; set; } = new MailSettings();
|
||||
public virtual StorageSettings Storage { get; set; } = new StorageSettings();
|
||||
public virtual StorageSettings Events { get; set; } = new StorageSettings();
|
||||
public virtual StorageSettings Notifications { get; set; } = new StorageSettings();
|
||||
public virtual AttachmentSettings Attachment { get; set; } = new AttachmentSettings();
|
||||
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
|
||||
public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings();
|
||||
|
@ -25,9 +25,9 @@ namespace Bit.Core.Services
|
||||
GlobalSettings globalSettings,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Events.ConnectionString);
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Notifications.ConnectionString);
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
_queue = queueClient.GetQueueReference("sync");
|
||||
_queue = queueClient.GetQueueReference("notifications");
|
||||
_globalSettings = globalSettings;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ namespace Bit.Core.Services
|
||||
public MultiServicePushNotificationService(
|
||||
GlobalSettings globalSettings,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ILogger<RelayPushNotificationService> relayLogger)
|
||||
ILogger<RelayPushNotificationService> relayLogger,
|
||||
ILogger<HubApiPushNotificationService> hubLogger)
|
||||
{
|
||||
if(globalSettings.SelfHosted)
|
||||
{
|
||||
@ -26,12 +27,22 @@ namespace Bit.Core.Services
|
||||
{
|
||||
_services.Add(new RelayPushNotificationService(globalSettings, httpContextAccessor, relayLogger));
|
||||
}
|
||||
// TODO: ApiPushNotificationService for SignalR
|
||||
if(CoreHelpers.SettingHasValue(globalSettings.InternalIdentityKey) &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.BaseServiceUri.InternalHub))
|
||||
{
|
||||
// _services.Add(new HubApiPushNotificationService(globalSettings, httpContextAccessor, hubLogger));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_services.Add(new NotificationHubPushNotificationService(globalSettings, httpContextAccessor));
|
||||
// _services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor));
|
||||
if(CoreHelpers.SettingHasValue(globalSettings.NotificationHub.ConnectionString))
|
||||
{
|
||||
_services.Add(new NotificationHubPushNotificationService(globalSettings, httpContextAccessor));
|
||||
}
|
||||
if(CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString))
|
||||
{
|
||||
// _services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace Bit.Hub
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString);
|
||||
var queueClient = storageAccount.CreateCloudQueueClient();
|
||||
_queue = queueClient.GetQueueReference("sync");
|
||||
_queue = queueClient.GetQueueReference("notifications");
|
||||
|
||||
while(!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
|
@ -9,16 +9,16 @@ namespace Bit.Hub
|
||||
{
|
||||
[Authorize("Internal")]
|
||||
[SelfHosted(SelfHostedOnly = true)]
|
||||
public class NotificationController : Controller
|
||||
public class NotificationsController : Controller
|
||||
{
|
||||
private readonly IHubContext<SyncHub> _syncHubContext;
|
||||
|
||||
public NotificationController(IHubContext<SyncHub> syncHubContext)
|
||||
public NotificationsController(IHubContext<SyncHub> syncHubContext)
|
||||
{
|
||||
_syncHubContext = syncHubContext;
|
||||
}
|
||||
|
||||
[HttpPost("~/notification")]
|
||||
[HttpPost("~/notifications")]
|
||||
public async Task PostNotification([FromBody]PushNotificationData<object> model)
|
||||
{
|
||||
await HubHelpers.SendNotificationToHubAsync(model, _syncHubContext);
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Hub
|
||||
{
|
||||
@ -17,8 +17,8 @@ namespace Bit.Hub
|
||||
case Core.Enums.PushType.SyncCipherCreate:
|
||||
case Core.Enums.PushType.SyncCipherDelete:
|
||||
case Core.Enums.PushType.SyncLoginDelete:
|
||||
var cipherPayload = (SyncCipherPushNotification)Convert.ChangeType(
|
||||
notification.Payload, typeof(SyncCipherPushNotification));
|
||||
var cipherPayload = JsonConvert.DeserializeObject<SyncCipherPushNotification>(
|
||||
JsonConvert.SerializeObject(notification.Payload));
|
||||
if(cipherPayload.UserId.HasValue)
|
||||
{
|
||||
await hubContext.Clients.User(cipherPayload.UserId.ToString())
|
||||
@ -34,8 +34,8 @@ namespace Bit.Hub
|
||||
case Core.Enums.PushType.SyncFolderUpdate:
|
||||
case Core.Enums.PushType.SyncFolderCreate:
|
||||
case Core.Enums.PushType.SyncFolderDelete:
|
||||
var folderPayload = (SyncFolderPushNotification)Convert.ChangeType(
|
||||
notification.Payload, typeof(SyncFolderPushNotification));
|
||||
var folderPayload = JsonConvert.DeserializeObject<SyncFolderPushNotification>(
|
||||
JsonConvert.SerializeObject(notification.Payload));
|
||||
await hubContext.Clients.User(folderPayload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", notification, cancellationToken);
|
||||
break;
|
||||
@ -43,8 +43,8 @@ namespace Bit.Hub
|
||||
case Core.Enums.PushType.SyncVault:
|
||||
case Core.Enums.PushType.SyncOrgKeys:
|
||||
case Core.Enums.PushType.SyncSettings:
|
||||
var userPayload = (SyncUserPushNotification)Convert.ChangeType(
|
||||
notification.Payload, typeof(SyncUserPushNotification));
|
||||
var userPayload = JsonConvert.DeserializeObject<SyncUserPushNotification>(
|
||||
JsonConvert.SerializeObject(notification.Payload));
|
||||
await hubContext.Clients.User(userPayload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", notification, cancellationToken);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user