1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

azure queue notification service

This commit is contained in:
Kyle Spearrin
2018-08-02 17:23:37 -04:00
parent 8b53ab2945
commit 0cde13e0c6
6 changed files with 393 additions and 51 deletions

View File

@ -0,0 +1,121 @@
using System;
using System.Threading.Tasks;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Bit.Core.Utilities;
using Microsoft.Extensions.Logging;
namespace Bit.Core.Services
{
public class MultiServicePushNotificationService : IPushNotificationService
{
private readonly List<IPushNotificationService> _services = new List<IPushNotificationService>();
public MultiServicePushNotificationService(
GlobalSettings globalSettings,
IHttpContextAccessor httpContextAccessor,
ILogger<RelayPushNotificationService> relayLogger)
{
if(globalSettings.SelfHosted)
{
if(CoreHelpers.SettingHasValue(globalSettings.PushRelayBaseUri) &&
globalSettings.Installation?.Id != null &&
CoreHelpers.SettingHasValue(globalSettings.Installation?.Key))
{
_services.Add(new RelayPushNotificationService(globalSettings, httpContextAccessor, relayLogger));
}
// TODO: ApiPushNotificationService for SignalR
}
else
{
#if NET471
_services.Add(new NotificationHubPushNotificationService(globalSettings, httpContextAccessor));
#endif
_services.Add(new AzureQueuePushNotificationService(globalSettings, httpContextAccessor));
}
}
public Task PushSyncCipherCreateAsync(Cipher cipher)
{
PushToServices((s) => s.PushSyncCipherCreateAsync(cipher));
return Task.FromResult(0);
}
public Task PushSyncCipherUpdateAsync(Cipher cipher)
{
PushToServices((s) => s.PushSyncCipherUpdateAsync(cipher));
return Task.FromResult(0);
}
public Task PushSyncCipherDeleteAsync(Cipher cipher)
{
PushToServices((s) => s.PushSyncCipherDeleteAsync(cipher));
return Task.FromResult(0);
}
public Task PushSyncFolderCreateAsync(Folder folder)
{
PushToServices((s) => s.PushSyncFolderCreateAsync(folder));
return Task.FromResult(0);
}
public Task PushSyncFolderUpdateAsync(Folder folder)
{
PushToServices((s) => s.PushSyncFolderUpdateAsync(folder));
return Task.FromResult(0);
}
public Task PushSyncFolderDeleteAsync(Folder folder)
{
PushToServices((s) => s.PushSyncFolderDeleteAsync(folder));
return Task.FromResult(0);
}
public Task PushSyncCiphersAsync(Guid userId)
{
PushToServices((s) => s.PushSyncCiphersAsync(userId));
return Task.FromResult(0);
}
public Task PushSyncVaultAsync(Guid userId)
{
PushToServices((s) => s.PushSyncVaultAsync(userId));
return Task.FromResult(0);
}
public Task PushSyncOrgKeysAsync(Guid userId)
{
PushToServices((s) => s.PushSyncOrgKeysAsync(userId));
return Task.FromResult(0);
}
public Task PushSyncSettingsAsync(Guid userId)
{
PushToServices((s) => s.PushSyncSettingsAsync(userId));
return Task.FromResult(0);
}
public Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier)
{
throw new NotImplementedException();
}
public Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier)
{
throw new NotImplementedException();
}
private void PushToServices(Func<IPushNotificationService, Task> pushFunc)
{
if(_services != null)
{
foreach(var service in _services)
{
pushFunc(service);
}
}
}
}
}