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

Feature/58 aws options from appsettings #61

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

devklick
Copy link
Contributor

The changes in this PR are to address issues #58 and #57 - Adding support to take pieces of configuration from an appsettings file, rather than all configuration having to be specified in code.

Reading from config

Can be enabled by calling the SecretsManagerConfigurationProviderOptions.ReadFromConfigSection method and optionally specifying the name of the config section to be read from. See example app for usage.

Supported options

Several options can be specified in config - see the example config section in README for those that are supported.

Falling back on AWS config

The default AWS config section will be used as a fallback source for the AWS client region & credentials profile if this information is not specified in the custom config section. See README for more.

Mixing appsettings and hardcoded config

Options can be taken from a combination of appsettings & hardcoded, but some rules apply - see README for more.

Still to be done

  • Unit tests

Copy link
Owner

@Kralizek Kralizek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR. Added few comments, waiting for the unit tests.

Comment on lines +250 to +251
and both will be used. The same applies for the `ListSecretsFilters` collection. For all other properties, the code-based configuration
will take precedence.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really "code-based precedence will take precedence" or simply "last called wins"?

Comment on lines -200 to +270
If you would like to build this project locally, just execute the `build.cake` script.
If you would like to build this project locally, just exe7ute the `build.cake` script.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a typo

/// <summary>
/// Determines whether or not the options for the configuration provider should be read from configuration.
/// </summary>
public bool ReadFromConfig { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid shortenings.

Suggested change
public bool ReadFromConfig { get; set; }
public bool ReadFromConfiguration { get; set; }

/// <summary>
/// The name of the configuration section containing the options.
/// </summary>
public string ConfigSectionName { get; set; } = SecretsManagerConfigurationSection.DefaultConfigSectionName;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Suggested change
public string ConfigSectionName { get; set; } = SecretsManagerConfigurationSection.DefaultConfigSectionName;
public string ConfigurationSectionName { get; set; } = SecretsManagerConfigurationSection.DefaultConfigSectionName;

/// Enables the extension to read options from an IConfigurationSection.
/// </summary>
/// <param name="configSectionName">The name of the configuration section containing the options.</param>
public void ReadFromConfigSection(string configSectionName = SecretsManagerConfigurationSection.DefaultConfigSectionName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go for ReadFromConfiguration instead.

Suggested change
public void ReadFromConfigSection(string configSectionName = SecretsManagerConfigurationSection.DefaultConfigSectionName)
public void ReadFromConfiguration(string configSectionName = SecretsManagerConfigurationSection.DefaultConfigSectionName)

Another option could be UseConfiguration. What do you think?


public RegionEndpoint? Region { get; set; }

public IConfigurationProvider Build(IConfigurationBuilder builder)
{
var client = CreateClient();
var client = CreateClient();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space.

options.AcceptedSecretArns?.AddRange(smConfig.AcceptedSecretArns);

options.PollingInterval ??= smConfig?.PollingIntervalInSeconds != null
? TimeSpan.FromSeconds(smConfig.PollingIntervalInSeconds.Value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should support TimeSpan.Parse as well here.

Comment on lines +69 to +70
if (profile == null)
return FallbackCredentialsFactory.GetCredentials();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (profile == null)
return FallbackCredentialsFactory.GetCredentials();
if (profile == null)
{
return FallbackCredentialsFactory.GetCredentials();
}

Comment on lines +192 to +194
## Configuration via appsettings.json
Many options can be specified in a JSON file rather than hardcoded within the app. To do so,
the `ReadFromConfigSection` method should be called, like so:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather specify that many options can be specified using the Microsoft Configuration system without limiting to the JSON file. After all, the configuration values can be provided using other providers.

```csharp
builder.AddSecretsManager(configurator: options =>
{
options.ReadFromConfigSection();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align to new name.

@savornicesei
Copy link

Hi @Kralizek, @devklick
What needs to be done to get this PR merged?

Thank you.

/// The location of the file containing the credentials profiles.
/// </summary>
public string ProfilesLocation { get; set; }
}
Copy link

@savornicesei savornicesei Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking if it's better for the extension to handle everything or if it is worth taking a dependency on AWSSDK.Extensions.NETCore.Setup .

Unfortunately AWSOptions? options = settings.GetAWSOptions("AWS:SecretsManager"); from the mentioned AWS package does not initialize AWSCredentials for some reason.
To overcome this I added a new method to IConfiguration : GetAWSOptionsWithCredentials that also sets the options.Credentials.

Using AWSSDK.Extensions.NETCore.Setup will allow smooth integration with localstack through localstack-dotnet-client

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this library as supple and lean as possible.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense

@Kralizek
Copy link
Owner

Kralizek commented Nov 8, 2022

I'm considering closing this PR because I am doubtful about importing the whole authentication and request signing into this library. There are still good bits that should be taken like support for configuration file. I will open a new PR with that part and make sure that @devklick will get recognition for their work on this PR that was instrumental to understand the problem space and how to go forward.

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.

Take AWS options from appsettings Is it possible to provide AcceptedArns through config file?
4 participants