1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-15 10:08:14 -05:00

hub configurations

This commit is contained in:
Kyle Spearrin 2018-08-16 13:35:16 -04:00
parent 030f85278c
commit 42d3a2d8e3
6 changed files with 30 additions and 18 deletions

View File

@ -19,6 +19,7 @@ namespace Bit.Core
public virtual MailSettings Mail { get; set; } = new MailSettings(); public virtual MailSettings Mail { get; set; } = new MailSettings();
public virtual StorageSettings Storage { get; set; } = new StorageSettings(); public virtual StorageSettings Storage { get; set; } = new StorageSettings();
public virtual StorageSettings Events { 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 AttachmentSettings Attachment { get; set; } = new AttachmentSettings();
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings(); public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings(); public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings();

View File

@ -25,9 +25,9 @@ namespace Bit.Core.Services
GlobalSettings globalSettings, GlobalSettings globalSettings,
IHttpContextAccessor httpContextAccessor) IHttpContextAccessor httpContextAccessor)
{ {
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("sync"); _queue = queueClient.GetQueueReference("notifications");
_globalSettings = globalSettings; _globalSettings = globalSettings;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
} }

View File

@ -16,7 +16,8 @@ namespace Bit.Core.Services
public MultiServicePushNotificationService( public MultiServicePushNotificationService(
GlobalSettings globalSettings, GlobalSettings globalSettings,
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
ILogger<RelayPushNotificationService> relayLogger) ILogger<RelayPushNotificationService> relayLogger,
ILogger<HubApiPushNotificationService> hubLogger)
{ {
if(globalSettings.SelfHosted) if(globalSettings.SelfHosted)
{ {
@ -26,12 +27,22 @@ namespace Bit.Core.Services
{ {
_services.Add(new RelayPushNotificationService(globalSettings, httpContextAccessor, relayLogger)); _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 else
{ {
_services.Add(new NotificationHubPushNotificationService(globalSettings, httpContextAccessor)); if(CoreHelpers.SettingHasValue(globalSettings.NotificationHub.ConnectionString))
// _services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor)); {
_services.Add(new NotificationHubPushNotificationService(globalSettings, httpContextAccessor));
}
if(CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString))
{
// _services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor));
}
} }
} }

View File

@ -58,7 +58,7 @@ namespace Bit.Hub
{ {
var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString); var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient(); var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("sync"); _queue = queueClient.GetQueueReference("notifications");
while(!cancellationToken.IsCancellationRequested) while(!cancellationToken.IsCancellationRequested)
{ {

View File

@ -9,16 +9,16 @@ namespace Bit.Hub
{ {
[Authorize("Internal")] [Authorize("Internal")]
[SelfHosted(SelfHostedOnly = true)] [SelfHosted(SelfHostedOnly = true)]
public class NotificationController : Controller public class NotificationsController : Controller
{ {
private readonly IHubContext<SyncHub> _syncHubContext; private readonly IHubContext<SyncHub> _syncHubContext;
public NotificationController(IHubContext<SyncHub> syncHubContext) public NotificationsController(IHubContext<SyncHub> syncHubContext)
{ {
_syncHubContext = syncHubContext; _syncHubContext = syncHubContext;
} }
[HttpPost("~/notification")] [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, _syncHubContext);

View File

@ -1,8 +1,8 @@
using System; using System.Threading;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Core.Models; using Bit.Core.Models;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
namespace Bit.Hub namespace Bit.Hub
{ {
@ -17,8 +17,8 @@ namespace Bit.Hub
case Core.Enums.PushType.SyncCipherCreate: case Core.Enums.PushType.SyncCipherCreate:
case Core.Enums.PushType.SyncCipherDelete: case Core.Enums.PushType.SyncCipherDelete:
case Core.Enums.PushType.SyncLoginDelete: case Core.Enums.PushType.SyncLoginDelete:
var cipherPayload = (SyncCipherPushNotification)Convert.ChangeType( var cipherPayload = JsonConvert.DeserializeObject<SyncCipherPushNotification>(
notification.Payload, typeof(SyncCipherPushNotification)); JsonConvert.SerializeObject(notification.Payload));
if(cipherPayload.UserId.HasValue) if(cipherPayload.UserId.HasValue)
{ {
await hubContext.Clients.User(cipherPayload.UserId.ToString()) await hubContext.Clients.User(cipherPayload.UserId.ToString())
@ -34,8 +34,8 @@ namespace Bit.Hub
case Core.Enums.PushType.SyncFolderUpdate: case Core.Enums.PushType.SyncFolderUpdate:
case Core.Enums.PushType.SyncFolderCreate: case Core.Enums.PushType.SyncFolderCreate:
case Core.Enums.PushType.SyncFolderDelete: case Core.Enums.PushType.SyncFolderDelete:
var folderPayload = (SyncFolderPushNotification)Convert.ChangeType( var folderPayload = JsonConvert.DeserializeObject<SyncFolderPushNotification>(
notification.Payload, typeof(SyncFolderPushNotification)); JsonConvert.SerializeObject(notification.Payload));
await hubContext.Clients.User(folderPayload.UserId.ToString()) await hubContext.Clients.User(folderPayload.UserId.ToString())
.SendAsync("ReceiveMessage", notification, cancellationToken); .SendAsync("ReceiveMessage", notification, cancellationToken);
break; break;
@ -43,8 +43,8 @@ namespace Bit.Hub
case Core.Enums.PushType.SyncVault: case Core.Enums.PushType.SyncVault:
case Core.Enums.PushType.SyncOrgKeys: case Core.Enums.PushType.SyncOrgKeys:
case Core.Enums.PushType.SyncSettings: case Core.Enums.PushType.SyncSettings:
var userPayload = (SyncUserPushNotification)Convert.ChangeType( var userPayload = JsonConvert.DeserializeObject<SyncUserPushNotification>(
notification.Payload, typeof(SyncUserPushNotification)); JsonConvert.SerializeObject(notification.Payload));
await hubContext.Clients.User(userPayload.UserId.ToString()) await hubContext.Clients.User(userPayload.UserId.ToString())
.SendAsync("ReceiveMessage", notification, cancellationToken); .SendAsync("ReceiveMessage", notification, cancellationToken);
break; break;