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
Some properties are hard to reference from environment #178
Comments
As mentioned on #164 - the PR on #177 should fix most of this. The syntax for adressing the tester using docker (more or less directly transferrable to kubernetes) would eg. be Now, with the guide you have outlined from (https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding-from-environment-variables):
-I would say we have what we need. Do you agree @petermicuch? |
Hi @jvitrifork. I had to test this now before giving you a statement. I took your changes, build image and provided these variables:
Issue is, that when you specify new key in the map, i.e. in my case Any idea how else I could get rid of the other two entries other then explicitly overwriting them? |
Well - thats more a question for what kind of defaults that are relevant. If zero defaults is generally preferrable, as it sounds like is your preference, I'll suggest to remove the current defaults in yaml file - @jamesagnew what's your take on that? I have little opinion on this. |
@jvitrifork the idea is mainly, that for small customizations, I do not need to touch |
I guess we cant do much about the spring boot behavior - and regarding underscores (see kubernetes/kubernetes#16863), that seems to have a reason on its own. |
@petermicuch Since we are now using named indicies, which makes it easier to reference, what more can be done for now? I agree that the application.yaml should provide as sane defaults as possible, |
@jvitrifork Unless there is a single default in application.yaml, there is no chance to override it with environment, if the same key is not used. To be honest, I would prefer to stay with arrays instead of named indices unless we solve default values dilemma. I was also not suggesting to use dash in environment name. I was suggesting to switch to dashes instead of underscores in application.yaml. Then it would be clear to omit any dashes in environment variable names as per spring boot documentation. But this seems to be not acceptable for you. So please rather keep the behavior as is without changes, since there is workaround (omit any underscore in environment variable names after usage of array index). |
@petermicuch feel free to make a PR that replaces and transform to your needs. Then we'll have a look |
It is difficult to easily reference some properties of starter hapi server after switch to spring boot and related switch from
hapi.properties
file toapplication.yaml
. Especially it is very difficult for arrays such ashapi.fhir.tester
.According to relaxed binding guide and binding from environment structure that the current
application.yaml
has, should actually work. However there is one case that is not described even in spring boot documentation and that is the case of arrays read from environment variables.In the documentation of spring boot, you can read: To convert a property name in the canonical-form to an environment variable name you can follow these rules:
[x]
with_x_
, wherex
is integer.By following above rules, let's convert this snippet from
application.yaml
:into environment variables:
However except of
HAPI_FHIR_TESTER_0_ID
andHAPI_FHIR_TESTER_0_NAME
nothing is correctly bound to respective variables. Experimenting with these bindings for a bit I found out that after removing underscores_
from env variable names after array index, it started to work fine.Working example:
Considering spring boot documentation recommendation and above undocumented behavior, I personally think that the best for hapi starter project would be to switch from underscore notation to either camel case or kebab case notation (i.e.
hapi.fhir.tester.serverAddress
orhapi.fhir.tester.server-address
). To preserve more or less same readability ofapplication.yaml
file, kebab case notation is probably more suitable although my personal preference is camel case in configuration as well as naming in the code itself. But no matter if camel case or kebab case is chosen, once you are following rules given in binding from environment guide all simply works without issues.@jvitrifork or @jamesagnew - could you please consider this to better support setting from environment, which is quite common and more flexible than
application.yaml
file loaded from configuration map. Thank you.The text was updated successfully, but these errors were encountered: