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

Environment Variable name look-up #1274

Closed
AkashWorkGit opened this issue Jun 13, 2022 · 6 comments
Closed

Environment Variable name look-up #1274

AkashWorkGit opened this issue Jun 13, 2022 · 6 comments

Comments

@AkashWorkGit
Copy link
Contributor

Issue:
If light-4j is configured to pull a variable value from the environment, and the variable does not have a legal env-var name (e.g.: the token is my.server.ip), then light-4j will be unable to get any value for that variable.

Proposed Feature/Update:
In cases where a value comes from the environment, we want light-4j to convert the variable name to a legal env-var name before trying to find the value (e.g.: look for the env-var named MY_SERVER_IP instead of my.server.ip).

So this new feature will remove any alpha-numeric values from the naming convention and replace the "." with an "_" and then converting it to uppercase.

This behaviour is similar to functionality found in frameworks such as Spring.

@stevehu
Copy link
Contributor

stevehu commented Jun 13, 2022

I totally agree with you and we are in the process to convert some variables. The first step is to convert some secrets and passwords. Let us know what else we need to convert.

Here is an example we are doing.

https://github.com/networknt/light-4j/blob/master/client/src/main/resources/config/client.yml#L27

@AkashWorkGit AkashWorkGit changed the title External variable naming convention Environment Variable name look-up Jun 15, 2022
@miklish
Copy link
Collaborator

miklish commented Jun 15, 2022

Hi @stevehu ,

Its good to see you start the process of updating the default variable names. :)

However -- just to make sure we're on the same page -- we are not proposing changing the default variable names in this issue (though we think that's a good idea). What we are proposing in this issue would actually allow light-4j to keep the existing variable names, but have light-4j dynamically change the names to a legal env-var format whenever it tries to find that value in the environment.

For example: This would allow light-4j to continue to use the variable name client.keyStore in the default config files... However, in the case that light-4j needs to get the value of client.keyStore from an environment variable, it would look for the value of CLIENT_KEYSTORE rather than client.keyStore. It would automatically do this name conversion (client.keyStore -> CLIENT_KEYSTORE) at runtime, and it would only do this name conversion when it attempts to get the value from the environment.

@miklish
Copy link
Collaborator

miklish commented Jun 15, 2022

E.g.: Something like this

... = System.getenv(toLegalEnvVarFormat(externalVarName));

@stevehu
Copy link
Contributor

stevehu commented Jun 15, 2022

@miklish I think that is a good idea. It allows us to have unified externalized config files without figuring out which fields would be possible to be overwritten by the env vars. I am wondering if you could submit a PR to get it implemented.

@AkashWorkGit
Copy link
Contributor Author

Hi Steve, Yes we are going to submit a PR for this to get implemented.

stevehu pushed a commit that referenced this issue Sep 13, 2022
#1357)

* Changes made to the code as per the requirements mentioned in Issue #1274 & Issue #1287

* Changes made to the code as per the requirements mentioned in Issue #1274 & Issue #1287

* Made a static object for Decryptor to be used in the class since while starting the service it was creating multiple instances of the decryptor.

Co-authored-by: Akash <[email protected]>
stevehu pushed a commit that referenced this issue Sep 13, 2022
#1357)

* Changes made to the code as per the requirements mentioned in Issue #1274 & Issue #1287

* Changes made to the code as per the requirements mentioned in Issue #1274 & Issue #1287

* Made a static object for Decryptor to be used in the class since while starting the service it was creating multiple instances of the decryptor.

Co-authored-by: Akash <[email protected]>
@stevehu
Copy link
Contributor

stevehu commented Dec 14, 2022

This issue has been completed on both 1.6.0 and 2.0.0 branches.

@stevehu stevehu closed this as completed Dec 14, 2022
younggwon1 pushed a commit to younggwon1/light-4j that referenced this issue Feb 10, 2024
… & networknt#1287 (networknt#1357)

* Changes made to the code as per the requirements mentioned in Issue networknt#1274 & Issue networknt#1287

* Changes made to the code as per the requirements mentioned in Issue networknt#1274 & Issue networknt#1287

* Made a static object for Decryptor to be used in the class since while starting the service it was creating multiple instances of the decryptor.

Co-authored-by: Akash <[email protected]>
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