Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Updated gubernator-cli with TLS support
Browse files Browse the repository at this point in the history
  • Loading branch information
thrawn01 committed Nov 10, 2020
1 parent eb5649e commit 4174455
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 500 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build image
FROM golang:1.15.1 as build
FROM golang:1.15.4 as build

WORKDIR /go/src

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ don't have either, the docker-compose method is the simplest way to try gubernat

##### Docker with existing etcd cluster
```bash
$ docker run -p 8081:81 -p 8080:80 -e GUBER_ETCD_ENDPOINTS=etcd1:2379,etcd2:2379 \
$ docker run -p 8081:81 -p 9080:80 -e GUBER_ETCD_ENDPOINTS=etcd1:2379,etcd2:2379 \
thrawn01/gubernator:latest

# Hit the API at localhost:8080 (GRPC is at 8081)
$ curl http://localhost:8080/v1/HealthCheck
# Hit the API at localhost:9080
$ curl http://localhost:9080/v1/HealthCheck
```

##### Docker compose
The docker compose file includes a local etcd server and 2 gubernator instances
The docker compose file uses member-list for peer discovery
```bash
# Download the docker-compose file
$ curl -O https://raw.githubusercontent.com/mailgun/gubernator/master/docker-compose.yaml
Expand All @@ -271,8 +271,8 @@ $ vi docker-compose.yaml
# Run the docker container
$ docker-compose up -d

# Hit the API at localhost:8080 (GRPC is at 8081)
$ curl http://localhost:8080/v1/HealthCheck
# Hit the API at localhost:9080 (GRPC is at 9081)
$ curl http://localhost:9080/v1/HealthCheck
```

##### Kubernetes
Expand Down
5 changes: 5 additions & 0 deletions cli-tls.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GUBER_DEBUG=true
GUBER_GRPC_ADDRESS=localhost:9081
GUBER_TLS_CA=certs/ca.pem
GUBER_TLS_KEY=certs/gubernator.key
GUBER_TLS_CERT=certs/gubernator.pem
33 changes: 28 additions & 5 deletions cmd/gubernator-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"math/rand"
"os"

"github.com/davecgh/go-spew/spew"
guber "github.com/mailgun/gubernator"
"github.com/mailgun/holster/v3/clock"
"github.com/mailgun/holster/v3/setter"
"github.com/mailgun/holster/v3/syncutil"
"github.com/sirupsen/logrus"
)

var log *logrus.Logger

func checkErr(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
log.Errorf(err.Error())
os.Exit(1)
}
}
Expand All @@ -40,12 +46,29 @@ func randInt(min, max int) int64 {
}

func main() {
if len(os.Args) < 2 {
fmt.Printf("Please provide an gubernator GRPC endpoint address\n")
os.Exit(1)
var configFile, GRPCAddress string
var err error

log = logrus.StandardLogger()
flags := flag.NewFlagSet("gubernator", flag.ContinueOnError)
flags.StringVar(&configFile, "config", "", "environment config file")
flags.StringVar(&GRPCAddress, "e", "", "the gubernator GRPC endpoint address")
checkErr(flags.Parse(os.Args[1:]))

conf, err := guber.SetupDaemonConfig(log, configFile)
checkErr(err)
setter.SetOverride(&conf.GRPCListenAddress, GRPCAddress)

if configFile == "" && GRPCAddress == "" && os.Getenv("GUBER_GRPC_ADDRESS") == "" {
checkErr(errors.New("please provide a GRPC endpoint via -e or from a config " +
"file via -config or set the env GUBER_GRPC_ADDRESS"))
}

client, err := guber.DialV1Server(os.Args[1], nil)
err = guber.SetupTLS(conf.TLS)
checkErr(err)

log.Infof("Connecting to '%s'...\n", conf.GRPCListenAddress)
client, err := guber.DialV1Server(conf.GRPCListenAddress, conf.ClientTLS())
checkErr(err)

// Generate a selection of rate limits with random limits
Expand Down
Loading

0 comments on commit 4174455

Please sign in to comment.