- adding the coverage, vetting and linting to the Makefile and test stage
- fixing the "range variable listener captured by func literal" issue
This commit is contained in:
parent
8ce85540b3
commit
9880cc458e
31
Makefile
31
Makefile
|
@ -3,23 +3,28 @@ NAME=vault-sidekick
|
|||
AUTHOR=gambol99
|
||||
HARDWARE=$(shell uname -m)
|
||||
VERSION=$(shell awk '/Version =/ { print $$3 }' main.go | sed 's/"//g')
|
||||
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr
|
||||
|
||||
.PHONY: test authors changelog build docker static release
|
||||
|
||||
default: build
|
||||
|
||||
build:
|
||||
@echo "--> Compiling the project"
|
||||
mkdir -p bin
|
||||
go build -o bin/${NAME}
|
||||
|
||||
docker: build
|
||||
@echo "--> Building the docker image"
|
||||
sudo docker build -t ${AUTHOR}/${NAME}:${VERSION} .
|
||||
|
||||
static:
|
||||
@echo "--> Compiling the static binary"
|
||||
mkdir -p bin
|
||||
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags '-w' -o bin/${NAME}
|
||||
|
||||
push: docker
|
||||
@echo "--> Pushing the image to docker.io"
|
||||
sudo docker tag -f ${AUTHOR}/${NAME}:${VERSION} docker.io/${AUTHOR}/${NAME}:${VERSION}
|
||||
sudo docker push docker.io/${AUTHOR}/${NAME}:${VERSION}
|
||||
|
||||
|
@ -33,16 +38,34 @@ clean:
|
|||
rm -rf ./release 2>/dev/null
|
||||
|
||||
authors:
|
||||
@echo "--> Updating the AUTHORS"
|
||||
git log --format='%aN <%aE>' | sort -u > AUTHORS
|
||||
|
||||
deps:
|
||||
@echo "--> Installing build dependencies"
|
||||
go get -d -v ./...
|
||||
go get github.com/stretchr/testify/assert
|
||||
|
||||
vet:
|
||||
@echo "--> Running go tool vet $(VETARGS) ."
|
||||
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
|
||||
go get golang.org/x/tools/cmd/vet; \
|
||||
fi
|
||||
@go tool vet $(VETARGS) .
|
||||
|
||||
format:
|
||||
@echo "--> Running go fmt"
|
||||
@go fmt $(PACKAGES)
|
||||
|
||||
cover:
|
||||
@echo "--> Running go cover"
|
||||
go list ./... | xargs -n1 go test --cover
|
||||
|
||||
test:
|
||||
go get
|
||||
go get github.com/stretchr/testify/assert
|
||||
test: deps
|
||||
@echo "--> Running the tests"
|
||||
go test -v
|
||||
make cover
|
||||
@$(MAKE) vet
|
||||
@$(MAKE) cover
|
||||
|
||||
changelog: release
|
||||
git log $(shell git tag | tail -n1)..HEAD --no-merges --format=%B > changelog
|
||||
|
|
18
vault.go
18
vault.go
|
@ -72,12 +72,9 @@ func NewVaultService(url string) (*VaultService, error) {
|
|||
service.config = api.DefaultConfig()
|
||||
service.config.Address = url
|
||||
service.listeners = make([]chan VaultEvent, 0)
|
||||
|
||||
// step: skip the cert verification if requested
|
||||
if options.tlsVerify {
|
||||
service.config.HttpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
service.config.HttpClient.Transport, err = service.getHTTPTransport()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// step: create the service processor channels
|
||||
|
@ -101,7 +98,7 @@ func NewVaultService(url string) (*VaultService, error) {
|
|||
return service, nil
|
||||
}
|
||||
|
||||
func (r *VaultService) getHttpTransport() (*http.Transport, error) {
|
||||
func (r *VaultService) getHTTPTransport() (*http.Transport, error) {
|
||||
transport := &http.Transport{}
|
||||
|
||||
// step: are we skip the tls verify?
|
||||
|
@ -309,13 +306,12 @@ func (r VaultService) scheduleIn(rn *watchedResource, ch chan *watchedResource,
|
|||
func (r VaultService) upstream(item *watchedResource) {
|
||||
// step: chunk this into a go-routine not to block us
|
||||
for _, listener := range r.listeners {
|
||||
go func() {
|
||||
glog.V(6).Infof("sending the event for resource: %s upstream to listener: %v", item.resource, listener)
|
||||
listener <- VaultEvent{
|
||||
go func(ch chan VaultEvent) {
|
||||
ch <- VaultEvent{
|
||||
Resource: item.resource,
|
||||
Secret: item.secret.Data,
|
||||
}
|
||||
}()
|
||||
}(listener)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue