Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT]: Allow to configure secret using IConfiguration instance #567

Closed
1 task done
ganhammar opened this issue Sep 6, 2024 · 3 comments · Fixed by #568
Closed
1 task done

[FEAT]: Allow to configure secret using IConfiguration instance #567

ganhammar opened this issue Sep 6, 2024 · 3 comments · Fixed by #568
Labels
Type: Feature New feature or request

Comments

@ganhammar
Copy link
Contributor

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
@ganhammar ganhammar added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Sep 6, 2024
Copy link

github-actions bot commented Sep 6, 2024

👋 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! 🚀

@JamieMagee
Copy link
Contributor

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

@ganhammar
Copy link
Contributor Author

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"))

@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Sep 9, 2024
@JamieMagee JamieMagee removed the Status: Up for grabs Issues that are ready to be worked on by anyone label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants