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

Question: How to represent array properties in parameter store? #245

Closed
rmpestano opened this issue Feb 16, 2022 · 3 comments
Closed

Question: How to represent array properties in parameter store? #245

rmpestano opened this issue Feb 16, 2022 · 3 comments
Labels
component: parameter-store Parameter Store integration related issue type: bug Something isn't working

Comments

@rmpestano
Copy link

rmpestano commented Feb 16, 2022

Type: Bug

Component:
"Parameter Store"

Describe the bug
I need to represent list properties in parameter store, is it possible?

The main issue is that list indexes are represented by square brackets in Spring which are not supported as parameter names in ssm API, here's the pattern: a-zA-Z0-9_.-

Sample
Here's a sample spring config I want to represent on ssm:

config.users:
  - name: 'user1'
    password: 'pass1'
  - name: 'user2'
    password: 'pass2'

in parameter store I'd need the following parameters:

/config/app/config.users[0].name
/config/app/config.users[0].password
/config/app/config.users[1].name
/config/app/config.users[1].password

But I cannot create them because of the brackets.

Note that the env var representation would work as it uses _ for the array index.

@github-actions github-actions bot added type: bug Something isn't working status: waiting-for-triage Team has not yet looked into this issue labels Feb 16, 2022
@maciejwalkowiak maciejwalkowiak added component: parameter-store Parameter Store integration related issue and removed status: waiting-for-triage Team has not yet looked into this issue labels Feb 16, 2022
@rmpestano
Copy link
Author

Hi again,

We fixed this in our project by representing array indexes with _INDEX_. The example on the description of this issue would be represented as:

/config/app/config.users_0_.name
/config/app/config.users_0_.password
/config/app/config.users_1_.name
/config/app/config.users_1_.password

Not sure that would work as a general solution without breaking existing applications.

If someone else needs this now, in our project we've created a property source that just gets the parameters resolved by AwsParamStorePropertySource (they'll have the underscore array index notation) and transform them into the system properties array notation (with brackets):

public class ArraySupportParamStorePropertySource implements PropertySourceLocator {

    private final Map<String, Object> configProperties;

    public ArraySupportParamStorePropertySource(final AwsParamStorePropertySource awsParamStorePropertySource) {
        var parameterStoreParams = Arrays.stream(awsParamStorePropertySource.getPropertyNames()).toList();
        configProperties = parameterStoreParams.stream()
                .filter(param -> param.startsWith("my-config"))
                .map(param -> Map.entry(param.replaceAll("_(\\d)_", "[$1]"), awsParamStorePropertySource.getProperty(param)))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }

    @Override
    public PropertySource<?> locate(Environment environment) {
        return new MapPropertySource("my-config", configProperties);
    }
}

@maciejwalkowiak
Copy link
Contributor

Thanks @rmpestano! @MatejNedic is looking how to tackle this issue on the Spring Cloud AWS side. Perhaps we can come up together with a PR?

@rmpestano
Copy link
Author

Hey @maciejwalkowiak, I've just opened a draft PR (#248), maybe we can use it as a starting point.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: parameter-store Parameter Store integration related issue type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants