diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookManager.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookManager.cs index 7816fd807..d1929c4d1 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookManager.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookManager.cs @@ -6,6 +6,7 @@ using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Volo.Abp.Http; namespace LINGYUN.Abp.Webhooks { @@ -52,12 +53,15 @@ namespace LINGYUN.Abp.Webhooks throw new ArgumentNullException(nameof(serializedBody)); } - request.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); + request.Content = new StringContent(serializedBody, Encoding.UTF8, MimeTypes.Application.Json); - var secretBytes = Encoding.UTF8.GetBytes(secret); - var headerValue = string.Format(CultureInfo.InvariantCulture, SignatureHeaderValueTemplate, serializedBody.Sha256(secretBytes)); + if (!secret.IsNullOrWhiteSpace()) + { + var secretBytes = Encoding.UTF8.GetBytes(secret); + var headerValue = string.Format(CultureInfo.InvariantCulture, SignatureHeaderValueTemplate, serializedBody.Sha256(secretBytes)); - request.Headers.Add(SignatureHeaderName, headerValue); + request.Headers.Add(SignatureHeaderName, headerValue); + } } public virtual async Task GetSerializedBodyAsync(WebhookSenderArgs webhookSenderArgs) diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs index b3e52ae7f..53f4801ff 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs @@ -1,7 +1,7 @@ using LINGYUN.Abp.Webhooks; using LINGYUN.Abp.WebhooksManagement.Authorization; -using LINGYUN.Abp.WebhooksManagement.Extensions; using Microsoft.AspNetCore.Authorization; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -68,6 +68,12 @@ public class WebhookSendRecordAppService : WebhooksManagementAppServiceBase, IWe var sendEvent = await EventRepository.GetAsync(sendRecord.WebhookEventId); var subscription = await SubscriptionRepository.GetAsync(sendRecord.WebhookSubscriptionId); + var headersToSend = new Dictionary(); + if (!sendRecord.RequestHeaders.IsNullOrWhiteSpace()) + { + headersToSend = JsonConvert.DeserializeObject>(sendRecord.RequestHeaders); + } + using (CurrentTenant.Change(sendRecord.TenantId)) { await BackgroundJobManager.EnqueueAsync(new WebhookSenderArgs @@ -78,9 +84,10 @@ public class WebhookSendRecordAppService : WebhooksManagementAppServiceBase, IWe WebhookName = sendEvent.WebhookName, WebhookUri = subscription.WebhookUri, Data = sendEvent.Data, - Headers = subscription.GetWebhookHeaders(), + Headers = headersToSend, Secret = subscription.Secret, TryOnce = true, + SendExactSameData = sendRecord.SendExactSameData }); } } diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DefaultWebhookManager.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DefaultWebhookManager.cs index 659677104..5922ba9a5 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DefaultWebhookManager.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DefaultWebhookManager.cs @@ -40,7 +40,10 @@ public class DefaultWebhookManager : WebhookManager, ITransientDependency GuidGenerator.Create(), webhookSenderArgs.WebhookEventId, webhookSenderArgs.WebhookSubscriptionId, - webhookSenderArgs.TenantId); + webhookSenderArgs.TenantId) + { + SendExactSameData = webhookSenderArgs.SendExactSameData + }; await WebhookSendAttemptRepository.InsertAsync(record); diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs index 7b59f356e..83cf5ef51 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs @@ -23,6 +23,8 @@ public class WebhookSendRecord : Entity, IHasCreationTime, IHasModificatio public virtual string ResponseHeaders { get; protected set; } + public virtual bool SendExactSameData { get; set; } + public virtual DateTime CreationTime { get; set; } public virtual DateTime? LastModificationTime { get; set; } diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.Designer.cs b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.Designer.cs new file mode 100644 index 000000000..bc1d86085 --- /dev/null +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.Designer.cs @@ -0,0 +1,175 @@ +// +using System; +using LY.MicroService.WebhooksManagement.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Volo.Abp.EntityFrameworkCore; + +#nullable disable + +namespace LY.MicroService.WebhooksManagement.Migrations +{ + [DbContext(typeof(WebhooksManagementMigrationsDbContext))] + [Migration("20220413110728_Add-Field-SendExactSameData-With-SendAttempts")] + partial class AddFieldSendExactSameDataWithSendAttempts + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql) + .HasAnnotation("ProductVersion", "6.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookEventRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("Data") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("Data"); + + b.Property("DeletionTime") + .HasColumnType("datetime(6)") + .HasColumnName("DeletionTime"); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("tinyint(1)") + .HasDefaultValue(false) + .HasColumnName("IsDeleted"); + + b.Property("TenantId") + .HasColumnType("char(36)"); + + b.Property("WebhookName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)") + .HasColumnName("WebhookName"); + + b.HasKey("Id"); + + b.ToTable("AbpWebhooksEvents", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("LastModificationTime") + .HasColumnType("datetime(6)") + .HasColumnName("LastModificationTime"); + + b.Property("RequestHeaders") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("RequestHeaders"); + + b.Property("Response") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("Response"); + + b.Property("ResponseHeaders") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("ResponseHeaders"); + + b.Property("ResponseStatusCode") + .HasColumnType("int"); + + b.Property("SendExactSameData") + .HasColumnType("tinyint(1)"); + + b.Property("TenantId") + .HasColumnType("char(36)"); + + b.Property("WebhookEventId") + .HasColumnType("char(36)"); + + b.Property("WebhookSubscriptionId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("WebhookEventId"); + + b.ToTable("AbpWebhooksSendAttempts", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSubscription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("Headers") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("Headers"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("Secret") + .HasMaxLength(128) + .HasColumnType("varchar(128)") + .HasColumnName("Secret"); + + b.Property("TenantId") + .HasColumnType("char(36)"); + + b.Property("WebhookUri") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)") + .HasColumnName("WebhookUri"); + + b.Property("Webhooks") + .HasMaxLength(2147483647) + .HasColumnType("longtext") + .HasColumnName("Webhooks"); + + b.HasKey("Id"); + + b.ToTable("AbpWebhooksSubscriptions", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", b => + { + b.HasOne("LINGYUN.Abp.WebhooksManagement.WebhookEventRecord", "WebhookEvent") + .WithOne() + .HasForeignKey("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", "WebhookEventId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WebhookEvent"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.cs b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.cs new file mode 100644 index 000000000..15e36d842 --- /dev/null +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LY.MicroService.WebhooksManagement.Migrations +{ + public partial class AddFieldSendExactSameDataWithSendAttempts : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "SendExactSameData", + table: "AbpWebhooksSendAttempts", + type: "tinyint(1)", + nullable: false, + defaultValue: false); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "SendExactSameData", + table: "AbpWebhooksSendAttempts"); + } + } +} diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs index 1b8d69039..5911b2582 100644 --- a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs @@ -92,6 +92,9 @@ namespace LY.MicroService.WebhooksManagement.Migrations b.Property("ResponseStatusCode") .HasColumnType("int"); + b.Property("SendExactSameData") + .HasColumnType("tinyint(1)"); + b.Property("TenantId") .HasColumnType("char(36)");