From b8bff6372f7666a2f3766b14b4a2d121498225f7 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 12 Feb 2020 09:01:19 -0500 Subject: [PATCH 1/4] add git hooks --- .github/hooks/pre-commit | 16 ++++++++++++++++ .gitignore | 1 + Makefile | 19 ++++++++++++------- handler/Makefile | 9 +++++++-- handler/go.mod | 4 ++++ handler/go.sum | 11 +++++++++++ 6 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 .github/hooks/pre-commit diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit new file mode 100644 index 0000000..a029116 --- /dev/null +++ b/.github/hooks/pre-commit @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# GITLEAKS_PRECOMMIT_HOOK BEGIN +precommit_version="v0.0.1" +precommit_url="https://raw.githubusercontent.com/GSA/odp-code-repository-commit-rules/${precommit_version}/gitleaks/precommit.sh" +precommit_path="$(git rev-parse --show-toplevel)/.git/hooks/precommit.sh" + +if [ ! -f "${precommit_path}" ]; then + curl --silent -o "${precommit_path}" "${precommit_url}" + if [ "$os" = "Linux" ] || [ "$os" = "Darwin" ]; then + chmod +x "${precommit_path}" + fi +fi + +"${precommit_path}" "${precommit_version}" +# GITLEAKS_PRECOMMIT_HOOK END \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0add000..77380e0 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ release/ # IntelliJ’s project specific settings files/directory (Goland) .idea .idea/ +*.iml # vi/vim/GVim/MacVim backup files *.swp diff --git a/Makefile b/Makefile index f7f5165..cdce66d 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ test: test_handler plan_terraform deploy: build_handler apply_terraform -check: +check: precommit ifeq ($(strip $(backend_bucket)),) @echo "backend_bucket must be provided" @exit 1 @@ -30,19 +30,19 @@ ifeq ($(strip $(backend_key)),) @exit 1 endif -lint_handler: +lint_handler: precommit make -C handler lint -test_handler: +test_handler: precommit make -C handler test -build_handler: +build_handler: precommit make -C handler build -release_handler: +release_handler: precommit make -C handler release -integration_test: +integration_test: precommit make -C handler integration_test plan_terraform: validate_terraform @@ -65,5 +65,10 @@ apply_terraform_tests: destroy_terraform_tests: make -C tests destroy -clean: +clean: precommit make -C handler clean + +precommit: +ifneq ($(strip $(hooksPath)),.github/hooks) + @git config --add core.hooksPath .github/hooks +endif diff --git a/handler/Makefile b/handler/Makefile index 2121a79..c3766fa 100644 --- a/handler/Makefile +++ b/handler/Makefile @@ -28,7 +28,7 @@ else ghr -u $(CIRCLE_PROJECT_USERNAME) -r $(CIRCLE_PROJECT_REPONAME) -c $(CIRCLE_SHA1) -delete $(CIRCLE_TAG) $(RELEASEDIR) endif -clean: +clean: precommit rm -rf $(RELEASEDIR) test: lint @@ -47,7 +47,7 @@ ifeq (,$(wildcard go.mod)) go mod init endif -dependencies: $(GOLANGCILINT) $(GOSEC) $(GHR) +dependencies: precommit $(GOLANGCILINT) $(GOSEC) $(GHR) $(GOLANGCILINT): go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@v1.22.2 @@ -57,3 +57,8 @@ $(GOSEC): $(GHR): go get -u github.com/tcnksm/ghr + +precommit: +ifneq ($(strip $(hooksPath)),.github/hooks) + @git config --add core.hooksPath .github/hooks +endif \ No newline at end of file diff --git a/handler/go.mod b/handler/go.mod index f9d2858..40aaa4c 100644 --- a/handler/go.mod +++ b/handler/go.mod @@ -8,6 +8,10 @@ require ( github.com/caarlos0/env/v6 v6.1.0 github.com/google/go-cmp v0.3.1 github.com/gruntwork-io/terratest v0.23.0 + github.com/pkg/errors v0.9.1 // indirect github.com/tealeg/xlsx v1.0.5 + golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect + golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect + google.golang.org/appengine v1.6.5 // indirect gotest.tools/v3 v3.0.0 ) diff --git a/handler/go.sum b/handler/go.sum index 33c39a5..50aa773 100644 --- a/handler/go.sum +++ b/handler/go.sum @@ -49,6 +49,7 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 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 v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -96,6 +97,8 @@ github.com/oracle/oci-go-sdk v7.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.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/pquerna/otp v1.2.0 h1:/A3+Jn+cagqayeR3iHs/L62m5ue7710D35zl1zJ1kok= @@ -136,13 +139,17 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 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= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/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-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -153,6 +160,8 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -176,6 +185,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= From db66013b3421958f6e3112d612bc1dcfa811c63c Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 12 Feb 2020 09:30:42 -0500 Subject: [PATCH 2/4] add precommit to PHONY --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cdce66d..c71f611 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ endif export appenv := $(shell echo "$(environment)" | tr '[:upper:]' '[:lower:]') export TF_VAR_appenv := $(appenv) -.PHONY: test deploy check lint_handler test_handler build_handler release_handler integration_test plan_terraform validate_terraform init_terraform apply_terraform apply_terraform_tests destroy_terraform_tests clean +.PHONY: precommit test deploy check lint_handler test_handler build_handler release_handler integration_test plan_terraform validate_terraform init_terraform apply_terraform apply_terraform_tests destroy_terraform_tests clean test: test_handler plan_terraform deploy: build_handler apply_terraform From 8daab107a4ea21cca271680ef406c3021c0d90fb Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 12 Feb 2020 11:33:30 -0500 Subject: [PATCH 3/4] update precommit version --- .github/hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit index a029116..e105b42 100644 --- a/.github/hooks/pre-commit +++ b/.github/hooks/pre-commit @@ -1,7 +1,7 @@ #!/usr/bin/env sh # GITLEAKS_PRECOMMIT_HOOK BEGIN -precommit_version="v0.0.1" +precommit_version="v0.0.3" precommit_url="https://raw.githubusercontent.com/GSA/odp-code-repository-commit-rules/${precommit_version}/gitleaks/precommit.sh" precommit_path="$(git rev-parse --show-toplevel)/.git/hooks/precommit.sh" From a3f951c6f88fffd17b9c47609060d3a212416b46 Mon Sep 17 00:00:00 2001 From: Brady Date: Thu, 13 Feb 2020 14:20:34 -0500 Subject: [PATCH 4/4] fix os environment variable and update hook version --- .github/hooks/pre-commit | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit index e105b42..5f4231d 100644 --- a/.github/hooks/pre-commit +++ b/.github/hooks/pre-commit @@ -1,15 +1,14 @@ -#!/usr/bin/env sh - +#!/bin/sh # GITLEAKS_PRECOMMIT_HOOK BEGIN -precommit_version="v0.0.3" +precommit_latest_url=$(curl --silent --location --head --output /dev/null --write-out '%{url_effective}' -- https://github.com/GSA/odp-code-repository-commit-rules/releases/latest) +precommit_version=${precommit_latest_url##*/} precommit_url="https://raw.githubusercontent.com/GSA/odp-code-repository-commit-rules/${precommit_version}/gitleaks/precommit.sh" precommit_path="$(git rev-parse --show-toplevel)/.git/hooks/precommit.sh" -if [ ! -f "${precommit_path}" ]; then - curl --silent -o "${precommit_path}" "${precommit_url}" - if [ "$os" = "Linux" ] || [ "$os" = "Darwin" ]; then - chmod +x "${precommit_path}" - fi +curl --silent -o "${precommit_path}" "${precommit_url}" +os=$(uname -s | cut -d'_' -f 1) +if [ "$os" = "Linux" ] || [ "$os" = "Darwin" ]; then + chmod +x "${precommit_path}" fi "${precommit_path}" "${precommit_version}"