This commit is contained in:
Dimitri Herzog 2020-04-08 23:03:07 +02:00
parent 8367a043cf
commit 0766c6480a
29 changed files with 1774 additions and 700 deletions

View File

@ -23,18 +23,18 @@ jobs:
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0
- name: Run golangci-lint
run: make lint
- name: Build
run: make tools build
- name: Test
run: make test
run: make test
- name: Build
run: make build
- name: Run golangci-lint
run: make lint
- name: Docker images
run: make docker-build

View File

@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v1
- name: Build
run: make build
run: make tools build
- name: Test
run: make test

3
.gitignore vendored
View File

@ -1,6 +1,9 @@
.idea/
*.iml
bin/
docs/swagger.json
docs/swagger.yaml
docs/docs.go
config.yml
coverage.txt
todo.txt

View File

@ -22,6 +22,7 @@ RUN go mod download
ADD . .
ARG opts
RUN make tools
RUN env ${opts} make build
# final stage
@ -36,4 +37,6 @@ COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
HEALTHCHECK --interval=1m --timeout=3s CMD dig @127.0.0.1 -p 53 healthcheck.blocky +tcp || exit 1
WORKDIR /app
ENTRYPOINT ["/app/blocky","--config","/app/config.yml"]

View File

@ -1,4 +1,4 @@
.PHONY: all clean build test lint run buildMultiArchRelease docker-buildx-push help
.PHONY: all tools clean build test lint run buildMultiArchRelease docker-buildx-push help
.DEFAULT_GOAL := help
VERSION := $(shell git describe --always --tags)
@ -7,18 +7,23 @@ DOCKER_IMAGE_NAME="spx01/blocky"
BINARY_NAME=blocky
BIN_OUT_DIR=bin
tools: ## prepare build tools
mkdir -p ~/.docker && echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json
go get github.com/swaggo/swag/cmd/swag
all: test lint build ## Build binary (with tests)
clean: ## cleans output directory
$(shell rm -rf $(BIN_OUT_DIR)/*)
build: ## Build binary
go build -v -ldflags="-w -s -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}" -o $(BIN_OUT_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX)
$(shell go env GOPATH)/bin/swag init -g api/api.go
go build -v -ldflags="-w -s -X blocky/cmd.version=${VERSION} -X blocky/cmd.buildTime=${BUILD_TIME}" -o $(BIN_OUT_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX)
test: ## run tests
go test -v -coverprofile=coverage.txt -covermode=atomic -cover ./...
lint: ## run golangcli-lint checks
lint: build ## run golangcli-lint checks
$(shell go env GOPATH)/bin/golangci-lint run
run: build ## Build and run binary

24
api/api.go Normal file
View File

@ -0,0 +1,24 @@
// @title blocky API
// @description blocky API
// @contact.name blocky@github
// @contact.url https://github.com/0xERR0R/blocky
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /api/
package api
const (
BlockingStatusPath = "/api/blocking/status"
BlockingEnablePath = "/api/blocking/enable"
BlockingDisablePath = "/api/blocking/disable"
)
type BlockingStatus struct {
// True if blocking is enabled
Enabled bool `json:"enabled"`
// If blocking is temporary disabled: amount of seconds until blocking will be enabled
AutoEnableInSec uint `json:"autoEnableInSec"`
}

107
cmd/blocking.go Normal file
View File

@ -0,0 +1,107 @@
package cmd
import (
"blocky/api"
"encoding/json"
"fmt"
"net/http"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
//nolint:gochecknoinits
func init() {
rootCmd.AddCommand(blockingCmd)
blockingCmd.AddCommand(&cobra.Command{
Use: "enable",
Args: cobra.NoArgs,
Aliases: []string{"on"},
Short: "Enable blocking",
Run: enableBlocking,
})
disableCommand := &cobra.Command{
Use: "disable",
Aliases: []string{"off"},
Args: cobra.NoArgs,
Short: "Disable blocking for certain duration",
Run: disableBlocking,
}
disableCommand.Flags().DurationP("duration", "d", 0, "duration in min")
blockingCmd.AddCommand(disableCommand)
blockingCmd.AddCommand(&cobra.Command{
Use: "status",
Args: cobra.NoArgs,
Short: "Print the status of blocking resolver",
Run: statusBlocking,
})
}
//nolint:gochecknoglobals
var blockingCmd = &cobra.Command{
Use: "blocking",
Aliases: []string{"block"},
Short: "Control status of blocking resolver",
}
func enableBlocking(cmd *cobra.Command, args []string) {
resp, err := http.Get(apiURL(api.BlockingEnablePath))
if err != nil {
log.Fatal("can't execute", err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
log.Info("OK")
} else {
log.Fatal("NOK: ", resp.Status)
}
}
func disableBlocking(cmd *cobra.Command, args []string) {
duration, _ := cmd.Flags().GetDuration("duration")
resp, err := http.Get(fmt.Sprintf("%s?duration=%s", apiURL(api.BlockingDisablePath), duration))
if err != nil {
log.Fatal("can't execute", err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
log.Info("OK")
} else {
log.Fatal("NOK: ", resp.Status)
}
}
func statusBlocking(cmd *cobra.Command, args []string) {
resp, err := http.Get(apiURL(api.BlockingStatusPath))
if err != nil {
log.Fatal("can't execute", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatal("NOK: ", resp.Status)
}
var result api.BlockingStatus
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
log.Fatal("can't read response: ", err)
}
if result.Enabled {
log.Info("blocking enabled")
} else {
if result.AutoEnableInSec == 0 {
log.Info("blocking disabled")
} else {
log.Infof("blocking disabled for %d seconds", result.AutoEnableInSec)
}
}
}

42
cmd/blocking_test.go Normal file
View File

@ -0,0 +1,42 @@
package cmd
import (
"blocky/api"
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"testing"
)
func testHTTPAPIServer(fn func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
ts := httptest.NewServer(http.HandlerFunc(fn))
url, _ := url.Parse(ts.URL)
apiHost = url.Hostname()
port, _ := strconv.Atoi(url.Port())
apiPort = uint16(port)
return ts
}
func TestEnable(t *testing.T) {
ts := testHTTPAPIServer(func(w http.ResponseWriter, r *http.Request) {})
defer ts.Close()
enableBlocking(nil, []string{})
}
func TestDisable(t *testing.T) {
ts := testHTTPAPIServer(func(w http.ResponseWriter, r *http.Request) {})
defer ts.Close()
disableBlocking(blockingCmd, []string{})
}
func TestStatus(t *testing.T) {
ts := testHTTPAPIServer(func(w http.ResponseWriter, r *http.Request) {
response, _ := json.Marshal(api.BlockingStatus{Enabled: true})
_, _ = w.Write(response)
})
defer ts.Close()
statusBlocking(nil, []string{})
}

86
cmd/root.go Normal file
View File

@ -0,0 +1,86 @@
package cmd
import (
"blocky/config"
"fmt"
"os"
"github.com/spf13/cobra"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
log "github.com/sirupsen/logrus"
)
//nolint:gochecknoglobals
var (
version = "undefined"
buildTime = "undefined"
configPath string
cfg config.Config
apiHost string
apiPort uint16
)
//nolint:gochecknoglobals
var rootCmd = &cobra.Command{
Use: "blocky",
Short: "blocky is a DNS proxy ",
Long: `A fast and configurable DNS Proxy
and ad-blocker for local network.
Complete documentation is available at https://github.com/0xERR0R/blocky`,
Run: func(cmd *cobra.Command, args []string) {
serveCmd.Run(cmd, args)
},
}
func apiURL(path string) string {
return fmt.Sprintf("http://%s:%d%s", apiHost, apiPort, path)
}
//nolint:gochecknoinits
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config.yml", "path to config file")
rootCmd.PersistentFlags().StringVar(&apiHost, "apiHost", "localhost", "host of blocky (API)")
rootCmd.PersistentFlags().Uint16Var(&apiPort, "apiPort", 0, "port of blocky (API)")
}
func configureLog(cfg *config.Config) {
if level, err := log.ParseLevel(cfg.LogLevel); err != nil {
log.Fatalf("invalid log level %s %v", cfg.LogLevel, err)
} else {
log.SetLevel(level)
}
logFormatter := &prefixed.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
ForceFormatting: true,
ForceColors: true,
QuoteEmptyFields: true}
logFormatter.SetColorScheme(&prefixed.ColorScheme{
PrefixStyle: "blue+b",
TimestampStyle: "white+h",
})
log.SetFormatter(logFormatter)
}
func initConfig() {
cfg = config.NewConfig(configPath)
configureLog(&cfg)
if apiPort == 0 {
apiPort = cfg.HTTPPort
}
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

101
cmd/serve.go Normal file
View File

@ -0,0 +1,101 @@
package cmd
import (
"blocky/config"
"blocky/server"
"context"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
//nolint:gochecknoinits
func init() {
rootCmd.AddCommand(serveCmd)
}
//nolint:gochecknoglobals
var serveCmd = &cobra.Command{
Use: "serve",
Args: cobra.NoArgs,
Short: "start blocky DNS server (default command)",
Run: func(cmd *cobra.Command, args []string) {
printBanner()
configureHTTPClient(&cfg)
signals := make(chan os.Signal)
done := make(chan bool)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
server, err := server.NewServer(&cfg)
if err != nil {
log.Fatal("cant start server ", err)
}
server.Start()
go func() {
<-signals
log.Infof("Terminating...")
server.Stop()
done <- true
}()
<-done
},
}
func configureHTTPClient(cfg *config.Config) {
if cfg.BootstrapDNS != (config.Upstream{}) {
if cfg.BootstrapDNS.Net == "tcp" || cfg.BootstrapDNS.Net == "udp" {
dns := net.JoinHostPort(cfg.BootstrapDNS.Host, fmt.Sprint(cfg.BootstrapDNS.Port))
log.Debugf("using %s as bootstrap dns server", dns)
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(2000),
}
return d.DialContext(ctx, cfg.BootstrapDNS.Net, dns)
}}
http.DefaultTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
Resolver: r,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
}
} else {
log.Fatal("bootstrap dns net should be udp or tcs")
}
}
}
func printBanner() {
log.Info("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/")
log.Info("_/ _/")
log.Info("_/ _/")
log.Info("_/ _/ _/ _/ _/")
log.Info("_/ _/_/_/ _/ _/_/ _/_/_/ _/ _/ _/ _/ _/")
log.Info("_/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/")
log.Info("_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/")
log.Info("_/ _/_/_/ _/ _/_/ _/_/_/ _/ _/ _/_/_/ _/")
log.Info("_/ _/ _/")
log.Info("_/ _/_/ _/")
log.Info("_/ _/")
log.Info("_/ _/")
log.Infof("_/ Version: %-18s Build time: %-18s _/", version, buildTime)
log.Info("_/ _/")
log.Info("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/")
}

21
cmd/version.go Normal file
View File

@ -0,0 +1,21 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
//nolint:gochecknoinits
func init() {
rootCmd.AddCommand(&cobra.Command{
Use: "version",
Args: cobra.NoArgs,
Short: "Print the version number of blocky",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("blocky")
fmt.Printf("Version: %s\n", version)
fmt.Printf("Build time: %s\n", buildTime)
},
})
}

View File

@ -10,7 +10,7 @@
<p align="center">
<img height="200" src="blocky.svg">
<img height="200" src="https://github.com/0xERR0R/blocky/blob/master/docs/blocky.svg">
</p>
# Blocky
@ -130,7 +130,7 @@ queryLog:
# optional: DNS listener port, default 53 (UDP and TCP)
port: 53
# optional: HTTP listener port, default 0 = no http listener. If > 0, will be used for prometheus metrics, pprof, ...
# optional: HTTP listener port, default 0 = no http listener. If > 0, will be used for prometheus metrics, pprof, REST API, ...
httpPort: 4000
# optional: use this DNS server to resolve blacklist urls and upstream DNS servers (DOH). Useful if no DNS resolver is configured and blocky needs to resolve a host name. Format net:IP:port, net must be udp or tcp
bootstrapDns: tcp:1.1.1.1
@ -165,11 +165,23 @@ Download binary file for your architecture and run `./blocky --config config.yml
### Run with kubernetes (helm)
See [this repo](https://github.com/billimek/billimek-charts/tree/master/charts/blocky) or [the helm hub site](https://hub.helm.sh/charts/billimek/blocky) for details about running blocky via helm in kubernetes.
## CLI / REST API
If http listener is enabled, blocky provides REST API to control blocking status. Swagger documentation under `http://host:port/swagger`
To run CLI, please ensure, that blocky DNS server is running, than execute `blocky help` for help or
- `./blocky blocking enable` to enable blocking
- `./blocky blocking disable` to disable blocking
- `./blocky blocking disable --duration [duration]` to disable blocking for a certain amount of time (30s, 5m, 10m30s, ...)
- `./blocky blocking status` to print current status of blocking
To run this inside docker run `docker exec blocky ./blocky blocking status`
## Additional information
### Prometheus
Blocky can export metrics for prometheus. Example grafana dashboard definition [as JSON](blocky-grafana.json)
![grafana-dashboard](grafana-dashboard.png)
![grafana-dashboard](grafana-dashboard.png). Please install `grafana-piechart-panel` and set [disable-sanitize-html](https://grafana.com/docs/grafana/latest/installation/configuration/#disable-sanitize-html) in config or as env to use control buttons to enable/disable the blocking status.
Following metrics are being exported:

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 228 KiB

15
go.mod
View File

@ -3,8 +3,14 @@ module blocky
go 1.14
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/go-chi/chi v4.1.0+incompatible
github.com/go-chi/cors v1.0.1
github.com/go-openapi/spec v0.19.7 // indirect
github.com/go-openapi/strfmt v0.19.4 // indirect
github.com/go-openapi/swag v0.19.8 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-runewidth v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
@ -14,8 +20,13 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.4.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.7
github.com/stretchr/testify v1.4.0
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba
github.com/swaggo/swag v1.6.5
github.com/x-cray/logrus-prefixed-formatter v0.5.2
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82
gopkg.in/yaml.v2 v2.2.5
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b // indirect
gopkg.in/yaml.v2 v2.2.8
)

191
go.sum
View File

@ -1,38 +1,101 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/chi v4.1.0+incompatible h1:ETj3cggsVIY2Xao5ExCu6YhEh5MD6JTfcBzS37R260w=
github.com/go-chi/chi v4.1.0+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/cors v1.0.1 h1:56TT/uWGoLWZpnMI/AwAmCneikXr5eLsiIq27wrKecw=
github.com/go-chi/cors v1.0.1/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-openapi/errors v0.19.2 h1:a2kIyV3w+OS3S97zxUndRVD46+FhGOUBDFY7nmu4CsY=
github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94=
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o=
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.19.4 h1:ixzUSnHTd6hCemgtAJgluaTSGYpLNpJY4mA2DIkdOAo=
github.com/go-openapi/spec v0.19.4/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
github.com/go-openapi/spec v0.19.7 h1:0xWSeMd35y5avQAThZR2PkEuqSosoS5t6gDH4L8n11M=
github.com/go-openapi/spec v0.19.7/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
github.com/go-openapi/strfmt v0.19.4 h1:eRvaqAhpL0IL6Trh5fDsGnGhiXndzHFuA05w6sXH6/g=
github.com/go-openapi/strfmt v0.19.4/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk=
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.8 h1:vfK6jLhs7OI4tAXkvkooviaE1JEPcw3mutyegLHHjmk=
github.com/go-openapi/swag v0.19.8/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@ -41,23 +104,47 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
@ -68,6 +155,8 @@ github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1f
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -75,6 +164,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@ -82,11 +172,14 @@ github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8=
github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
@ -94,16 +187,40 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.7 h1:FfTH+vuMXOas8jmfb5/M7dzEYx7LpcLb7a0LPe34uOU=
github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -113,23 +230,66 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM=
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI=
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba h1:lUPlXKqgbqT2SVg2Y+eT9mu5wbqMnG+i/+Q9nK7C0Rs=
github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba/go.mod h1:O1lAbCgAAX/KZ80LM/OXwtWFI/5TvZlwxSg8Cq08PV0=
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
github.com/swaggo/swag v1.6.3/go.mod h1:wcc83tB4Mb2aNiL/HP4MFeQdpHUrca+Rp/DRNgWAUio=
github.com/swaggo/swag v1.6.5 h1:2C+t+xyK6p1sujqncYO/VnMvPZcBJjNdKKyxbOdAW8o=
github.com/swaggo/swag v1.6.5/go.mod h1:Y7ZLSS0d0DdxhWGVhQdu+Bu1QhaF5k0RD7FKdiAykeY=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0=
github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2tfCQDUqRd8fI=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.mongodb.org/mongo-driver v1.0.3 h1:GKoji1ld3tw2aC+GX1wbr/J2fX13yNacEYoJ8Nhr0yU=
go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -137,36 +297,64 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEha
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18 h1:xFbv3LvlvQAmbNJFCBKRv1Ccvnh9FVsW0FX2kTWWowE=
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b h1:AFZdJUT7jJYXQEC29hYH/WZkoV7+KhwxQGmdZ19yYoY=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
@ -174,3 +362,6 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -8,6 +8,7 @@ import (
"os"
"testing"
"github.com/go-chi/chi"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)
@ -81,7 +82,7 @@ func Test_Match_Download_No_Group(t *testing.T) {
}
func Test_Match_Download_WithMetrics(t *testing.T) {
metrics.Start(config.PrometheusConfig{Enable: true, Path: "/metrics"})
metrics.Start(chi.NewRouter(), config.PrometheusConfig{Enable: true, Path: "/metrics"})
server1 := helpertest.TestServer("blocked1.com\nblocked1a.com")
defer server1.Close()

122
main.go
View File

@ -1,127 +1,11 @@
package main
import (
"blocky/config"
"blocky/server"
"context"
"flag"
"fmt"
"net"
"net/http"
"blocky/cmd"
"os"
"os/signal"
"syscall"
"time"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
//nolint:gochecknoglobals
var version = "undefined"
//nolint:gochecknoglobals
var buildTime = "undefined"
func main() {
configPath := flag.String("config", "./config.yml", "Path to config file.")
flag.Parse()
cfg := config.NewConfig(*configPath)
configureLog(&cfg)
printBanner()
configureHTTPClient(&cfg)
signals := make(chan os.Signal)
done := make(chan bool)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
server, err := server.NewServer(&cfg)
if err != nil {
log.Fatal("cant start server ", err)
}
server.Start()
go func() {
<-signals
log.Infof("Terminating...")
server.Stop()
done <- true
}()
<-done
}
func configureHTTPClient(cfg *config.Config) {
if cfg.BootstrapDNS != (config.Upstream{}) {
if cfg.BootstrapDNS.Net == "tcp" || cfg.BootstrapDNS.Net == "udp" {
dns := net.JoinHostPort(cfg.BootstrapDNS.Host, fmt.Sprint(cfg.BootstrapDNS.Port))
log.Debugf("using %s as bootstrap dns server", dns)
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(2000),
}
return d.DialContext(ctx, cfg.BootstrapDNS.Net, dns)
}}
http.DefaultTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
Resolver: r,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
}
} else {
log.Fatal("bootstrap dns net should be udp or tcs")
}
}
}
func configureLog(cfg *config.Config) {
if level, err := log.ParseLevel(cfg.LogLevel); err != nil {
log.Fatalf("invalid log level %s %v", cfg.LogLevel, err)
} else {
log.SetLevel(level)
}
logFormatter := &prefixed.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
ForceFormatting: true,
ForceColors: true,
QuoteEmptyFields: true}
logFormatter.SetColorScheme(&prefixed.ColorScheme{
PrefixStyle: "blue+b",
TimestampStyle: "white+h",
})
logrus.SetFormatter(logFormatter)
}
func printBanner() {
log.Info("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/")
log.Info("_/ _/")
log.Info("_/ _/")
log.Info("_/ _/ _/ _/ _/")
log.Info("_/ _/_/_/ _/ _/_/ _/_/_/ _/ _/ _/ _/ _/")
log.Info("_/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/")
log.Info("_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/")
log.Info("_/ _/_/_/ _/ _/_/ _/_/_/ _/ _/ _/_/_/ _/")
log.Info("_/ _/ _/")
log.Info("_/ _/_/ _/")
log.Info("_/ _/")
log.Info("_/ _/")
log.Infof("_/ Version: %-18s Build time: %-18s _/", version, buildTime)
log.Info("_/ _/")
log.Info("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/")
cmd.Execute()
os.Exit(0)
}

View File

@ -2,8 +2,8 @@ package metrics
import (
"blocky/config"
"net/http"
"github.com/go-chi/chi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@ -18,13 +18,13 @@ func RegisterMetric(c prometheus.Collector) {
_ = reg.Register(c)
}
func Start(cfg config.PrometheusConfig) {
func Start(router *chi.Mux, cfg config.PrometheusConfig) {
enabled = cfg.Enable
if cfg.Enable {
reg.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
reg.MustRegister(prometheus.NewGoCollector())
http.Handle(cfg.Path, promhttp.InstrumentMetricHandler(reg,
router.Handle(cfg.Path, promhttp.InstrumentMetricHandler(reg,
promhttp.HandlerFor(reg, promhttp.HandlerOpts{})))
}
}

View File

@ -1,17 +1,24 @@
package resolver
import (
"blocky/api"
"blocky/config"
"blocky/lists"
"blocky/metrics"
"blocky/util"
"encoding/json"
"fmt"
"net"
"net/http"
"reflect"
"sort"
"strings"
"time"
"github.com/go-chi/chi"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
const (
@ -45,11 +52,48 @@ func resolveBlockType(cfg config.BlockingConfig) BlockType {
return NxDomain
}
logrus.Fatalf("unknown blockType, please use one of: ZeroIP, NxDomain")
log.Fatalf("unknown blockType, please use one of: ZeroIP, NxDomain")
return ZeroIP
}
type status struct {
enabled bool
enabledGauge prometheus.Gauge
enableTimer *time.Timer
disableEnd time.Time
}
func (s *status) enableBlocking() {
s.enableTimer.Stop()
s.enabled = true
if metrics.IsEnabled() {
s.enabledGauge.Set(1)
}
}
func (s *status) disableBlocking(duration time.Duration) {
s.enableTimer.Stop()
s.enabled = false
if metrics.IsEnabled() {
s.enabledGauge.Set(0)
}
s.disableEnd = time.Now().Add(duration)
if duration == 0 {
log.Info("disable blocking")
} else {
log.Infof("disable blocking for %s", duration)
s.enableTimer = time.AfterFunc(duration, func() {
s.enableBlocking()
log.Info("blocking enabled again")
})
}
}
// checks request's question (domain name) against black and white lists
type BlockingResolver struct {
NextResolver
@ -58,21 +102,110 @@ type BlockingResolver struct {
clientGroupsBlock map[string][]string
blockType BlockType
whitelistOnlyGroups []string
status status
}
func NewBlockingResolver(cfg config.BlockingConfig) ChainedResolver {
func NewBlockingResolver(router *chi.Mux, cfg config.BlockingConfig) ChainedResolver {
bt := resolveBlockType(cfg)
blacklistMatcher := lists.NewListCache(lists.BLACKLIST, cfg.BlackLists, cfg.RefreshPeriod)
whitelistMatcher := lists.NewListCache(lists.WHITELIST, cfg.WhiteLists, cfg.RefreshPeriod)
whitelistOnlyGroups := determineWhitelistOnlyGroups(&cfg)
return &BlockingResolver{
var enabledGauge prometheus.Gauge
if metrics.IsEnabled() {
enabledGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "blocky_blocking_enabled",
Help: "Blockings status",
})
enabledGauge.Set(1)
metrics.RegisterMetric(enabledGauge)
}
res := &BlockingResolver{
blockType: bt,
clientGroupsBlock: cfg.ClientGroupsBlock,
blacklistMatcher: blacklistMatcher,
whitelistMatcher: whitelistMatcher,
whitelistOnlyGroups: whitelistOnlyGroups,
status: status{
enabledGauge: enabledGauge,
enabled: true,
enableTimer: time.NewTimer(0),
},
}
// register API endpoints
router.Get(api.BlockingEnablePath, res.apiBlockingEnable)
router.Get(api.BlockingDisablePath, res.apiBlockingDisable)
router.Get(api.BlockingStatusPath, res.apiBlockingStatus)
return res
}
// apiBlockingEnable is the http endpoint to enable the blocking status
// @Summary Enable blocking
// @Description enable the blocking status
// @Tags blocking
// @Success 200 "Blocking is enabled"
// @Router /blocking/enable [get]
func (r *BlockingResolver) apiBlockingEnable(_ http.ResponseWriter, _ *http.Request) {
log.Info("enabling blocking...")
r.status.enableBlocking()
}
// apiBlockingStatus is the http endpoint to get current blocking status
// @Summary Blocking status
// @Description get current blocking status
// @Tags blocking
// @Produce json
// @Success 200 {object} api.BlockingStatus "Returns current blocking status"
// @Router /blocking/status [get]
func (r *BlockingResolver) apiBlockingStatus(rw http.ResponseWriter, _ *http.Request) {
var autoEnableDuration time.Duration
if !r.status.enabled && r.status.disableEnd.After(time.Now()) {
autoEnableDuration = time.Until(r.status.disableEnd)
}
response, _ := json.Marshal(api.BlockingStatus{
Enabled: r.status.enabled,
AutoEnableInSec: uint(autoEnableDuration.Seconds()),
})
_, err := rw.Write(response)
if err != nil {
log.Fatal("unable to write response ", err)
}
}
// apiBlockingDisable is the http endpoint to disable the blocking status
// @Summary Disable blocking
// @Description disable the blocking status
// @Tags blocking
// @Param duration query string false "duration of blocking (Example: 300s, 5m, 1h, 5m30s)" Format(duration)
// @Success 200 "Blocking is disabled"
// @Failure 400 "Wrong duration format"
// @Router /blocking/disable [get]
func (r *BlockingResolver) apiBlockingDisable(rw http.ResponseWriter, req *http.Request) {
var (
duration time.Duration
err error
)
// parse duration from query parameter
durationParam := req.URL.Query().Get("duration")
if len(durationParam) > 0 {
duration, err = time.ParseDuration(durationParam)
if err != nil {
log.Errorf("wrong duration format '%s'", durationParam)
rw.WriteHeader(http.StatusBadRequest)
return
}
}
r.status.disableBlocking(duration)
}
// returns groups, which have only whitelist entries
@ -91,7 +224,7 @@ func determineWhitelistOnlyGroups(cfg *config.BlockingConfig) (result []string)
}
// sets answer and/or return code for DNS response, if request should be blocked
func (r *BlockingResolver) handleBlocked(logger *logrus.Entry,
func (r *BlockingResolver) handleBlocked(logger *log.Entry,
request *Request, question dns.Question, reason string) (*Response, error) {
response := new(dns.Msg)
response.SetReply(request.Req)
@ -142,9 +275,9 @@ func (r *BlockingResolver) Configuration() (result []string) {
func (r *BlockingResolver) Resolve(request *Request) (*Response, error) {
logger := withPrefix(request.Log, "blacklist_resolver")
groupsToCheck := r.groupsToCheckForClient(request)
whitelistOnlyAlowed := reflect.DeepEqual(groupsToCheck, r.whitelistOnlyGroups)
whitelistOnlyAllowed := reflect.DeepEqual(groupsToCheck, r.whitelistOnlyGroups)
if len(groupsToCheck) > 0 {
if r.status.enabled && len(groupsToCheck) > 0 {
logger.WithField("groupsToCheck", strings.Join(groupsToCheck, "; ")).Debug("checking groups for request")
for _, question := range request.Req.Question {
@ -156,7 +289,7 @@ func (r *BlockingResolver) Resolve(request *Request) (*Response, error) {
return r.next.Resolve(request)
}
if whitelistOnlyAlowed {
if whitelistOnlyAllowed {
return r.handleBlocked(logger, request, question, "BLOCKED (WHITELIST ONLY85.100.115.92)")
}
@ -168,7 +301,7 @@ func (r *BlockingResolver) Resolve(request *Request) (*Response, error) {
respFromNext, err := r.next.Resolve(request)
if err == nil && len(groupsToCheck) > 0 && respFromNext.Res != nil {
if err == nil && r.status.enabled && len(groupsToCheck) > 0 && respFromNext.Res != nil {
for _, rr := range respFromNext.Res.Answer {
entryToCheck, tName := extractEntryToCheckFromResponse(rr)
if len(entryToCheck) > 0 {

View File

@ -1,12 +1,18 @@
package resolver
import (
"blocky/api"
"blocky/config"
"blocky/helpertest"
"blocky/util"
"encoding/json"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/go-chi/chi"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
@ -17,7 +23,7 @@ func Test_Resolve_ClientName_IpZero(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"client1": {"gr1"},
@ -54,7 +60,7 @@ func Test_Resolve_ClientIp_A_IpZero(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"192.168.178.55": {"gr1"},
@ -81,7 +87,7 @@ func Test_Resolve_ClientWith2Names_A_IpZero(t *testing.T) {
file2 := helpertest.TempFile("blocked2.com")
defer file2.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{
"gr1": {file1.Name()},
"gr2": {file2.Name()},
@ -121,7 +127,7 @@ func Test_Resolve_Default_A_IpZero(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -140,11 +146,191 @@ func Test_Resolve_Default_A_IpZero(t *testing.T) {
assert.Equal(t, "blocked1.com. 21600 IN A 0.0.0.0", resp.Res.Answer[0].String())
}
func Test_Disable_Blocking(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
},
}).(*BlockingResolver)
m := &resolverMock{}
m.On("Resolve", mock.Anything).Return(new(Response), nil)
sut.Next(m)
req := util.NewMsgWithQuestion("blocked1.com.", dns.TypeA)
resp, err := sut.Resolve(&Request{
Req: req,
ClientNames: []string{"unknown"},
ClientIP: net.ParseIP("192.168.178.1"),
Log: logrus.NewEntry(logrus.New()),
})
assert.NoError(t, err)
assert.Equal(t, dns.RcodeSuccess, resp.Res.Rcode)
assert.Equal(t, "blocked1.com. 21600 IN A 0.0.0.0", resp.Res.Answer[0].String())
m.AssertNumberOfCalls(t, "Resolve", 0)
r, _ := http.NewRequest("GET", "/api/blocking/disable", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(sut.apiBlockingDisable)
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
// now is blocking disabled, query the url again
req = util.NewMsgWithQuestion("blocked1.com.", dns.TypeA)
_, err = sut.Resolve(&Request{
Req: req,
ClientNames: []string{"unknown"},
ClientIP: net.ParseIP("192.168.178.1"),
Log: logrus.NewEntry(logrus.New()),
})
assert.NoError(t, err)
m.AssertExpectations(t)
m.AssertNumberOfCalls(t, "Resolve", 1)
}
func Test_Disable_BlockingWithWrongParam(t *testing.T) {
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{}).(*BlockingResolver)
r, _ := http.NewRequest("GET", "/api/blocking/disable?duration=xyz", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(sut.apiBlockingDisable)
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusBadRequest, rr.Code)
}
func Test_Status_Blocking(t *testing.T) {
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{}).(*BlockingResolver)
// enable blocking
r, _ := http.NewRequest("GET", "/api/blocking/enable", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(sut.apiBlockingEnable)
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
// query status
r, _ = http.NewRequest("GET", "/api/blocking/status", nil)
rr = httptest.NewRecorder()
handler = sut.apiBlockingStatus
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
var result api.BlockingStatus
err := json.NewDecoder(rr.Body).Decode(&result)
assert.NoError(t, err)
assert.True(t, result.Enabled)
// now disable blocking
r, _ = http.NewRequest("GET", "/api/blocking/disable", nil)
rr = httptest.NewRecorder()
handler = sut.apiBlockingDisable
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
// now query status again
r, _ = http.NewRequest("GET", "/api/blocking/status", nil)
rr = httptest.NewRecorder()
handler = sut.apiBlockingStatus
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
err = json.NewDecoder(rr.Body).Decode(&result)
assert.NoError(t, err)
assert.False(t, result.Enabled)
}
//nolint:funlen
func Test_Disable_BlockingWithDuration(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
},
}).(*BlockingResolver)
m := &resolverMock{}
m.On("Resolve", mock.Anything).Return(new(Response), nil)
sut.Next(m)
req := util.NewMsgWithQuestion("blocked1.com.", dns.TypeA)
resp, err := sut.Resolve(&Request{
Req: req,
ClientNames: []string{"unknown"},
ClientIP: net.ParseIP("192.168.178.1"),
Log: logrus.NewEntry(logrus.New()),
})
assert.NoError(t, err)
assert.Equal(t, dns.RcodeSuccess, resp.Res.Rcode)
assert.Equal(t, "blocked1.com. 21600 IN A 0.0.0.0", resp.Res.Answer[0].String())
m.AssertNumberOfCalls(t, "Resolve", 0)
// disable for 0.5 sec
r, _ := http.NewRequest("GET", "/api/blocking/disable?duration=500ms", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(sut.apiBlockingDisable)
handler.ServeHTTP(rr, r)
assert.Equal(t, http.StatusOK, rr.Code)
// now is blocking disabled, query the url again
req = util.NewMsgWithQuestion("blocked1.com.", dns.TypeA)
_, err = sut.Resolve(&Request{
Req: req,
ClientNames: []string{"unknown"},
ClientIP: net.ParseIP("192.168.178.1"),
Log: logrus.NewEntry(logrus.New()),
})
assert.NoError(t, err)
m.AssertExpectations(t)
m.AssertNumberOfCalls(t, "Resolve", 1)
// wait 1 sec
time.Sleep(time.Second)
req = util.NewMsgWithQuestion("blocked1.com.", dns.TypeA)
resp, err = sut.Resolve(&Request{
Req: req,
ClientNames: []string{"unknown"},
ClientIP: net.ParseIP("192.168.178.1"),
Log: logrus.NewEntry(logrus.New()),
})
assert.NoError(t, err)
assert.Equal(t, dns.RcodeSuccess, resp.Res.Rcode)
assert.Equal(t, "blocked1.com. 21600 IN A 0.0.0.0", resp.Res.Answer[0].String())
}
func Test_Resolve_Default_Block_With_Whitelist(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
WhiteLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
@ -171,7 +357,7 @@ func Test_Resolve_Whitelist_Only(t *testing.T) {
file := helpertest.TempFile("whitelisted.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
WhiteLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -229,7 +415,7 @@ func Test_Resolve_Default_A_NxRecord(t *testing.T) {
file := helpertest.TempFile("BLOCKED1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -252,7 +438,7 @@ func Test_Resolve_Default_BlockIP_A(t *testing.T) {
file := helpertest.TempFile("123.145.123.145")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -281,7 +467,7 @@ func Test_Resolve_Default_BlockIP_AAAA(t *testing.T) {
file := helpertest.TempFile("2001:db8:85a3:08d3::370:7344")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -311,7 +497,7 @@ func Test_Resolve_Default_BlockIP_A_With_Whitelist(t *testing.T) {
file := helpertest.TempFile("123.145.123.145")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
WhiteLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
@ -340,7 +526,7 @@ func Test_Resolve_Default_Block_CNAME(t *testing.T) {
file := helpertest.TempFile("baddomain.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"default": {"gr1"},
@ -379,7 +565,7 @@ func Test_Resolve_NoBlock(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
"client1": {"gr1"},
@ -405,7 +591,7 @@ func Test_Configuration_BlockingResolver(t *testing.T) {
file := helpertest.TempFile("blocked1.com")
defer file.Close()
sut := NewBlockingResolver(config.BlockingConfig{
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlackLists: map[string][]string{"gr1": {file.Name()}},
WhiteLists: map[string][]string{"gr1": {file.Name()}},
ClientGroupsBlock: map[string][]string{
@ -424,7 +610,7 @@ func Test_Resolve_WrongBlockType(t *testing.T) {
logrus.StandardLogger().ExitFunc = func(int) { fatal = true }
_ = NewBlockingResolver(config.BlockingConfig{
_ = NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{
BlockType: "wrong",
})
@ -432,7 +618,7 @@ func Test_Resolve_WrongBlockType(t *testing.T) {
}
func Test_Resolve_NoLists(t *testing.T) {
sut := NewBlockingResolver(config.BlockingConfig{})
sut := NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{})
m := &resolverMock{}
m.On("Resolve", mock.Anything).Return(new(Response), nil)
sut.Next(m)

View File

@ -38,7 +38,7 @@ func (m *MetricsResolver) Resolve(request *Request) (*Response, error) {
"reason": response.Reason,
"response_code": dns.RcodeToString[response.Res.Rcode],
"response_type": response.rType.String()}).Inc()
reqDurationMs := float64(time.Since(request.RequestTs).Milliseconds())
reqDurationMs := float64(time.Since(request.RequestTS).Milliseconds())
m.durationHistogram.WithLabelValues(response.rType.String()).Observe(reqDurationMs)
}
}

View File

@ -2,7 +2,6 @@ package resolver
import (
"blocky/config"
"fmt"
"io/ioutil"
"net"
"net/http"
@ -38,8 +37,6 @@ func (r *resolverMock) Resolve(req *Request) (*Response, error) {
func TestDOHUpstream(fn func(request *dns.Msg) (response *dns.Msg),
reqFn ...func(w http.ResponseWriter)) config.Upstream {
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("here")
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal("can't read request: ", err)

View File

@ -15,7 +15,7 @@ type Request struct {
ClientNames []string
Req *dns.Msg
Log *logrus.Entry
RequestTs time.Time
RequestTS time.Time
}
type ResponseType int

View File

@ -4,11 +4,13 @@ import (
"blocky/config"
"testing"
"github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
)
func Test_Chain(t *testing.T) {
ch := Chain(NewBlockingResolver(config.BlockingConfig{}), NewClientNamesResolver(config.ClientLookupConfig{}))
ch := Chain(NewBlockingResolver(chi.NewRouter(),
config.BlockingConfig{}), NewClientNamesResolver(config.ClientLookupConfig{}))
c, ok := ch.(ChainedResolver)
assert.True(t, ok)
@ -16,6 +18,6 @@ func Test_Chain(t *testing.T) {
assert.NotNil(t, next)
}
func Test_Name(t *testing.T) {
name := Name(NewBlockingResolver(config.BlockingConfig{}))
name := Name(NewBlockingResolver(chi.NewRouter(), config.BlockingConfig{}))
assert.Equal(t, "BlockingResolver", name)
}

View File

@ -4,7 +4,6 @@ import (
"blocky/config"
"blocky/util"
"crypto/tls"
"fmt"
"net/http"
"strings"
"testing"
@ -186,7 +185,6 @@ func Test_Resolve_UpstreamTimeout(t *testing.T) {
counter++
// timeout on first x attempts
if counter <= attemptsWithTimeout {
fmt.Print("timeout")
time.Sleep(110 * time.Millisecond)
}
response, err := util.NewMsgWithAnswer("example.com 123 IN A 123.124.122.122")

View File

@ -2,25 +2,30 @@ package server
import (
"blocky/config"
"blocky/docs"
"blocky/metrics"
"blocky/resolver"
"blocky/web"
"html/template"
"net/http"
"syscall"
// nolint
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"runtime/debug"
"syscall"
"time"
"blocky/util"
"fmt"
"net"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/cors"
"github.com/miekg/dns"
"github.com/sirupsen/logrus"
httpSwagger "github.com/swaggo/http-swagger"
)
type Server struct {
@ -29,6 +34,7 @@ type Server struct {
httpListener net.Listener
queryResolver resolver.Resolver
cfg *config.Config
httpMux *chi.Mux
}
func logger() *logrus.Entry {
@ -57,15 +63,15 @@ func NewServer(cfg *config.Config) (*Server, error) {
var httpListener net.Listener
router := createRouter(cfg)
if cfg.HTTPPort > 0 {
var err error
httpListener, err = net.Listen("tcp", fmt.Sprintf(":%d", cfg.HTTPPort))
if err != nil {
if httpListener, err = net.Listen("tcp", fmt.Sprintf(":%d", cfg.HTTPPort)); err != nil {
logger().Fatalf("start http listener on port %d failed: %v", cfg.HTTPPort, err)
}
metrics.Start(cfg.Prometheus)
metrics.Start(router, cfg.Prometheus)
}
queryResolver := resolver.Chain(
@ -75,7 +81,7 @@ func NewServer(cfg *config.Config) (*Server, error) {
resolver.NewMetricsResolver(cfg.Prometheus),
resolver.NewConditionalUpstreamResolver(cfg.Conditional),
resolver.NewCustomDNSResolver(cfg.CustomDNS),
resolver.NewBlockingResolver(cfg.Blocking),
resolver.NewBlockingResolver(router, cfg.Blocking),
resolver.NewCachingResolver(cfg.Caching),
resolver.NewParallelBestResolver(cfg.Upstream),
)
@ -86,18 +92,82 @@ func NewServer(cfg *config.Config) (*Server, error) {
queryResolver: queryResolver,
cfg: cfg,
httpListener: httpListener,
httpMux: router,
}
server.printConfiguration()
udpHandler.HandleFunc(".", server.OnRequest)
udpHandler.HandleFunc("healthcheck.blocky", server.OnHealthCheck)
tcpHandler.HandleFunc(".", server.OnRequest)
tcpHandler.HandleFunc("healthcheck.blocky", server.OnHealthCheck)
server.registerDNSHandlers(udpHandler)
server.registerDNSHandlers(tcpHandler)
return &server, nil
}
func (s *Server) registerDNSHandlers(handler *dns.ServeMux) {
handler.HandleFunc(".", s.OnRequest)
handler.HandleFunc("healthcheck.blocky", s.OnHealthCheck)
}
func createRouter(cfg *config.Config) *chi.Mux {
router := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300,
})
router.Use(cors.Handler)
router.Mount("/debug", middleware.Profiler())
router.Get("/swagger/*", func(writer http.ResponseWriter, request *http.Request) {
// set swagger host with host from request
docs.SwaggerInfo.Host = request.Host
swaggerHandler := httpSwagger.Handler(
httpSwagger.URL(fmt.Sprintf("http://%s/swagger/doc.json", request.Host)),
)
swaggerHandler.ServeHTTP(writer, request)
})
router.Get("/", func(writer http.ResponseWriter, request *http.Request) {
t := template.New("index")
_, _ = t.Parse(web.IndexTmpl)
type HandlerLink struct {
URL string
Title string
}
var links = []HandlerLink{
{
URL: fmt.Sprintf("http://%s/swagger/", request.Host),
Title: "Swagger Rest API Documentation",
},
{
URL: fmt.Sprintf("http://%s/debug/", request.Host),
Title: "Go Profiler",
},
}
if cfg.Prometheus.Enable {
links = append(links, HandlerLink{
URL: fmt.Sprintf("http://%s%s", request.Host, cfg.Prometheus.Path),
Title: "Prometheus endpoint",
})
}
err := t.Execute(writer, links)
if err != nil {
logrus.Error("can't write index template: ", err)
writer.WriteHeader(http.StatusInternalServerError)
}
})
return router
}
func (s *Server) printConfiguration() {
logger().Info("current configuration:")
@ -161,7 +231,7 @@ func (s *Server) Start() {
if s.httpListener != nil {
logger().Infof("http server is up and running on port %d", s.cfg.HTTPPort)
if err := http.Serve(s.httpListener, nil); err != nil {
if err := http.Serve(s.httpListener, s.httpMux); err != nil {
logger().Fatalf("start http listener failed: %v", err)
}
}
@ -197,7 +267,7 @@ func (s *Server) OnRequest(w dns.ResponseWriter, request *dns.Msg) {
r := &resolver.Request{
ClientIP: clientIP,
Req: request,
RequestTs: time.Now(),
RequestTS: time.Now(),
Log: logrus.WithFields(logrus.Fields{
"question": util.QuestionToString(request.Question),
"client_ip": clientIP,

View File

@ -348,7 +348,7 @@ func Test_Stop(t *testing.T) {
func BenchmarkServerExternalResolver(b *testing.B) {
upstreamExternal := resolver.TestUDPUpstream(func(request *dns.Msg) (response *dns.Msg) {
msg, _ := util.NewMsgWithAnswer(fmt.Sprintf("example.com IN A 123.124.122.122"))
msg, _ := util.NewMsgWithAnswer("example.com IN A 123.124.122.122")
return msg
})

16
web/index.go Normal file
View File

@ -0,0 +1,16 @@
package web
const IndexTmpl = `<!DOCTYPE html>
<html>
<head>
<title>blocky</title>
</head>
<body>
<h1>blocky</h1>
<ul>
{{range .}}
<li><a href="{{.URL}}">{{.Title}}</a></li>
{{end}}
</ul>
</body>
</html>`