Minor updates related to Github's comments

* Access-Token Header is not sent if it has not been configured (or left blank)
* Access token is now also sent in URI string with "token" as key
* NotificationType is manually added to the notification data (original data is cloned before to avoid conflict in case of re-usage by other notification handlers)
pull/3291/head
Namaneo 5 years ago
parent 78ac3984cb
commit 8ae98c91c1

@ -5,6 +5,6 @@ namespace Ombi.Api.Webhook
{ {
public interface IWebhookApi public interface IWebhookApi
{ {
Task PushAsync(string endpoint, string accessToken, IReadOnlyDictionary<string, string> parameters); Task PushAsync(string endpoint, string accessToken, IDictionary<string, string> parameters);
} }
} }

@ -17,17 +17,22 @@ namespace Ombi.Api.Webhook
private readonly IApi _api; private readonly IApi _api;
public async Task PushAsync(string baseUrl, string accessToken, IReadOnlyDictionary<string, string> parameters) public async Task PushAsync(string baseUrl, string accessToken, IDictionary<string, string> parameters)
{ {
var request = new Request("/", baseUrl, HttpMethod.Post); var request = new Request("/", baseUrl, HttpMethod.Post);
request.AddHeader("Access-Token", accessToken);
request.ApplicationJsonContentType(); if (!string.IsNullOrWhiteSpace(accessToken))
{
request.AddQueryString("token", accessToken);
request.AddHeader("Access-Token", accessToken);
}
var body = parameters.ToDictionary( var body = parameters.ToDictionary(
x => _nameResolver.GetResolvedPropertyName(x.Key), x => _nameResolver.GetResolvedPropertyName(x.Key),
x => x.Value x => x.Value
); );
request.ApplicationJsonContentType();
request.AddJsonBody(body); request.AddJsonBody(body);
await _api.Request(request); await _api.Request(request);

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Ombi.Api.Webhook; using Ombi.Api.Webhook;
@ -105,9 +106,11 @@ namespace Ombi.Notifications.Agents
return; return;
} }
var notificationData = parsed.Data.ToDictionary(x => x.Key, x => x.Value);
notificationData[nameof(NotificationType)] = type.ToString();
var notification = new NotificationMessage var notification = new NotificationMessage
{ {
Data = parsed.Data, Data = notificationData,
}; };
await Send(notification, settings); await Send(notification, settings);

@ -9,6 +9,6 @@ namespace Ombi.Notifications.Models
public string To { get; set; } public string To { get; set; }
public Dictionary<string, string> Other { get; set; } = new Dictionary<string, string>(); public Dictionary<string, string> Other { get; set; } = new Dictionary<string, string>();
public IReadOnlyDictionary<string, string> Data { get; set; } public IDictionary<string, string> Data { get; set; }
} }
} }
Loading…
Cancel
Save