octokit/webhooks.net

[FEAT]: Allow to configure secret using IConfiguration instance

ganhammar opened this issue ยท 3 comments

Describe the need

Currently, it's only possible to configure GitHub webhooks secret by passing the string to ConfigureGitHubWebhooks (at least if you don't manually want to configure GitHubWebhooksOptions). I suggest adding a configuration extension method that accepts a Func<IConfiguration, string> to retrieve the secret from configuration sources, allowing for a more dynamic configuration.

new HostBuilder()
    .ConfigureServices(collection =>
    {
        collection.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>();
    })
    .ConfigureGitHubWebhooks((configuration) => configuration.GetValue<string>("GitHubWebhookSecret"))
    .ConfigureFunctionsWorkerDefaults()
    .Build()
    .Run();

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

๐Ÿ‘‹ Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! ๐Ÿš€

I think #550 might be a solution to what you're after? IOptionsMonitor seems to be the community approach over Func<IConfiguration, string>.

Hey @JamieMagee!

Thanks for the reply!

Switching to IOptionsMonitor was the correct choice, this is more of a question of configuring the options instance. If I want to configure it using a configuration source, which is preferable, since the value can then come from a secure place, like Azure KeyVault, AWS Systems Manager Parameter Store, or AWS Secrets Manager, I would have to look at the internals of this package and manually configure the GitHubWebhooksOptions, like so:

new HostBuilder()
    .ConfigureServices(collection =>
    {
        collection.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>();
        collection.AddOptions<GitHubWebhooksOptions>()
            .Configure<IConfiguration>((options, configuration) =>
            {
                options.Secret = configuration["GitHubWebhookSecret"];
            });
    })
    .ConfigureFunctionsWorkerDefaults()
    .Build()
    .Run();

Which is not ideal, since I would need to keep this updated as the package evolves. What I'm suggesting is not to move away from IOptionsMonitor but to make it possible to achieve the same result through the IConfiguration instance:

.ConfigureGitHubWebhooks((configuration) => configuration.GetValue<string>("GitHubWebhookSecret"))