1
0
mirror of https://github.com/bitwarden/server synced 2026-01-01 16:13:33 +00:00

[PM-22380] Enable NRT for some Core project files (#5912)

* Enable NRT for Core/Jobs files

* Enable NRT for Core/HostedServices files

* Enable NRT for Core/Exceptions files

* Enable NRT for Core/NotificationHub files

---------

Co-authored-by: Bernd Schoolmann <mail@quexten.com>
This commit is contained in:
Ben Bryant
2025-06-06 12:59:57 +01:00
committed by GitHub
parent 25d5efacd8
commit 20d3911b80
26 changed files with 99 additions and 39 deletions

View File

@@ -2,6 +2,8 @@
namespace Bit.Core.NotificationHub;
#nullable enable
public interface INotificationHubProxy
{
Task<(INotificationHubClient Client, NotificationOutcome Outcome)[]> SendTemplateNotificationAsync(IDictionary<string, string> properties, string tagExpression);

View File

@@ -2,6 +2,8 @@
namespace Bit.Core.NotificationHub;
#nullable enable
public interface INotificationHubPool
{
NotificationHubConnection ConnectionFor(Guid comb);

View File

@@ -2,6 +2,8 @@
namespace Bit.Core.NotificationHub;
#nullable enable
public class NotificationHubClientProxy : INotificationHubProxy
{
private readonly IEnumerable<INotificationHubClient> _clients;

View File

@@ -1,4 +1,5 @@
using System.Security.Cryptography;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using Bit.Core.Settings;
@@ -7,21 +8,23 @@ using Microsoft.Azure.NotificationHubs;
namespace Bit.Core.NotificationHub;
#nullable enable
public class NotificationHubConnection
{
public string HubName { get; init; }
public string ConnectionString { get; init; }
public string? HubName { get; init; }
public string? ConnectionString { get; init; }
private Lazy<NotificationHubConnectionStringBuilder> _parsedConnectionString;
public Uri Endpoint => _parsedConnectionString.Value.Endpoint;
private string SasKey => _parsedConnectionString.Value.SharedAccessKey;
private string SasKeyName => _parsedConnectionString.Value.SharedAccessKeyName;
public bool EnableSendTracing { get; init; }
private NotificationHubClient _hubClient;
private NotificationHubClient? _hubClient;
/// <summary>
/// Gets the NotificationHubClient for this connection.
///
///
/// If the client is null, it will be initialized.
///
///
/// <throws>Exception</throws> if the connection is invalid.
/// </summary>
public NotificationHubClient HubClient
@@ -45,13 +48,13 @@ public class NotificationHubConnection
}
/// <summary>
/// Gets the start date for registration.
///
///
/// If null, registration is always disabled.
/// </summary>
public DateTime? RegistrationStartDate { get; init; }
/// <summary>
/// Gets the end date for registration.
///
///
/// If null, registration has no end date.
/// </summary>
public DateTime? RegistrationEndDate { get; init; }
@@ -155,9 +158,10 @@ public class NotificationHubConnection
};
}
[MemberNotNull(nameof(_hubClient))]
private NotificationHubConnection Init()
{
HubClient = NotificationHubClient.CreateClientFromConnectionString(ConnectionString, HubName, EnableSendTracing);
_hubClient = NotificationHubClient.CreateClientFromConnectionString(ConnectionString, HubName, EnableSendTracing);
return this;
}

View File

@@ -5,6 +5,8 @@ using Microsoft.Extensions.Logging;
namespace Bit.Core.NotificationHub;
#nullable enable
public class NotificationHubPool : INotificationHubPool
{
private List<NotificationHubConnection> _connections { get; }

View File

@@ -19,6 +19,8 @@ using Notification = Bit.Core.NotificationCenter.Entities.Notification;
namespace Bit.Core.NotificationHub;
#nullable enable
/// <summary>
/// Sends mobile push notifications to the Azure Notification Hub.
/// Used by Cloud-Hosted environments.

View File

@@ -13,6 +13,8 @@ using Microsoft.Extensions.Logging;
namespace Bit.Core.NotificationHub;
#nullable enable
public class NotificationHubPushRegistrationService : IPushRegistrationService
{
private static readonly JsonSerializerOptions webPushSerializationOptions = new()
@@ -37,7 +39,7 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
}
public async Task CreateOrUpdateRegistrationAsync(PushRegistrationData data, string deviceId, string userId,
string identifier, DeviceType type, IEnumerable<string> organizationIds, Guid installationId)
string? identifier, DeviceType type, IEnumerable<string> organizationIds, Guid installationId)
{
var orgIds = organizationIds.ToList();
var clientType = DeviceTypes.ToClientType(type);
@@ -79,7 +81,7 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
}
private async Task CreateOrUpdateMobileRegistrationAsync(Installation installation, string userId,
string identifier, ClientType clientType, List<string> organizationIds, DeviceType type, Guid installationId)
string? identifier, ClientType clientType, List<string> organizationIds, DeviceType type, Guid installationId)
{
if (string.IsNullOrWhiteSpace(installation.PushChannel))
{
@@ -137,7 +139,7 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
}
private async Task CreateOrUpdateWebRegistrationAsync(string endpoint, string p256dh, string auth, Installation installation, string userId,
string identifier, ClientType clientType, List<string> organizationIds, Guid installationId)
string? identifier, ClientType clientType, List<string> organizationIds, Guid installationId)
{
// The Azure SDK is currently lacking support for web push registrations.
// We need to use the REST API directly.
@@ -187,7 +189,7 @@ public class NotificationHubPushRegistrationService : IPushRegistrationService
}
private static KeyValuePair<string, InstallationTemplate> BuildInstallationTemplate(string templateId, [StringSyntax(StringSyntaxAttribute.Json)] string templateBody,
string userId, string identifier, ClientType clientType, List<string> organizationIds, Guid installationId)
string userId, string? identifier, ClientType clientType, List<string> organizationIds, Guid installationId)
{
var fullTemplateId = $"template:{templateId}";

View File

@@ -1,5 +1,7 @@
namespace Bit.Core.NotificationHub;
#nullable enable
public record struct WebPushRegistrationData
{
public string Endpoint { get; init; }
@@ -9,9 +11,9 @@ public record struct WebPushRegistrationData
public record class PushRegistrationData
{
public string Token { get; set; }
public string? Token { get; set; }
public WebPushRegistrationData? WebPush { get; set; }
public PushRegistrationData(string token)
public PushRegistrationData(string? token)
{
Token = token;
}