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

Allow to override nested array / maps properties #358

Open
sschuberth opened this issue Mar 3, 2023 · 10 comments
Open

Allow to override nested array / maps properties #358

sschuberth opened this issue Mar 3, 2023 · 10 comments

Comments

@sschuberth
Copy link
Contributor

          > I guess we could support `databases[1]__port = 9301` ?

I'd still be interested to override single properties within a list of a config read from a file via CLI options like that, without the need to declare "placeholder properties" that refer to environment variables. Is something like that supported by now?

Originally posted by @sschuberth in #144 (comment)

@sschuberth
Copy link
Contributor Author

sschuberth commented Mar 3, 2023

More specifically, it would be great if MapPropertySource and CommandLinePropertySource would support the "key" to contain an index like [1] to be able to override single values nested within an array list. (Even is that value was not present originally, so it's more "add" than "override"; in that aspect this issue is different from #144, where you can work with environment placeholders.)

@sschuberth
Copy link
Contributor Author

@sksamuel I'm willing to work on this, but I have no clue where to start. Is my approach outlined above even feasible to implement?

@sksamuel
Copy link
Owner

I think your approach for map property source and cli property source are perfectly reasonable.
We already do something some what similar in the aws preprocessor with [] used for json fields.

@stale
Copy link

stale bot commented Aug 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 12, 2023
@sschuberth
Copy link
Contributor Author

While I didn't have time to work on this yet, I believe it still makes sense as a feature to add.

@stale stale bot removed the wontfix This will not be worked on label Aug 17, 2023
@sschuberth
Copy link
Contributor Author

aws preprocessor with [] used for json fields.

Maybe by now https://github.com/eygraber/JsonPathKt could be leveraged...

@sksamuel
Copy link
Owner

Not sure we even need that. Just need to take [n] and apply that to the list ?

@sschuberth
Copy link
Contributor Author

Not sure we even need that. Just need to take [n] and apply that to the list ?

For lists you're probably right. But we basically have the same issue also for overriding values in a map. And there, in order to refer to the key's name in the map, maybe JsonPathKt would be helpful.

@sschuberth sschuberth changed the title Allow to override an array field / nested property Allow to override nested array / maps properties Sep 20, 2024
@rocketraman
Copy link
Contributor

For reference, Spring Boot does environment variable binding to object lists by the _n_ syntax. See https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables.

It'd probably be a good idea to implement the same in Hoplite for compatibility / consistency.

Also, from https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html:

Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. Other characters may be permitted by an implementation; applications shall tolerate the presence of such names.

So while characters like [ and ] are allowed, they would be unusual and may cause issues in some systems. Sticking with uppercase letters, digits, and _ (as Spring Boot does) would be best.

It seems like JsonPathKt would be overkill / too complicated syntax for this use case.

I'm not sure what you were thinking about for maps. I don't think Spring Boot supports that. That's not to say that Hoplite couldn't. Maybe the syntax for a map key could be double-underscore or something.

@sschuberth
Copy link
Contributor Author

I'm not sure what you were thinking about for maps.

I didn't have a concrete syntax in mind yet. I only know our requirement to be able to set Map<String, String> configuration items from the CLI 😄

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

No branches or pull requests

3 participants