diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c02995b..6c5d362 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: Testing +name: Build and Test Commits on: push: @@ -8,11 +8,11 @@ on: jobs: build: - name: Test + name: Build and Test runs-on: ubuntu-latest strategy: matrix: - go: [ '1.13', '1.14' ] + go: [ '1.13', '1.14', '1.15' ] steps: - name: Set up timezone uses: zcong1993/setup-timezone@v1.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b6b5ef4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,67 @@ +on: + release: + types: [published] + +name: Build Assets for Release Tag + +jobs: + build: + name: Upload Asset to Release + runs-on: ubuntu-latest + strategy: + matrix: + platform: [ 'linux', 'freebsd', 'windows', 'darwin' ] + architecture: [ 'amd64' ] + include: + - platform: linux + architecture: arm + - platform: linux + architecture: arm64 + steps: + - name: Set up timezone + uses: zcong1993/setup-timezone@v1.0 + with: + timezone: America/Los_Angeles + + - name: Set up Golang + uses: actions/setup-go@v2 + with: + go-version: 1.15 + id: go + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build asset + env: + GOOS: ${{ matrix.platform }} + GOARCH: ${{ matrix.architecture }} + run: make release + + - name: Get release + id: get-release + uses: bruceadams/get-release@v1.2.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload zip asset + id: upload-release-zip-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get-release.outputs.upload_url }} + asset_path: ./release/gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip + asset_name: gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip + asset_content_type: application/zip + + - name: Upload sha256 asset + id: upload-release-sha256-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get-release.outputs.upload_url }} + asset_path: ./release/gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip.sha256 + asset_name: gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip.sha256 + asset_content_type: text/plain \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4da8928..94f7cba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,19 @@ scratch.txt targets.json +# Certificates +server.crt +server.key + +# Emitted binary and releases +gnmi-gateway +release/ + +# OpenConfig models download +oc-models/ + +# pprof debugging web server +cpu.pprof # GoLang-specific ignores # Binaries for programs and plugins @@ -172,16 +185,3 @@ com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties - -# Certificates -server.crt -server.key - -# Emitted binary -gnmi-gateway - -# OpenConfig models download -oc-models/ - -# pprof debugging web server -cpu.pprof diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1cb80f9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: go -go: - - "1.13" - - "1.14" - -script: - - make build - - ./gnmi-gateway -version - -branches: - only: - - release diff --git a/Makefile b/Makefile index e508c48..39af822 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ GOLDFLAGS += -X github.com/openconfig/gnmi-gateway/gateway.Version=$(VERSION) GOLDFLAGS += -X github.com/openconfig/gnmi-gateway/gateway.Buildtime=$(BUILDTIME) GOFLAGS = -ldflags "$(GOLDFLAGS)" +.PHONY: build release + build: clean go build -o gnmi-gateway $(GOFLAGS) . ./gnmi-gateway -version @@ -26,10 +28,29 @@ download: godoc: godoc -http=":6060" +imports: + goimports -local github.com/openconfig/gnmi-gateway -w -l $(shell find . -type f -name '*.go' -not -path './vendor/*' -not -path '*.pb.go') + integration: echo "Integration Test Note: Make sure you have Zookeeper running on 127.0.0.1:2181 (see README)." go test -tags=integration -count=1 -cover ./... +lint: imports + go fmt ./ ./gateway/... + go vet + +release: + mkdir -p release + rm -f release/gnmi-gateway release/gnmi-gateway.exe +ifeq ($(shell go env GOOS), windows) + go build -o release/gnmi-gateway.exe $(GOFLAGS) . + cd release; zip -m "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" gnmi-gateway.exe +else + go build -o release/gnmi-gateway $(GOFLAGS) . + cd release; zip -m "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" gnmi-gateway +endif + cd release; sha256sum "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" > "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip.sha256" + run: build ./gnmi-gateway -EnableGNMIServer -ServerTLSCert=server.crt -ServerTLSKey=server.key -TargetLoaders=json -TargetJSONFile=targets.json diff --git a/README.md b/README.md index 2626bc4..86b3a99 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,26 @@ gnmi-gateway cache, gNMI clients with relevant subscriptions, and Target Loaders are components that are used to generate target connection configurations that are sent to the connection manager. Target Loaders and the connection manager communicate using the [target.proto][6] model -found in the github.com/openconfig/gnmi repository. See +found in the github.com/openconfig/gnmi repository. gnmi-gateway accepts a few +additional parameters in the Target.meta field: + + NoTLSVerify: inlcude this field to disable TLS verification. This enables + the use of self-signed certificates. Note that connections + without TLS are not supported per the gNMI specification. + + NoLock: include this field to disable locking for the associated target even + if clustering is enabled. Only include this field if you are + handling de-duplication outside of gnmi-gateway. + +There are a few Target Loaders included with gnmi-gateway that you can use +right away using the `-TargetLoaders` flag from the command-line. The Target +Loaders included are: + +- [json](./gateway/loaders/json/json.go) +- [netbox](./gateway/loaders/netbox/netbox.go) +- [simple](./gateway/loaders/simple/simple.go) + +If you'd like to build your own Target Loader see [loaders/loader.go](./gateway/loaders/loader.go) for details on how to implement the TargetLoader interface. @@ -60,8 +79,17 @@ connections or you can run exporters on a server acting as clients to another gnmi-gateway cluster. This allows for some flexibility in your deployment design. -See [exporters/exporter.go](./gateway/exporters/exporter.go) for details on -how to implement the Exporter interface. +Some Exporters have been included with gnmi-gateway and you can start using them +by providing a comma-separated list of Exporters from the command-line with the +`-Exporters` flag. The included Exporters are: + +- [debug](./gateway/exporters/debug/debug.go) (log to stdout) +- [kafka](./gateway/exporters/kafka/kafka.go) +- [prometheus](./gateway/exporters/prometheus/prometheus.go) + +To build a custom Exporter see +[exporters/exporter.go](./gateway/exporters/exporter.go) for details on how to +implement the Exporter interface. ## Documentation diff --git a/gateway/clustering/zookeeper.go b/gateway/clustering/zookeeper.go index 0cfb94b..4dee916 100644 --- a/gateway/clustering/zookeeper.go +++ b/gateway/clustering/zookeeper.go @@ -17,10 +17,12 @@ package clustering import ( "fmt" - "github.com/go-zookeeper/zk" - "github.com/openconfig/gnmi-gateway/gateway/configuration" "strings" "time" + + "github.com/go-zookeeper/zk" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" ) const ClusterMemberPath = "/members" diff --git a/gateway/clustering/zookeeper_integration_test.go b/gateway/clustering/zookeeper_integration_test.go index 384756c..d662807 100644 --- a/gateway/clustering/zookeeper_integration_test.go +++ b/gateway/clustering/zookeeper_integration_test.go @@ -19,13 +19,15 @@ package clustering_test import ( "fmt" - "github.com/go-zookeeper/zk" - "github.com/openconfig/gnmi-gateway/gateway/clustering" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/stretchr/testify/assert" "sync" "testing" "time" + + "github.com/go-zookeeper/zk" + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/clustering" + "github.com/openconfig/gnmi-gateway/gateway/configuration" ) const ZookeeperIntegrationServerAddress = "127.0.0.1:2181" diff --git a/gateway/configuration/config.go b/gateway/configuration/config.go index 6873781..22f8684 100644 --- a/gateway/configuration/config.go +++ b/gateway/configuration/config.go @@ -22,14 +22,15 @@ import ( "crypto/tls" "encoding/json" "fmt" - "github.com/Netflix/spectator-go" - gnmipb "github.com/openconfig/gnmi/proto/gnmi" - "github.com/rs/zerolog" - "google.golang.org/grpc/credentials" "io/ioutil" "os" "path/filepath" "time" + + "github.com/Netflix/spectator-go" + gnmipb "github.com/openconfig/gnmi/proto/gnmi" + "github.com/rs/zerolog" + "google.golang.org/grpc/credentials" ) // GatewayConfig contains all of the configurables and tunables for various components of the gateway. diff --git a/gateway/connections/state.go b/gateway/connections/state.go index fb554fe..d09becd 100644 --- a/gateway/connections/state.go +++ b/gateway/connections/state.go @@ -33,21 +33,23 @@ import ( "context" "crypto/tls" "fmt" + "sync" + "time" + "github.com/Netflix/spectator-go" "github.com/Netflix/spectator-go/histogram" "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/locking" - "github.com/openconfig/gnmi-gateway/gateway/stats" - "github.com/openconfig/gnmi-gateway/gateway/utils" "github.com/openconfig/gnmi/cache" "github.com/openconfig/gnmi/client" gnmiclient "github.com/openconfig/gnmi/client/gnmi" gnmipb "github.com/openconfig/gnmi/proto/gnmi" targetpb "github.com/openconfig/gnmi/proto/target" "golang.org/x/sync/semaphore" - "sync" - "time" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/locking" + "github.com/openconfig/gnmi-gateway/gateway/stats" + "github.com/openconfig/gnmi-gateway/gateway/utils" ) // ConnectionState makes the calls to connect a target, tracks any associated connection state, and is the container for @@ -69,6 +71,9 @@ type ConnectionState struct { lock locking.DistributedLocker // The unique name of the target that is being connected to name string + // noTLSWarning indicates if the warning about the NoTLS flag deprecation + // has been displayed yet. + noTLSWarning bool queryTarget string request *gnmipb.SubscribeRequest // seen is the list of targets that have been seen on this connection @@ -159,9 +164,15 @@ func (t *ConnectionState) doConnect() { // TODO (cmcintosh): make PR for targetpb to include TLS config and remove this _, NoTLS := t.target.Meta["NoTLS"] + if NoTLS && !t.noTLSWarning { + t.noTLSWarning = true + t.config.Log.Warn().Msg("DEPRECATED: The 'NoTLS' target flag has been deprecated and will be removed in a future release. Please use 'NoTLSVerify' instead.") + } + + _, NoTLSVerify := t.target.Meta["NoTLSVerify"] // TLS is always enabled for localTargets but we won't verify certs if no client TLS config exists. - if t.config.ClientTLSConfig != nil && !NoTLS { + if t.config.ClientTLSConfig != nil && (!NoTLS || !NoTLSVerify) { query.TLS = t.config.ClientTLSConfig } else { query.TLS = &tls.Config{ diff --git a/gateway/connections/zookeeper.go b/gateway/connections/zookeeper.go index f5a785e..835514c 100644 --- a/gateway/connections/zookeeper.go +++ b/gateway/connections/zookeeper.go @@ -21,12 +21,13 @@ import ( "sync" "github.com/go-zookeeper/zk" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/locking" "github.com/openconfig/gnmi/cache" targetlib "github.com/openconfig/gnmi/target" "github.com/rs/zerolog/log" "golang.org/x/sync/semaphore" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/locking" ) var _ ConnectionManager = new(ZookeeperConnectionManager) diff --git a/gateway/connections/zookeeper_test.go b/gateway/connections/zookeeper_test.go index 052359c..b969992 100644 --- a/gateway/connections/zookeeper_test.go +++ b/gateway/connections/zookeeper_test.go @@ -16,10 +16,12 @@ package connections import ( - "github.com/openconfig/gnmi-gateway/gateway/configuration" + "testing" + "github.com/openconfig/gnmi/client" "github.com/stretchr/testify/assert" - "testing" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" ) func TestNewZookeeperConnectionManagerDefault(t *testing.T) { diff --git a/gateway/exporters/all/all.go b/gateway/exporters/all/all.go index e21d869..5e18242 100644 --- a/gateway/exporters/all/all.go +++ b/gateway/exporters/all/all.go @@ -15,6 +15,8 @@ package all -import _ "github.com/openconfig/gnmi-gateway/gateway/exporters/debug" -import _ "github.com/openconfig/gnmi-gateway/gateway/exporters/kafka" -import _ "github.com/openconfig/gnmi-gateway/gateway/exporters/prometheus" +import ( + _ "github.com/openconfig/gnmi-gateway/gateway/exporters/debug" + _ "github.com/openconfig/gnmi-gateway/gateway/exporters/kafka" + _ "github.com/openconfig/gnmi-gateway/gateway/exporters/prometheus" +) diff --git a/gateway/exporters/debug/debug.go b/gateway/exporters/debug/debug.go index 8301360..aaa210f 100644 --- a/gateway/exporters/debug/debug.go +++ b/gateway/exporters/debug/debug.go @@ -18,12 +18,13 @@ package debug import ( - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/exporters" - "github.com/openconfig/gnmi-gateway/gateway/utils" "github.com/openconfig/gnmi/cache" "github.com/openconfig/gnmi/ctree" gnmipb "github.com/openconfig/gnmi/proto/gnmi" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/exporters" + "github.com/openconfig/gnmi-gateway/gateway/utils" ) const Name = "debug" diff --git a/gateway/exporters/exporter.go b/gateway/exporters/exporter.go index 731c3fa..8e6d37a 100644 --- a/gateway/exporters/exporter.go +++ b/gateway/exporters/exporter.go @@ -20,9 +20,10 @@ package exporters //go:generate mockgen -destination=exporter_mock_test.go -package=exporters_test github.com/openconfig/gnmi-gateway/gateway/exporters Exporter import ( - "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi/cache" "github.com/openconfig/gnmi/ctree" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" ) var Registry = make(map[string]func(config *configuration.GatewayConfig) Exporter) diff --git a/gateway/exporters/exporter_mock_test.go b/gateway/exporters/exporter_mock_test.go index 0c31967..0730c7a 100644 --- a/gateway/exporters/exporter_mock_test.go +++ b/gateway/exporters/exporter_mock_test.go @@ -5,10 +5,11 @@ package exporters_test import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" cache "github.com/openconfig/gnmi/cache" ctree "github.com/openconfig/gnmi/ctree" - reflect "reflect" ) // MockExporter is a mock of Exporter interface diff --git a/gateway/exporters/kafka/kafka.go b/gateway/exporters/kafka/kafka.go index 16e99d5..ca43bf6 100644 --- a/gateway/exporters/kafka/kafka.go +++ b/gateway/exporters/kafka/kafka.go @@ -18,15 +18,17 @@ package kafka import ( "context" "errors" + "github.com/golang/protobuf/proto" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/exporters" - "github.com/openconfig/gnmi-gateway/gateway/utils" "github.com/openconfig/gnmi/cache" "github.com/openconfig/gnmi/ctree" gnmipb "github.com/openconfig/gnmi/proto/gnmi" "github.com/rs/zerolog" "github.com/segmentio/kafka-go" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/exporters" + "github.com/openconfig/gnmi-gateway/gateway/utils" ) const Name = "kafka" diff --git a/gateway/exporters/prometheus/delta.go b/gateway/exporters/prometheus/delta.go index 98ada1d..c968162 100644 --- a/gateway/exporters/prometheus/delta.go +++ b/gateway/exporters/prometheus/delta.go @@ -16,9 +16,10 @@ package prometheus import ( - "github.com/cespare/xxhash/v2" "sort" "sync" + + "github.com/cespare/xxhash/v2" ) func NewDeltaCalculator() *DeltaCalculator { diff --git a/gateway/exporters/prometheus/prometheus.go b/gateway/exporters/prometheus/prometheus.go index d834a79..0f52440 100644 --- a/gateway/exporters/prometheus/prometheus.go +++ b/gateway/exporters/prometheus/prometheus.go @@ -18,17 +18,19 @@ package prometheus import ( "errors" "fmt" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/exporters" - "github.com/openconfig/gnmi-gateway/gateway/openconfig" + "net/http" + "strings" + "github.com/openconfig/gnmi/cache" "github.com/openconfig/gnmi/ctree" gnmipb "github.com/openconfig/gnmi/proto/gnmi" prom "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" - "net/http" - "strings" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/exporters" + "github.com/openconfig/gnmi-gateway/gateway/openconfig" ) const Name = "prometheus" diff --git a/gateway/exporters/prometheus/prometheus_test.go b/gateway/exporters/prometheus/prometheus_test.go index b7cac24..d0ad235 100644 --- a/gateway/exporters/prometheus/prometheus_test.go +++ b/gateway/exporters/prometheus/prometheus_test.go @@ -16,13 +16,15 @@ package prometheus_test import ( - "github.com/openconfig/gnmi-gateway/gateway/exporters" - "github.com/openconfig/gnmi-gateway/gateway/exporters/prometheus" - prom "github.com/prometheus/client_golang/prometheus" - "github.com/stretchr/testify/assert" "math/rand" "strconv" "testing" + + prom "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/exporters" + "github.com/openconfig/gnmi-gateway/gateway/exporters/prometheus" ) var _ exporters.Exporter = new(prometheus.PrometheusExporter) diff --git a/gateway/gateway.go b/gateway/gateway.go index b3fca20..17a28a9 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -73,6 +73,12 @@ import ( "github.com/Netflix/spectator-go" "github.com/go-zookeeper/zk" + "github.com/openconfig/gnmi/ctree" + "github.com/openconfig/gnmi/proto/gnmi" + "github.com/rs/zerolog" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "github.com/openconfig/gnmi-gateway/gateway/clustering" "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/connections" @@ -81,11 +87,6 @@ import ( "github.com/openconfig/gnmi-gateway/gateway/loaders/cluster" "github.com/openconfig/gnmi-gateway/gateway/server" "github.com/openconfig/gnmi-gateway/gateway/stats" - "github.com/openconfig/gnmi/ctree" - "github.com/openconfig/gnmi/proto/gnmi" - "github.com/rs/zerolog" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" ) var ( diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index ec6e030..9b9f6eb 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -17,13 +17,14 @@ package gateway import ( "fmt" + "os" + "time" + "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/exporters" "github.com/openconfig/gnmi-gateway/gateway/exporters/prometheus" "github.com/openconfig/gnmi-gateway/gateway/loaders" "github.com/openconfig/gnmi-gateway/gateway/loaders/json" - "os" - "time" ) // A simple example of how to configure the gateway. diff --git a/gateway/loaders/all/all.go b/gateway/loaders/all/all.go index a0d1f91..ce01197 100644 --- a/gateway/loaders/all/all.go +++ b/gateway/loaders/all/all.go @@ -15,6 +15,8 @@ package all -import _ "github.com/openconfig/gnmi-gateway/gateway/loaders/json" -import _ "github.com/openconfig/gnmi-gateway/gateway/loaders/netbox" -import _ "github.com/openconfig/gnmi-gateway/gateway/loaders/simple" +import ( + _ "github.com/openconfig/gnmi-gateway/gateway/loaders/json" + _ "github.com/openconfig/gnmi-gateway/gateway/loaders/netbox" + _ "github.com/openconfig/gnmi-gateway/gateway/loaders/simple" +) diff --git a/gateway/loaders/cluster/cluster.go b/gateway/loaders/cluster/cluster.go index b61eb69..fec7764 100644 --- a/gateway/loaders/cluster/cluster.go +++ b/gateway/loaders/cluster/cluster.go @@ -17,14 +17,17 @@ package cluster import ( "fmt" + + "github.com/openconfig/gnmi/proto/gnmi" + "github.com/openconfig/gnmi/proto/target" + "github.com/openconfig/gnmi-gateway/gateway/clustering" "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/connections" - "github.com/openconfig/gnmi/proto/gnmi" - "github.com/openconfig/gnmi/proto/target" ) -// ClusterTargetLoader is used internally to connect/disconnect from other cluster members if clustering is enabled. +// ClusterTargetLoader is used internally to connect/disconnect from other +// cluster members if clustering is enabled. type ClusterTargetLoader struct { config *configuration.GatewayConfig cluster clustering.ClusterMember diff --git a/gateway/loaders/json/json.go b/gateway/loaders/json/json.go index 3305606..90d26d7 100644 --- a/gateway/loaders/json/json.go +++ b/gateway/loaders/json/json.go @@ -17,14 +17,16 @@ package json import ( "fmt" + "os" + "time" + "github.com/golang/protobuf/jsonpb" + targetpb "github.com/openconfig/gnmi/proto/target" + "github.com/openconfig/gnmi/target" + "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/connections" "github.com/openconfig/gnmi-gateway/gateway/loaders" - targetpb "github.com/openconfig/gnmi/proto/target" - "github.com/openconfig/gnmi/target" - "os" - "time" ) var _ loaders.TargetLoader = new(JSONFileTargetLoader) diff --git a/gateway/loaders/loader.go b/gateway/loaders/loader.go index 745de2b..3e7294b 100644 --- a/gateway/loaders/loader.go +++ b/gateway/loaders/loader.go @@ -18,9 +18,10 @@ package loaders import ( + targetpb "github.com/openconfig/gnmi/proto/target" + "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/connections" - targetpb "github.com/openconfig/gnmi/proto/target" ) var Registry = make(map[string]func(config *configuration.GatewayConfig) TargetLoader) diff --git a/gateway/loaders/netbox/netbox.go b/gateway/loaders/netbox/netbox.go index 093b7e6..66a73fa 100644 --- a/gateway/loaders/netbox/netbox.go +++ b/gateway/loaders/netbox/netbox.go @@ -19,19 +19,21 @@ package netbox import ( "context" "fmt" + "net" + "strconv" + "time" + "github.com/google/gnxi/utils/xpath" "github.com/netbox-community/go-netbox/netbox" "github.com/netbox-community/go-netbox/netbox/client" "github.com/netbox-community/go-netbox/netbox/client/dcim" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/connections" - "github.com/openconfig/gnmi-gateway/gateway/loaders" "github.com/openconfig/gnmi/proto/gnmi" targetpb "github.com/openconfig/gnmi/proto/target" "github.com/openconfig/gnmi/target" - "net" - "strconv" - "time" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/connections" + "github.com/openconfig/gnmi-gateway/gateway/loaders" ) const Name = "netbox" diff --git a/gateway/loaders/simple/simple.go b/gateway/loaders/simple/simple.go index bfe20ee..8b84bd7 100644 --- a/gateway/loaders/simple/simple.go +++ b/gateway/loaders/simple/simple.go @@ -33,16 +33,18 @@ package simple import ( "fmt" + "io/ioutil" + "time" + "github.com/google/gnxi/utils/xpath" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/connections" - "github.com/openconfig/gnmi-gateway/gateway/loaders" "github.com/openconfig/gnmi/proto/gnmi" targetpb "github.com/openconfig/gnmi/proto/target" "github.com/openconfig/gnmi/target" "gopkg.in/yaml.v2" - "io/ioutil" - "time" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/connections" + "github.com/openconfig/gnmi-gateway/gateway/loaders" ) var _ loaders.TargetLoader = new(SimpleTargetLoader) diff --git a/gateway/loaders/simple/simple_test.go b/gateway/loaders/simple/simple_test.go index 54dcb38..bd8ad53 100644 --- a/gateway/loaders/simple/simple_test.go +++ b/gateway/loaders/simple/simple_test.go @@ -16,9 +16,11 @@ package simple import ( - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" ) const TestData = ` diff --git a/gateway/locking/local_test.go b/gateway/locking/local_test.go index 9d25c69..f95bafb 100644 --- a/gateway/locking/local_test.go +++ b/gateway/locking/local_test.go @@ -16,9 +16,11 @@ package locking_test import ( - "github.com/openconfig/gnmi-gateway/gateway/locking" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/locking" ) func TestNonBlockingLock_Try(t *testing.T) { diff --git a/gateway/locking/zookeeper.go b/gateway/locking/zookeeper.go index ea75b69..6b9028e 100644 --- a/gateway/locking/zookeeper.go +++ b/gateway/locking/zookeeper.go @@ -46,10 +46,11 @@ package locking import ( "fmt" - "github.com/go-zookeeper/zk" "strconv" "strings" "time" + + "github.com/go-zookeeper/zk" ) type ZookeeperNonBlockingLock struct { diff --git a/gateway/locking/zookeeper_integration_test.go b/gateway/locking/zookeeper_integration_test.go index 73dc7de..d634440 100644 --- a/gateway/locking/zookeeper_integration_test.go +++ b/gateway/locking/zookeeper_integration_test.go @@ -19,11 +19,13 @@ package locking_test import ( "fmt" - "github.com/go-zookeeper/zk" - "github.com/openconfig/gnmi-gateway/gateway/locking" - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/go-zookeeper/zk" + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/locking" ) const ZookeeperIntegrationServerAddress = "127.0.0.1:2181" diff --git a/gateway/main.go b/gateway/main.go index 50e29b1..33cbbb6 100644 --- a/gateway/main.go +++ b/gateway/main.go @@ -18,10 +18,6 @@ package gateway import ( "flag" "fmt" - "github.com/kelseyhightower/envconfig" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - _ "github.com/openconfig/gnmi-gateway/gateway/exporters/all" - _ "github.com/openconfig/gnmi-gateway/gateway/loaders/all" "net/http" "os" "os/signal" @@ -29,6 +25,12 @@ import ( "strings" "syscall" "time" + + "github.com/kelseyhightower/envconfig" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + _ "github.com/openconfig/gnmi-gateway/gateway/exporters/all" + _ "github.com/openconfig/gnmi-gateway/gateway/loaders/all" ) // Main is the entry point for the command-line and it's a good example of how to call StartGateway but diff --git a/gateway/openconfig/types.go b/gateway/openconfig/types.go index 70f690f..c0e9c8e 100644 --- a/gateway/openconfig/types.go +++ b/gateway/openconfig/types.go @@ -35,11 +35,12 @@ package openconfig import ( - "github.com/openconfig/goyang/pkg/yang" "os" "path/filepath" "sort" "strings" + + "github.com/openconfig/goyang/pkg/yang" ) type TypeLookup struct { diff --git a/gateway/server/server.go b/gateway/server/server.go index 7f3ef29..31a69ed 100644 --- a/gateway/server/server.go +++ b/gateway/server/server.go @@ -40,13 +40,14 @@ import ( "context" "errors" "fmt" + "io" + "strings" + "time" + "github.com/openconfig/gnmi-gateway/gateway/clustering" "github.com/openconfig/gnmi-gateway/gateway/configuration" "github.com/openconfig/gnmi-gateway/gateway/connections" "github.com/openconfig/gnmi-gateway/gateway/stats" - "io" - "strings" - "time" "github.com/golang/protobuf/proto" "github.com/openconfig/gnmi/cache" diff --git a/gateway/server/server_test.go b/gateway/server/server_test.go index 3453d24..f8b3b93 100644 --- a/gateway/server/server_test.go +++ b/gateway/server/server_test.go @@ -39,9 +39,6 @@ import ( "crypto/tls" "errors" "fmt" - "github.com/openconfig/gnmi-gateway/gateway/clustering" - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/connections" "io" "net" "strings" @@ -49,6 +46,10 @@ import ( "testing" "time" + "github.com/openconfig/gnmi-gateway/gateway/clustering" + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/connections" + "github.com/golang/protobuf/proto" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" diff --git a/gateway/stats/spectator.go b/gateway/stats/spectator.go index b162a7b..f68e33c 100644 --- a/gateway/stats/spectator.go +++ b/gateway/stats/spectator.go @@ -17,9 +17,11 @@ package stats import ( "fmt" + "time" + "github.com/Netflix/spectator-go" + "github.com/openconfig/gnmi-gateway/gateway/configuration" - "time" ) var Registry *spectator.Registry diff --git a/gateway/stats/spectator_test.go b/gateway/stats/spectator_test.go index ec505ca..1dd1c53 100644 --- a/gateway/stats/spectator_test.go +++ b/gateway/stats/spectator_test.go @@ -16,12 +16,14 @@ package stats_test import ( - "github.com/openconfig/gnmi-gateway/gateway/configuration" - "github.com/openconfig/gnmi-gateway/gateway/stats" - "github.com/stretchr/testify/assert" "strconv" "sync" "testing" + + "github.com/stretchr/testify/assert" + + "github.com/openconfig/gnmi-gateway/gateway/configuration" + "github.com/openconfig/gnmi-gateway/gateway/stats" ) // some arbitrary value to keep the math consistent diff --git a/gateway/utils/utils.go b/gateway/utils/utils.go index 42b0a9b..f352ffc 100644 --- a/gateway/utils/utils.go +++ b/gateway/utils/utils.go @@ -17,9 +17,10 @@ package utils import ( "fmt" - "github.com/openconfig/gnmi/proto/gnmi" "sort" "strings" + + "github.com/openconfig/gnmi/proto/gnmi" ) // GNMINotificationPrettyString returns a human-readable string for diff --git a/targets-example.json b/targets-example.json index 297723f..6ab559a 100644 --- a/targets-example.json +++ b/targets-example.json @@ -29,7 +29,7 @@ }, "request": "default", "meta": { - "NoTLS": "yes" + "NoTLSVerify": "yes" } } } diff --git a/targets-example.yaml b/targets-example.yaml new file mode 100644 index 0000000..a728d0e --- /dev/null +++ b/targets-example.yaml @@ -0,0 +1,16 @@ +--- +connection: + demo-gnmi-router: + addresses: + - demo-gnmi-router.example.com:9339 + request: demo-request + meta: {} +request: + demo-request: + target: "*" + paths: + - /components + - /interfaces/interface[name=*]/state/counters + - /interfaces/interface[name=*]/ethernet/state/counters + - /interfaces/interface[name=*]/subinterfaces/subinterface[index=*]/state/counters + - /qos/interfaces/interface[interface-id=*]/output/queues/queue[name=*]/state