aws-dotnet-extensions-configuration icon indicating copy to clipboard operation
aws-dotnet-extensions-configuration copied to clipboard

Duplicate SSM parameter with different Case cause the whole SSM parameter fail to load

Open malah-code opened this issue 1 year ago • 7 comments

Describe the bug

If we have duplicate SSM parameters with different case like below, the whole SSM parameters not added to the config at all.

  • /dotnet-aws-samples/systems-manager-sample/OracleConnectionString
  • /dotnet-aws-samples/systems-manager-sample/ORACLECONNECTIONSTRING
  • /dotnet-aws-samples/systems-manager-sample/oracleconnectionstring

note: this is applicable, because AWS SSM parameter names are case sensitive.

this is because of the code in DefaultParameterProcessor, that doesn't take into consideration is edge case.

Expected Behavior

Just ignore the duplicate SSM parameter and continue, or load the latest duplicate SSM parameters , or even throw error, that will be acceptable too (when configureSource.Optional = true).

Current Behavior

silently ignores ALL the SSM parameters and not add any of them to the config.

Reproduction Steps

to reproduce, setup the sample project, and add below parameters to the AWS SSM , and use configureSource.Optional = true

configurationBuilder.AddSystemsManager(configureSource =>
                        {
               configureSource.Path = "/your/path/here"; 
               configureSource.Optional = true;
})
  • /dotnet-aws-samples/systems-manager-sample/sampleone
  • /dotnet-aws-samples/systems-manager-sample/SAMPLEONE
  • /dotnet-aws-samples/systems-manager-sample/SampleOne

reload the project, you will not find any config value coming from AWS SSM at all.

Possible Solution

this pull request should have the fix #145 summary we just add 2 lines of code in DefaultParameterProcessor.cs file, to prevent duplicated keys and take first one only instead of throw error

                .GroupBy(parameter => parameter.Key, StringComparer.OrdinalIgnoreCase)
                .ToDictionary(group => group.Key, group => group.First().Value, StringComparer.OrdinalIgnoreCase);

So the final method will be like that

        public virtual IDictionary<string, string> ProcessParameters(IEnumerable<Parameter> parameters, string path)
        {
            return parameters
                .Where(parameter => IncludeParameter(parameter, path))
                .Select(parameter => new
                {
                    Key = GetKey(parameter, path),
                    Value = GetValue(parameter, path)
                })                
                .GroupBy(parameter => parameter.Key, StringComparer.OrdinalIgnoreCase)
                .ToDictionary(group => group.Key, group => group.First().Value, StringComparer.OrdinalIgnoreCase);
        }

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

"AWSSDK.AppConfigData" Version="3.7.0.23" "AWSSDK.Extensions.NETCore.Setup" Version="3.7.1" "AWSSDK.SimpleSystemsManagement" Version="3.7.12.9" "Microsoft.Extensions.Configuration" Version="2.0.*"

Targeted .NET Platform

net6.0

Operating System and version

AmazonLinux, and MacOs 13.3.1

malah-code avatar May 04 '23 04:05 malah-code