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

Parse Json param with fallback to default way of parsing i.e. string or stringList #181

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

Conversation

snigdhasjg
Copy link

@snigdhasjg snigdhasjg commented Aug 7, 2024

Description

Processes a collection of AWS Systems Manager (SSM) Parameters Store parameters, converting them into a dictionary of strings.

This method supports both JSON-formatted parameters as per JsonParameterProcessor. And plain string & StringList as per DefaultParameterProcessor.

The resulting dictionary keys are case-insensitive, as the other 2 implemenation.

Motivation and Context

We have multiple types of SSM gets loaded during application startup.
Mainly Json and Text based. Params are dynamic in nature, so no way to telling if its Json or Text.

We are using this code for more than a week now, so why not merge it in the lib itself.

Testing

  1. Tested in our net8.0 application already. It runs on official docker image mcr.microsoft.com/dotnet/aspnet:8.0-jammy
  2. Tested in net6.0 locally
  3. Couldn't test on other 2 version for netstandard2.0;netcoreapp3.1 as using ARM

Unit tests have been added, validated.

No impact on existing area as new implementation of the IParameterProcessor

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new tests passed
  • All existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license


namespace Amazon.Extensions.Configuration.SystemsManager
{
public class JsonOrDefaultParameterProcessor : DefaultParameterProcessor
Copy link
Member

Choose a reason for hiding this comment

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

We need docs here explaining what this processor does. I would suggest instead of using the term Default here I would use String. So it is obvious to users that this supports either Json or falls back to String if the parameter fails to parse as Json.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I was thinking that, but then I hold myself cause it's both String and StringList

If you think JsonOrStringParameterProcessor would be good enough I can change that.

Copy link
Author

Choose a reason for hiding this comment

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

Updated the name

Copy link
Member

Choose a reason for hiding this comment

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

It is a valid concern that it is also doing StringList but I feel like String is better then Default. If I read the name JsonOrDefault.. and ignore my knowledge of how things are implemented I would see a name that says Json or some unknown format.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah used JsonOrStringParameterProcessor

Copy link
Author

Choose a reason for hiding this comment

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

added docs in places where I felt, open for suggestion

{
foreach (var kv in JsonConfigurationParser.Parse(parameter.Value))
{
var key = !string.IsNullOrEmpty(keyPrefix) ? ConfigurationPath.Combine(keyPrefix, kv.Key) : kv.Key;
Copy link
Member

Choose a reason for hiding this comment

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

Can you refactor this inner loop logic that is a duplicate inner loop logic in JsonParameterProcessor into a common internal utility method.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I was thinking on the same line.

I have 3 static methods -
ParseJson can be used in both the new class and json processor.
Other 2 ParseString and ParseStringList can also be extracted out and reused.

Let me work on that

Copy link
Author

@snigdhasjg snigdhasjg Aug 7, 2024

Choose a reason for hiding this comment

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

Extracted all 3 methods,
refactored both JsonParameterProcessor and DefaultParameterProcessor

Please review

@snigdhasjg
Copy link
Author

Changes are done from my end. Once reviewed, I'll squash all commits.

Copy link
Contributor

@peterrsongg peterrsongg left a comment

Choose a reason for hiding this comment

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

Checked out the branch, ran the tests myself. Looks good

Passed!  - Failed:     0, Passed:    74, Skipped:     0, Total:    74, Duration: 92 ms - Amazon.Extensions.Configuration.SystemsManager.Tests.dll (netcoreapp3.1)
Test run for C:\Dev\Repos\aws-dotnet-extensions-configuration\test\Amazon.Extensions.Configuration.SystemsManager.Tests\bin\Debug\net6.0\Amazon.Extensions.Configuration.SystemsManager.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

@snigdhasjg
Copy link
Author

@normj @peterrsongg have't heard back. any update on this?

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.

3 participants