Explain uses of these common env variables: HTTP_PROXY, HTTPS_PROXY, & NO_PROXY? - http-proxy

Can someone explain the purpose and effective usage of these three environment variables?
Is there a common convention when using them?
What happens if I set all of them at the same time? Is this application specific (I assume it is, but are there best practices?).
I see this as a pretty good "long form" answer. I don't know much about these variables or where to find more information about them and would love more information.

These environment variables are used by some tools like wget.
From the wget documentation of proxies
http_proxy
https_proxy
If set, the http_proxy and https_proxy variables should contain the URLs of the proxies for HTTP and HTTPS connections respectively.
no_proxy
This variable should contain a comma-separated list of domain extensions proxy should not be used for. For instance, if the value of no_proxy is ‘.mit.edu’, proxy will not be used to retrieve documents from MIT.
But others tools use different configuration of proxy settings, for instrance curl use -x, --proxy and --no-proxy arguments :
-x, --proxy <[protocol://][user:password#]proxyhost[:port]>
--noproxy <no-proxy-list>

Related

Is there a way to apply proxy configuration based on postman environment only?

In the case when you have to test a resource in different environments you may use postman environment variables to specify environment specific values. However, if only some of the environments use proxy you have to set it up Postman settings and enable/disable it manually every time you run the test against that environment. It is annoying and lacks automation. It gets even worse if different environments use different proxies.
In addition when you export environments and collections proxy configuration stays in Postman. It is not exported. Therefore you have to document it somewhere in order to avoid loosing the configuration, since there is no comments for an environment to document it there.
The question is: is there a way to apply proxy configuration based on environment? For example, specifying some Postman environment variables.
I tried to specify HTTP_PROXY, HTTPS_PROXY environment variables in Postman. Unfortunately, it did not work. Probably I was misled by using ambiguous "environment variable" term in "Respect HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables." setting. Obviously, Postman in fact respects system environment variables.
I was able to use Proxy Bypass to specify all hosts I do not want to apply proxy configuration to. However, the list is pretty big in my case, since proxy required only for one environment. In addition it does not resolve the issue if multiple proxies need to be used.

jvm.options IBM LIBERTY

I search a lot on the web, almost all links says define JVM custom variables in jvm.options also placed it on ${server.config.dir}/jvm.options.For example I added a variable called -DAPP_ENV=PROD. But this is getting as NULL after server startup.
Any idea?
It looks like you want to define an environment variable, so you have two options.
1. Use an Environment variable
In this case, you can define an environment variable (like $PATH) and load it in your app. Note this is not a JVM argument, and it will be set in the bin/server shell command used to start the server.
In the file:${server.config.dir}/server.env
Add the following line: APP_ENV=PROD
Access the value with:
System.getenv("APP_ENV"); -> PROD
2. Use a System property
This is what you are trying to do, so I am not sure why it doesn't work for you, but here's how:
In the file:${server.config.dir}/jvm.options
Add the following line: -DAPP_ENV=PROD
Access the value with:
System.getProperty("APP_ENV"); -> PROD
Note that in both cases these values are set at server start-up, and they are not changed dynamically (most Liberty configuration is dynamic). The JVM options and environment are sourced and set during the start script so a restart is required if you want to change either one.
My personal recommendation is go to the server.env route - its more generic and (to me) feels more appropriate since you are trying to influence the execution environment of the process, rather than defining behaviors or configuration of the JVM.

What exactly setenv.sh is used for in Tomcat?

I searched a lot but couldn't find any useful information about this:
What exactly setenv.sh is used for in Tomcat ?
Let's say we have a REST API (built with Java EE or Spring) which uses some parameters/variables like AWS Credentials, Database Credentials etc.
Does it make sense to parametrize the application with environment variables for these things I mentioned above and put their values to env vars on setenv.sh for each Tomcat instance in case we use more than one instance and with different parameters/variables ?
Or setenv.sh isn't for things like that ?
Thanks in advance
I've only ever seen it used for specifying CATALINA_OPTS, but I noticed that the RUNNING.txt file mentions using it to set JRE_HOME and JAVA_HOME.
RUNNING.txt also states under Advanced Configuration - Multiple Tomcat Instances:
In many circumstances, it is desirable to have a single copy of a
Tomcat binary distribution shared among multiple users on the same
server. To make this possible, you can set the CATALINA_BASE
environment variable to the directory that contains the files for your
'personal' Tomcat instance.
So I guess the answer is that a setenv file can be created for each app and can probably can be used to store credentials, but I don't think that it's commonly used for that purpose.
~/Programs/apache-tomcat-9.0.7/bin/setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -DENV_TARGET=prod -DMy_Env_Var1=Whatever -DMy_Env_Var2=CapitalOneIsTheBest"
So everything in between "" above in setenv.sh gets set as environmental variables for your applications in Tomcat. To retrieve/use those environmental variables, use this in your Java (Spring) applications:
Ex1) String myWhatever = java.lang.System.getProperties().getProperty("My_Env_Var1");
Ex2) String env= System.getProperties().getProperty("My_Env_Var2");
To change the environmental variable (for example when you are writing unit tests), do this:
System.setProperty("My_Env_Var1", "newEnv");

How to display IBM BPM snapshot environment variables using wsadmin?

I need to display all existing environment variables for snapshots installed on BPM. Is there a way I can do this using the wsadmin command ?
I don't think we have a wsadmin command to display all existing variables for a snapshot. If this is something that would be useful, I would suggest opening a Request for Enhancement(RFE) with BPM development for their consideration. Here is a link on how to do this:
https://developer.ibm.com/answers/questions/175980/how-do-i-submit-an-enhancement-request-or-rfe-for.html
Thanks!
I agree with Paula, there is no wsadmin cmd to display env variables.
However, you can check out:
BPMSetEnvironmentVariable:
https://www.ibm.com/support/knowledgecenter/SSFPJS_8.5.6/com.ibm.wbpm.ref.doc/topics/rref_bpmsetenvironmentvariable.html
And REST call to get env variable:
https://www.ibm.com/support/knowledgecenter/SSV2LR/com.ibm.wbpm.ref.doc/rest/bpmrest/rest_bpm_wle_v1_system_env_variable_get.htm
This can be achieved by the BPM REST Interface APIs.
Use this API to retrieve the list of process applications, in which you can find the ID of the snapshot you are interested in.
https://<bpm_host_or_ip>:9443/rest/bpm/wle/v1/processApps
Use this API to retrieve the envrionment variables and their default values.
https://<bpm_host_or_ip>:9443/rest/bpm/wle/v1/processAppSettings?snapshotId=2064.11a398d0-c6b8-41e4-b8eb-daaef864be14"
You can easily use jq in a Linux environment to parse out the information you are interested in.
Finally use this API to retrieve the current value of a given environment variable.
https://<bpm_host_or_ip>:9443/rest/bpm/wle/v1/system/env/variable?processAppAcronym=<APP_ACRONYM>&name=<ENV_VAR_NAME>

Config variables not visible as environment variables in Heroku app

I've set a few custom config variables. I can see them in my application's settings->config variables. I can also see the values with the heroku config command. But when I start my application the environment variables are not there. I use (System/getenv "MY_VARIABLE_NAME") in Clojure to fetch them.
Is it because I try to retrieve them at boot time? Are they only available later? Or is there some twitch which I can get rid of by doing some trick? I've used config variables in Heroku before and they've worked, I don't know what's the problem here...
I was trying to retrieve client ID and secret for oauth authentication with Google from a config variable with System/getenv. I use a library called Friend to do this. Problem is, the set up for oauth parameters in that library is done via macros. And macro expansion happens compile-time. Heroku config variables are not available as environment variables during compilation (for good reasons). They are, however available via filesystem which was my solution to the problem. So instead of:
(System/getenv "MY_APP_GOOGLE_CLIENT_ID")
I'm using this:
(slurp (str (System/getenv "ENV_DIR") "/" "MY_APP_GOOGLE_CLIENT_ID"))
And it works!

Resources