Browse Source

Merge pull request #570 from colinin/fix-webhooks-resend

fix(webhooks): 事件重新发送时应与之前的格式保持一致.
pull/580/head
yx lin 4 years ago
committed by GitHub
parent
commit
b99571ed5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookManager.cs
  2. 11
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordAppService.cs
  3. 5
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/DefaultWebhookManager.cs
  4. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs
  5. 175
      aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.Designer.cs
  6. 26
      aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.cs
  7. 3
      aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs

12
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<string> GetSerializedBodyAsync(WebhookSenderArgs webhookSenderArgs)

11
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<string, string>();
if (!sendRecord.RequestHeaders.IsNullOrWhiteSpace())
{
headersToSend = JsonConvert.DeserializeObject<Dictionary<string, string>>(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
});
}
}

5
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);

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSendRecord.cs

@ -23,6 +23,8 @@ public class WebhookSendRecord : Entity<Guid>, 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; }

175
aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/20220413110728_Add-Field-SendExactSameData-With-SendAttempts.Designer.cs

@ -0,0 +1,175 @@
// <auto-generated />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<string>("Data")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Data");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime(6)")
.HasColumnName("DeletionTime");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)")
.HasColumnName("LastModificationTime");
b.Property<string>("RequestHeaders")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("RequestHeaders");
b.Property<string>("Response")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Response");
b.Property<string>("ResponseHeaders")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("ResponseHeaders");
b.Property<int?>("ResponseStatusCode")
.HasColumnType("int");
b.Property<bool>("SendExactSameData")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("WebhookEventId")
.HasColumnType("char(36)");
b.Property<Guid>("WebhookSubscriptionId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("WebhookEventId");
b.ToTable("AbpWebhooksSendAttempts", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSubscription", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)")
.HasColumnName("CreatorId");
b.Property<string>("Headers")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Headers");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("Secret")
.HasMaxLength(128)
.HasColumnType("varchar(128)")
.HasColumnName("Secret");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("WebhookUri")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("varchar(255)")
.HasColumnName("WebhookUri");
b.Property<string>("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
}
}
}

26
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<bool>(
name: "SendExactSameData",
table: "AbpWebhooksSendAttempts",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SendExactSameData",
table: "AbpWebhooksSendAttempts");
}
}
}

3
aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs

@ -92,6 +92,9 @@ namespace LY.MicroService.WebhooksManagement.Migrations
b.Property<int?>("ResponseStatusCode")
.HasColumnType("int");
b.Property<bool>("SendExactSameData")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");

Loading…
Cancel
Save