forked from splunk/vault-plugin-splunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (47 loc) · 1.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
VERSION := 0.1.0
SHORT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
GO_VERSION := $(shell go version | awk '{ print $$3}' | sed 's/^go//')
TESTREPORT := test-results.xml
# XXX BUG(mweber) "go env GOBIN" is empty?
GOBIN := $(shell go env GOPATH)/bin
LD_FLAGS_PKG ?= main
LD_FLAGS :=
LD_FLAGS += -X "$(LD_FLAGS_PKG).version=$(VERSION)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).commit=$(SHORT_COMMIT)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).goVersion=$(GO_VERSION)"
.PHONY: all
all: dep build lint test
.PHONY: dep
dep: prereq
dep ensure $(DEPFLAGS)
.PHONY: build
build: dep vault.hcl
go install -ldflags '$(LD_FLAGS)' ./...
vault.hcl: vault.hcl.in
sed -e 's;@@GOBIN@@;$(GOBIN);g' < $< > $@
.PHONY: dev
dev: build
@test -n "$$VAULT_ADDR" || { echo 'error: environment variable VAULT_ADDR not set'; exit 1; }
@test -f ~/.vault-token || { echo 'error: ~/.vault-token does not exist. Use "vault auth ..." to login.'; exit 1; }
SHASUM=$$(shasum -a 256 "$(GOBIN)/vault-plugin-splunk" | cut -d " " -f1); \
vault write sys/plugins/catalog/secret/vault-plugin-splunk sha_256="$$SHASUM" command="vault-plugin-splunk"
vault secrets enable -path=splunk -plugin-name=vault-plugin-splunk plugin || true
curl -vk -H "X-Vault-Token: $$(cat ~/.vault-token)" $$VAULT_ADDR/v1/sys/plugins/reload/backend -XPUT -d '{"plugin":"vault-plugin-splunk"}'
.PHONY: test
test: build
@test -n "$$SPLUNK_ADDR" || { echo 'warning: SPLUNK_ADDR not set, creating new Splunk instances. This will be slow.'; }
mkdir -p $(dir $(TESTREPORT))
gotestsum --junitfile $(TESTREPORT) -- -cover -v ./...
.PHONY: lint
lint: dep
go list ./... | grep -v vendor | xargs go vet
go list ./... | grep -v vendor | xargs golint
.PHONY: prereq
prereq:
go get github.com/golang/dep/cmd/dep
go get golang.org/x/lint/golint
go get gotest.tools/gotestsum
.PHONY: clean
clean:
# XXX clean
rm -rf vault.hcl $(TESTREPORT) vendor/