Skip to content

Commit

Permalink
Support passing env variables instead of flags (#31)
Browse files Browse the repository at this point in the history
* Support passing env variables instead of flags

* Update readme to mention env vars
  • Loading branch information
dougwettlaufer authored Sep 2, 2021
1 parent 54e40ab commit 6fd3560
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,43 @@ or using Docker as
docker run -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 --contact-points <cluster node IPs or DNS names>
```

## 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 <your-secure-connect-bundle.zip>:/tmp/scb.zip -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 \
--bundle /tmp/scb.zip --username token --password <your-astra-token>
```

Environment Variables

```sh
docker run -v <your-secure-connect-bundle.zip>:/tmp/scb.zip -p 9042:9042 --rm datastax/cql-proxy:v0.0.1 \
-e BUNDLE=/tmp/scb.zip -e USERNAME=token -e PASSWORD=<your-astra-token>
```

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/
17 changes: 9 additions & 8 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 6fd3560

Please sign in to comment.