Duplicate SSM parameter with different Case cause the whole SSM parameter fail to load
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 5 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@malah-code I debated the same thing about
Optional
but if you look at the docs for theAddJson
method here it says theOptional
property means “Whether the file is optional.”. I’m interpreting that as it is optional the file exists not that it should ignore errors with the file. Which seems to prove true because when I make myappsettings.Development.json
file have unparseable JSON I get the errorFailed to load configuration file <file>
. So following that pattern I think it is safe for us to throw exceptions if the data coming back from SSM is invalid like duplicate keys.Just a proposed solution to provide Tolerant Implementation in case of duplicate parameters that may located in SSM with different CASE (like \Path1\Param1 and \path1\param1 , only first one will be taken). . this is like additional option for user to use instead of the DefaultParameterProcessor by using