diff --git a/Makefile b/Makefile index ece3a2c..fd98c29 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,32 @@ -BINARY=k8guard-action +.DEFAULT_GOAL := help +.PHONY: help +BINARY=k8guard-action VERSION=`git fetch;git describe --tags > /dev/null 2>&1` BUILD=`date +%FT%T%z` LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}" -all: deps build test +all: deps build test ## install dependecies, build for linux + +create-pre-commit-hooks: ## creates pre-commit hooks + chmod +x $(CURDIR)/hooks/pre-commit + ln -s $(CURDIR)/hooks/pre-commit .git/hooks/pre-commit || true -deps: +deps: ## install dependecies glide install glide-update: glide cc glide update -build-docker: +build-docker: ## builds docker local/k8guard-action docker build -t local/k8guard-action . -build: +build: ## builds binary for linux CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${BINARY} -mac: +mac: ## builds binary for mac CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o ${BINARY} dev-setup: @@ -30,7 +36,8 @@ clean: if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi go clean -sclean: clean +sclean: clean ## super clean, cleans binary and glide lock rm glide.lock -.PHONY: build +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/README.md b/README.md index 70d6ce0..e69bb97 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # k8guard-action +[![Go Report Card](https://goreportcard.com/badge/github.com/k8guard/k8guard-action)](https://goreportcard.com/report/github.com/k8guard/k8guard-action) For documentation please visit [K8Guard Website](https://k8guard.github.io/). diff --git a/db/actionqueries.go b/db/actionqueries.go index 9c0c699..3f67ce9 100644 --- a/db/actionqueries.go +++ b/db/actionqueries.go @@ -2,9 +2,10 @@ package db import ( "fmt" - "github.com/k8guard/k8guard-action/db/stmts" "time" + "github.com/k8guard/k8guard-action/db/stmts" + "github.com/gocql/gocql" libs "github.com/k8guard/k8guardlibs" diff --git a/db/stmts/stmts.go b/db/stmts/stmts.go index e74407f..2bdeec3 100644 --- a/db/stmts/stmts.go +++ b/db/stmts/stmts.go @@ -98,13 +98,12 @@ const ( WITH CLUSTERING ORDER BY (created_at desc) ` - INSERT_TO_VLOG = `INSERT INTO %s.vlog_namespace_type (namespace, cluster, type, source, vType, vSource, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)` + INSERT_TO_VLOG = `INSERT INTO %s.vlog_namespace_type (namespace, cluster, type, source, vType, vSource, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)` INSERT_TO_ALOG_NAMESPACE_TYPE = `INSERT INTO %s.alog_namespace_type (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - INSERT_TO_ALOG_TYPE = `INSERT INTO %s.alog_type (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - INSERT_TO_ALOG_VTYPE = `INSERT INTO %s.alog_vType (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - INSERT_TO_ALOG_ACTION = `INSERT INTO %s.alog_action (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - + INSERT_TO_ALOG_TYPE = `INSERT INTO %s.alog_type (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` + INSERT_TO_ALOG_VTYPE = `INSERT INTO %s.alog_vType (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` + INSERT_TO_ALOG_ACTION = `INSERT INTO %s.alog_action (namespace, cluster, type, source, vType, vSource, action, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)` INSERT_TO_VACTION = `INSERT INTO %s.vaction (namespace, cluster, type, source, vType, vSource, actions, created_at ,expire_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)` diff --git a/hooks/pre-commit b/hooks/pre-commit index e1a0660..6af1f57 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,5 +1,5 @@ #!/bin/sh - +printf "\n--- pre-commit formatting ---\n\n" go vet 2>&1 if [ $? -ne 0 ] then @@ -9,7 +9,7 @@ then exit 1 fi -gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$') +gofiles=$(git diff --name-only --diff-filter=ACM | grep '\.go$') [ -z "$gofiles" ] && exit 0 printf "Formatting the following Go files:\n" @@ -19,6 +19,6 @@ for file in $gofiles; do git add $PWD/$file done -printf "\n------------------------\n\n" +printf "\n--- Done ! ---\n\n" exit 0 diff --git a/messaging/consume.go b/messaging/consume.go index 9b402f8..2633ef3 100644 --- a/messaging/consume.go +++ b/messaging/consume.go @@ -11,9 +11,10 @@ import ( "github.com/k8guard/k8guardlibs/messaging/kafka" "encoding/json" - "github.com/k8guard/k8guard-action/actions" "reflect" + "github.com/k8guard/k8guard-action/actions" + "github.com/k8guard/k8guard-action/db" "github.com/k8guard/k8guardlibs/violations"