Skip to content

Commit

Permalink
Adding generic webhook extra data (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Jan 6, 2025
1 parent 55cf91b commit 97f7a10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion KeyVault.Acmebot/Internal/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Reflection;
using System;
using System.Reflection;

namespace KeyVault.Acmebot.Internal;

internal static class Constants
{
public static string FunctionAppName { get; } = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") ?? "Unknown";

public static string ApplicationVersion { get; } = typeof(Startup).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
Expand Down
17 changes: 15 additions & 2 deletions KeyVault.Acmebot/Internal/GenericPayloadBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
using System;
using System.Collections.Generic;

using KeyVault.Acmebot.Options;

namespace KeyVault.Acmebot.Internal;

internal class GenericPayloadBuilder : IWebhookPayloadBuilder
{
public GenericPayloadBuilder(AcmebotOptions options)
{
_options = options;
}

private readonly AcmebotOptions _options;

public object BuildCompleted(string certificateName, DateTimeOffset? expirationDate, IEnumerable<string> dnsNames, string acmeEndpoint)
{
return new
{
certificateName,
expirationDate,
dnsNames,
acmeEndpoint
acmeEndpoint,
keyVaultName = new Uri(_options.VaultBaseUrl).Host,
functionAppName = Constants.FunctionAppName
};
}

Expand All @@ -21,7 +32,9 @@ public object BuildFailed(string functionName, string reason)
return new
{
functionName,
reason
reason,
keyVaultName = new Uri(_options.VaultBaseUrl).Host,
functionAppName = Constants.FunctionAppName
};
}
}
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void Configure(IFunctionsHostBuilder builder)

if (options.Webhook is null)
{
return new GenericPayloadBuilder();
return new GenericPayloadBuilder(options);
}

if (options.Webhook.Host.EndsWith("hooks.slack.com", StringComparison.OrdinalIgnoreCase))
Expand All @@ -102,7 +102,7 @@ public override void Configure(IFunctionsHostBuilder builder)
return new TeamsPayloadBuilder();
}

return new GenericPayloadBuilder();
return new GenericPayloadBuilder(options);
});

// Add DNS Providers
Expand Down

0 comments on commit 97f7a10

Please sign in to comment.