-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from shibayan/feature/event-webhook
Adding Event webhook
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
AzureKeyVault.LetsEncrypt/Internal/InProcLifeCycleNotificationHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Azure.WebJobs.Extensions.DurableTask; | ||
|
||
namespace AzureKeyVault.LetsEncrypt.Internal | ||
{ | ||
internal class InProcLifeCycleNotificationHelper : ILifeCycleNotificationHelper | ||
{ | ||
public Task OrchestratorStartingAsync(string hubName, string functionName, string instanceId, bool isReplay) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OrchestratorCompletedAsync(string hubName, string functionName, string instanceId, bool continuedAsNew, bool isReplay) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public async Task OrchestratorFailedAsync(string hubName, string functionName, string instanceId, string reason, bool isReplay) | ||
{ | ||
await PostEventAsync(functionName, instanceId, reason); | ||
} | ||
|
||
public Task OrchestratorTerminatedAsync(string hubName, string functionName, string instanceId, string reason) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
private static readonly HttpClient _httpClient = new HttpClient(); | ||
|
||
private static async Task PostEventAsync(string functionName, string instanceId, string reason) | ||
{ | ||
if (string.IsNullOrEmpty(Settings.Default.Webhook)) | ||
{ | ||
return; | ||
} | ||
|
||
object model; | ||
|
||
if (Settings.Default.Webhook.Contains("hooks.slack.com")) | ||
{ | ||
model = new | ||
{ | ||
attachments = new[] | ||
{ | ||
new | ||
{ | ||
title = functionName, | ||
text = reason, | ||
color = "danger" | ||
} | ||
} | ||
}; | ||
} | ||
else | ||
{ | ||
model = new | ||
{ | ||
functionName, | ||
instanceId, | ||
reason | ||
}; | ||
} | ||
|
||
await _httpClient.PostAsJsonAsync(Settings.Default.Webhook, model); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters