HTTP Server for Environment Variables
A web server that delivers environment variables as HTML, JSON, YAML, and shell-evaluable script, and discrete curl-able endpoints. It allows filtering of environment variables based on inclusion and exclusion patterns to control what is exposed.
With a docker image weighing in at less than 1mb, it is ideal to use as a queryable pod metadata sidecar in Kubernetes, or any situation in which you need to expose simple data without a lot of overhead.
All of the below use a docker container... when running locally just replace
docker run ... kilna/envhttpd
with envhttpd
and make sure the environment
variables are available (e.g. export foo=bar
).
Fire up a container...
$ docker run -e foo=bar -e yo=bro -p 8111:8111 -d kilna/envhttpd
Server is running at http://localhost:8111
Now point your browser at http://localhost:8111 and you should see something like this:
Everything after the image name kilna/envhttpd
is passed as arguments to the
envhttpd
binary (see Command-Line Help for more details).
$ docker run -e foo=bar -e yo=bro -p 8222:8222 -d kilna/envhttpd -p 8222 -i foo -x yo -H envhttpd.local
Server is running at http://envhttpd.local:8222
Get a specific environment variable's value as plain UTF-8 text:
$ curl localhost:8111/var/foo
bar
Get all included environment variables as a JSON dictionary:
$ curl localhost:8111/json
{"foo":"bar","yo":"bro"}
$ curl localhost:8111/json?pretty
{
"foo": "bar",
"yo": "bro"
}
Get all included environment variables as a YAML dictionary:
$ curl localhost:8111/yaml
---
foo: bar
yo: bro
Get all included environment variables as a shell-evaluable script:
$ curl localhost:8111/sh
foo="bar"
yo="bro"
$ curl localhost:8111/sh?export
export foo="bar"
export yo="bro"
See the kubernetes example for pod and
sidecar deployment under the kubernetes/
folder.
$ envhttpd -h
Usage: envhttpd [OPTIONS]
envhttpd is a lightweight HTTP server designed to expose env vars
in HTML, JSON, YAML, and evaluatable shell formats. It allows
filtering of environment variables based on inclusion and exclusion
patterns to control what is exposed.
Options:
-p PORT Specify the port number the server listens on.
Default is 8111.
-i PATTERN Include env vars matching the specified PATTERN.
Supports glob patterns (e.g., APPNAME_*).
Default behavior is to include all env vars except
PATH and HOME since they're largely not relevant outside
of a container.
-x PATTERN Exclude env vars matching the specified PATTERN.
Supports glob patterns (e.g., DEBUG*, TEMP).
-d Run the server as a daemon in the background.
(Does not make sense in a docker container)
-D Enable debug mode logging and text/plain responses.
-H HOSTNAME Specify the hostname of the server.
-h Display this help message and exit.
Endpoints:
/ Displays a web page listing all included env vars.
/json Gets env vars in JSON format.
/json?pretty Gets env vars in pretty-printed JSON format.
/yaml Gets env vars in YAML format.
/sh Gets env vars in shell evaluatable format.
/sh?export Gets env vars as shell with `export` prefix.
/var/VARNAME Gets the value of the specified env var.
envhttpd, Copyright © 2024 Kilna, Anthony https://github.com/kilna/envhttpd