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

Allow user to set keyvault secret client option #577

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

zhiyuanliang-ms
Copy link
Contributor

@zhiyuanliang-ms zhiyuanliang-ms commented Jul 17, 2024

Why this PR?

#274

Visible change

New API
AzureAppConfigurationKeyVaultOptions.ConfigureClientOptions

usage:

IConfiguration config = new ConfigurationBuilder()
    .AddAzureAppConfiguration(options =>
    {
        options.ConfigureKeyVault(kv =>
        {
            kv.SetCredential(new DefaultAzureCredential());
            kv.ConfigureClientOptions(sco => sco.Retry.MaxAttempts = 3;
        });
    })
    .Build();

@zhiyuanliang-ms
Copy link
Contributor Author

zhiyuanliang-ms commented Jul 18, 2024

https://github.com/Azure/AppConfiguration-DotnetProvider/blob/main/src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationOptions.cs#L362

We have ConfigureClientOptions and other ConfigureXXX methods for AzureAppConfigurationOptions. However, this naming convention wasn't followed by AzureAppConfigurationKeyVaultOptions. We have SetXXX methods for AzureAppConfigurationKeyVaultOptions. I think SetClientOptions is more appropriate here. What do you think?

@jimmyca15 @amerjusupovic @avanigupta @zhenlan

@amerjusupovic
Copy link
Member

I think SetClientOptions is more appropriate here. What do you think?

I think part of the reason all the methods in AzureAppConfigurationKeyVaultOptions start with Set is that the methods aren't really configuring anything, it's just passing in a secret resolver, credential, or refresh interval. For example, AzureAppConfigurationRefreshOptions.SetRefreshInterval follows that pattern. However, I think the other Configure methods in the main AzureAppConfigurationOptions involve actually configuring an options class, which is what we're doing in the proposed SetClientOptions.

I think that means AzureAppConfigurationKeyVaultOptions.ConfigureClientOptions would make more sense to me. That's just how I see it right now though, any other thoughts?

@zhenlan
Copy link
Contributor

zhenlan commented Aug 9, 2024

It's not just the naming. The benefit of ConfigureClientOptions is that users can make necessary client option changes directly inline (#106). They don't have to create a new SecretClientOptions object in advance and replace the current one.

public AzureAppConfigurationOptions ConfigureClientOptions(Action<ConfigurationClientOptions> configure)

@jimmyca15
Copy link
Member

It's not just the naming. The benefit of ConfigureClientOptions is that users can make necessary client option changes directly inline (#106). They don't have to create a new SecretClientOptions object in advance and replace the current one.

public AzureAppConfigurationOptions ConfigureClientOptions(Action<ConfigurationClientOptions> configure)

I agree here, I prefer the case where the user gets passed a ClientOptions in the callback.

So in your example the usage becomes

IConfiguration config = new ConfigurationBuilder()
    .AddAzureAppConfiguration(options =>
    {
        options.ConfigureKeyVault(kv =>
        {
            kv.SetCredential(new DefaultAzureCredential());
            kv.ConfigureClientOptions(sco =>
            {
                        sco.Retry.MaxAttempts = 3;
            });
        });
    })
    .Build();

@zhiyuanliang-ms
Copy link
Contributor Author

@jimmyca15 @zhenlan I agree with the proposal. But my only concern is that user will not be able to set SecretClientOptions.Version through the callback pattern.

This is the implementation of SecretClientOptions.

public class SecretClientOptions : ClientOptions
{
    internal const ServiceVersion LatestVersion = ServiceVersion.V7_5;

    public ServiceVersion Version { get; }

    public bool DisableChallengeResourceVerification { get; set; }

    public SecretClientOptions(ServiceVersion version = ServiceVersion.V7_5)
    {
        Version = version;
        this.ConfigureLogging();
    }
}

If user want to configure the keyvault version, it can only be achieved through constructor because Version property doesn't have a public setter.

@jimmyca15
Copy link
Member

@zhiyuanliang-ms I think it's a good call out, but I still think it's the pattern we want.

@zhiyuanliang-ms zhiyuanliang-ms merged commit efb7742 into main Aug 13, 2024
3 checks passed
@zhiyuanliang-ms zhiyuanliang-ms deleted the zhiyuanliang/secret-client-option branch August 13, 2024 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants