From 6fd3560f4d44eda03b03e75c40b1038cbc229026 Mon Sep 17 00:00:00 2001 From: Doug Wettlaufer <45750136+dougwettlaufer@users.noreply.github.com> Date: Thu, 2 Sep 2021 12:39:50 -0500 Subject: [PATCH] Support passing env variables instead of flags (#31) * Support passing env variables instead of flags * Update readme to mention env vars --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ proxy.go | 17 +++++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 70ed385..0613529 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,43 @@ or using Docker as docker run -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 --contact-points ``` +## Configuration + +To pass configuration to the cql-proxy both command line flags and environment variables can be used. Below are examples of +the same command using both methods + +Flags + +```sh +docker run -v :/tmp/scb.zip -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 \ +--bundle /tmp/scb.zip --username token --password +``` + +Environment Variables + +```sh +docker run -v :/tmp/scb.zip -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 \ +-e BUNDLE=/tmp/scb.zip -e USERNAME=token -e PASSWORD= +``` + +To see what options are available the `-h` flag will display a help message listing all flags and their corresponding descriptions +and environment variables + +```sh +$ ./cql-proxy -h +Usage: cql-proxy + +Flags: + -h, --help Show context-sensitive help. + -b, --bundle=STRING Path to secure connect bundle ($BUNDLE) + -u, --username=STRING Username to use for authentication ($USERNAME) + -p, --password=STRING Password to use for authentication ($PASSWORD) + -c, --contact-points=CONTACT-POINTS,... + Contact points for cluster. Ignored if using the bundle path + option ($CONTACT_POINTS). + -a, --bind=STRING Address to use to bind serve ($BIND) + --debug Show debug logging ($DEBUG) + --profiling Enable profiling ($PROFILING) +``` + [astra]: https://astra.datastax.com/ diff --git a/proxy.go b/proxy.go index 1715498..5b6db69 100644 --- a/proxy.go +++ b/proxy.go @@ -20,22 +20,23 @@ import ( "net/http" _ "net/http/pprof" - "github.com/alecthomas/kong" "cql-proxy/astra" "cql-proxy/proxy" "cql-proxy/proxycore" + + "github.com/alecthomas/kong" "github.com/datastax/go-cassandra-native-protocol/primitive" "go.uber.org/zap" ) var cli struct { - Bundle string `help:"Path to secure connect bundle" short:"b"` - Username string `help:"Username to use for authentication" short:"u"` - Password string `help:"Password to use for authentication" short:"p"` - ContactPoints []string `help:"Contact points for cluster. Ignored if using the bundle path option." short:"c"` - Bind string `help:"Address to use to bind serve" short:"a"` - Debug bool `help:"Show debug logging"` - Profiling bool `help:"Enable profiling"` + Bundle string `help:"Path to secure connect bundle" short:"b" env:"BUNDLE"` + Username string `help:"Username to use for authentication" short:"u" env:"USERNAME"` + Password string `help:"Password to use for authentication" short:"p" env:"PASSWORD"` + ContactPoints []string `help:"Contact points for cluster. Ignored if using the bundle path option." short:"c" env:"CONTACT_POINTS"` + Bind string `help:"Address to use to bind serve" short:"a" env:"BIND"` + Debug bool `help:"Show debug logging" env:"DEBUG"` + Profiling bool `help:"Enable profiling" env:"PROFILING"` } func main() {