How to use environment variables in light-4j configuration files? - light-4j

In light-4j, is there a way to use environment variables in configuration files (like cors.yml, consul.yml, client.yml) similar to docker-compose files?

Yes. Take a look at this document
https://doc.networknt.com/concern/config/#environment-external-config-injection
You can use placeholders in the config files and use environment variables or values.yml to overwrite the variables in any config file.

Related

How to rename .env variables in package.json?

What I have
I have multiple projects using Percy for Cypress where I set the PERCY_TOKEN env variable inside the .env file. The token is different for each project. In the CI I set different env variables for each project, but locally I have to do it in the .env file. Because of this, I have to edit the .env file whenever I change between projects.
Goal
I would like to set them in the .env file this way:
PROJECT_A_PERCY_TOKEN=tokenhash1
PROJECT_B_PERCY_TOKEN=tokenhash2
So later I could rename these variables to PERCY_TOKEN, eliminating the need to constantly change the .env file.
What I tried
I'm trying to do this inside the package.json file's scripts property. Unfortunately echo $PROJECT_A_PERCY_TOKEN prints nothing. I know that I could create a shell/python/js script that parses the .env file, then passes the value back or calls npm run directly but I would like to do this without an external script.
Problem
It appears to me that I can't access the env variables inside package.json. Is there a way to rename the variable only using the npm script?
tl;dr
If the package you try to configure has the ability to do configuration via a JavaScript file, you can add the renaming at the beginning of it:
process.env.PERCY_TOKEN = process.env.CYPRESS_PERCY_SALESFORCE_TOKEN;
Explanation
While this isn't the solution I was looking for, it is a workaround for this specific use case. Percy supports JavaScript config files so I migrated my YAML config file, then I logged process.env and the .env file's variables were there, so I just need to copy the correct one. This might work for other packages that support JavaScript config files (or some alternative kind of hook/preloader where custom code can be placed), but if they don't, then the question is still unanswered.

How to use environment variables in prisma

From this document, Prisma cli try to download binaries from prisma s3. But as my corporate firewall rules this download was blocked, Following this document,I must change source binary file location by using PRISMA_ENGINES_MIRROR variable.
to utilize this variable,I must set environment variables. my build environment is like ElasticBeanstalk,after git push, build will start. from now on,I couldn't configure env variables in build environment. so that I consider to configure and write PRISMA_ENGINES_MIRROR variable to .env files and push them.
Is it possible? and how can I utilize these variable by .env ?
If someone has opinion,please let me know.
Thanks
You can configure environment variables in Elastic BeanStalk by going to
Configuration > Software Configuration > Environment Properties
You can add PRISMA_ENGINES_MIRROR in Environment Properties and it will be picked up by .env

Is there a way to set non-secret environment variables in Github Actions on the Settings page?

As far as I know, there are two ways to set environment variables in Github Actions:
Hardcoding them into YAML file
Adding them as repository secrets on the settings page
Repository secrets page
But what if I don't want them to be secret? On the picture above, SERVER_PREFIX and ANALYTICS_ENABLED shouldn't be secret. Is there a way to set up env variables on the settings page and make them visible? In Travis we had that option.
There isn't an option to add non-secret ENV variables on GitHub page at now.
You can create workflow-scope ENV variables in workflow step.
env:
SERVER_PREFIX: SOME_PREFIX
Then access by:
${{ env.SERVER_PREFIX }}
If you don't need to use them in the Action's YAML, just define your variables in a downloadable file and then use something like curl or wget to get them into your build environment.
For instance, I've done something similar for common CI files and now I've multiple projects running the same project building scripts, their local action is simply like: download an .sh file, run it.
If you need to set up variables in one of your build steps, to be used later by some other action, have a look at this (but I've never tried it myself).

Hasura endpoint as environment variable

I'm trying to check in my Hasura config.yaml file in a way that would be agnostic to my Hasura endpoint. The idea is that each developer will check out the project and work on a different Hasura instance, and then we would want to deploy and apply migrations separately to staging and production servers.
Is there, for instance, a way to make config.yaml get values from an .env file?
You can create a config.yaml.template file that contains the endpoints.
In this file you can define the endpoint like this:
endpoint: ${HASURA_ENDPOINT}
On startup of your hasura container you can generate a config.yaml file with envsubst:
envsubst '$HASURA_ENDPOINT' < /my_hasura_dir/config.yaml.template > /my_hasura_dir/config.yaml
You can use the —endpoint flag when executing commands. Similarly you can use flags for passing in admin secret and so on. Alternatively you can also use environment variables.
Read more here https://docs.hasura.io/1.0/graphql/manual/deployment/graphql-engine-flags/config-examples.html

Using environmental variable in rabbitmq.conf file

I am using RabbitMQ in windows environment. I am using RabbitMQ with ssl configuration.
My requirement is to use environment variable in the rabbitmq.conf file to read SSL certificates. I have used it as below,
{cacertfile, "${MY_HOME}/config/SSLCertificates/testca/cacert.pem"
The above usage of environmental variable doesnt work. Can any one of you please help me in correct usage of environmental variable.
Try adding your variables to file rabbitmq-env.bat from the docs that's the location in windows:
If rabbitmq-env.conf doesn't exist, it can be created manually in the location, specified by the RABBITMQ_CONF_ENV_FILE variable. On Windows systems, it is named rabbitmq-env.bat.
Also, you may need to use %% instead of ${} since you are in windows.
From the windows section
If you need to customise names, ports, locations, it is easiest to configure environment variables in the Windows dialogue: Start > Settings > Control Panel > System > Advanced > Environment Variables.
So after defining your environments, try this:
...
{cacertfile, "%YOURVAR%\path\to\cacert.pem"}
...
Windows: %APPDATA%\RabbitMQ

Resources