Skip to content

Commit 8d14602

Browse files
authored
Merge pull request #27 from devops-kung-fu/2.1.1
feat: README.md updates about security, minor tweaks
2 parents 98d8ddc + b39a3de commit 8d14602

File tree

6 files changed

+86
-44
lines changed

6 files changed

+86
-44
lines changed

.hookz.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
echo -e Tidying all found go.mod occurrences\n
1212
find . -name go.mod -print0 | xargs -0 -n1 dirname | xargs -L 1 bash -c 'cd \"$0\" && pwd && go mod tidy' \n
1313
"
14-
- name: "Go Build (Ensure pulled modules do not break the build)"
15-
exec: go
16-
args: ["build"]
1714
- name: "Update all go dependencies to latest"
1815
exec: go
1916
args: ["get", "-u", "./..."]
2017
- name: "Run gofmt to format the code"
2118
exec: gofmt
2219
args: ["-s", "-w", "**/*.go"]
20+
- name: "Go Build (Ensure pulled modules do not break the build)"
21+
exec: go
22+
args: ["build", "-v"]
2323
- name: "Add all changed files during the pre-commit stage"
2424
exec: git
2525
args: ["add", "."]

README.md

+57-33
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ Here's what happens when we use Hookz on Hookz itself:
2020

2121
## Installation
2222

23-
To install hookz, [download the latest release](https://github.com/devops-kung-fu/hookz/releases) , make is executable, rename it to _hookz_ and toss it in your ```/usr/local/bin``` directory for Linux, or on your path for other operating systems.
23+
To install hookz, [download the latest release](https://github.com/devops-kung-fu/hookz/releases) , make is executable, rename it to ```hookz``` and toss it in your ```/usr/local/bin``` directory for Linux, or on your path for other operating systems.
2424

2525
Linux Example:
2626

2727
```bash
28-
sudo chmod +x hookz-2.1.0-linux-amd64
29-
sudo mv hookz-2.1.0-linux-amd64 /usr/local/bin/hookz
28+
sudo chmod +x hookz-2.1.1-linux-amd64
29+
sudo mv hookz-2.1.1-linux-amd64 /usr/local/bin/hookz
3030
```
3131

3232
## Configuration
3333

34-
Hookz uses a configuration file to generate hooks in your local git repository. This file needs to be in the root of your repository and must be named *.hookz.yaml*
34+
Hookz uses a configuration file to generate hooks in your local git repository. This file needs to be in the root of your repository and must be named ```.hookz.yaml```
3535

3636
### Example Configuration
3737

3838
``` yaml
39-
version: 2.1
39+
version: 2.1.1
4040
hooks:
4141
- type: pre-commit
4242
actions:
@@ -59,9 +59,9 @@ hooks:
5959
args: ["-e", "Done!"]
6060
```
6161
62-
Hooks will read this example configuration and create a pre-commit hook and a post-commit hook based on this yaml.
62+
Hooks will read this example configuration and create a ```pre-commit``` hook and a ```post-commit``` hook based on this yaml.
6363

64-
An action with an URL will download the binary from the defined URL and configure the hook to execute the command with the defined arguments before a commit happens.
64+
An action with an ```URL``` will download the binary from the defined URL and configure the hook to execute the command with the defined arguments before a commit happens.
6565

6666
The post-commit in this configuration will execute a command named "dude" with the arguments "Hello World" after a commit has occurred. Note that the _dude_ command must be on your path. If it isn't this post-commit will fail because the command isn't found.
6767

@@ -71,16 +71,16 @@ The following notes apply to the elements in the YAML:
7171

7272
|Attribute|Notes|
7373
|---|---|
74-
|URL|If this exists, then exec and script are ignored. The URL must be a link to an executable binary|
75-
|exec|If this exists then URL and script are ignored|
76-
|script|If this exists then URL, exec, and args are ignored|
77-
|args|Optional in all cases|
74+
|```URL```|If this exists, then exec and script are ignored. The URL must be a link to an executable binary|
75+
|```exec```|If this exists then URL and script are ignored|
76+
|```script```|If this exists then URL, exec, and args are ignored|
77+
|```args```|Optional in all cases|
7878

7979
### Inline scripting
8080

81-
Scripts can be embedded into the .hookz.yaml in multiline format such as follows:
81+
Scripts can be embedded into the ```.hookz.yaml``` in multiline format such as follows:
8282

83-
__NOTE:__ There needs to be a \n at the end of a line if a multi-line statement exists in the script: node, and special characters need to be escaped properly.
83+
__NOTE:__ There needs to be a \n at the end of a line if a multi-line statement exists in the ```script``` node, and special characters need to be escaped properly.
8484

8585
``` yaml
8686
- type: pre-commit
@@ -96,35 +96,41 @@ If you have args flags set, they can be referenced as $1, $2, etc. in your scrip
9696

9797
### Support for multiple commands in a hook
9898

99-
If multiple hooks are defined in the configuration with the same type (ie: pre-commit) they will be configured to run in the order they appear in the file. There is no need to group types together, they will be written to the appropriate hooks.
99+
If multiple hooks are defined in the configuration with the same type (ie: ```pre-commit```) they will be configured to run in the order they appear in the file. There is no need to group types together, they will be written to the appropriate hooks.
100100

101101
### Hook types
102102

103103
Hook types that will execute are the same as supported by _git_. Examples are as follows:
104104

105-
* applypatch-msg
106-
* commit-msg
107-
* fsmonitor-watchman
108-
* post-commit
109-
* post-update
110-
* pre-applypatch
111-
* pre-commit
112-
* pre-update
113-
* prepare-commit-msg
114-
* pre-push
115-
* pre-rebase
116-
* pre-receive
117-
* update
105+
* ```applypatch-msg```
106+
* ```commit-msg```
107+
* ```fsmonitor-watchman```
108+
* ```post-commit```
109+
* ```post-update```
110+
* ```pre-applypatch```
111+
* ```pre-commit```
112+
* ```pre-update```
113+
* ```prepare-commit-msg```
114+
* ```pre-push```
115+
* ```pre-rebase```
116+
* ```pre-receive```
117+
* ```update```
118118

119119
### Return Codes
120120

121121
Any non-zero return code from a command executed in a hook will return a FAIL.
122122

123+
### Security
124+
125+
**IMPORTANT:** the ```URL``` element will download a binary, store it in your .git/hookz folder and mark it executable. It is important to ensure that **YOU KNOW THE SAFETY** of the executable that you are downloading. A more secure way is to use the ```exec``` attribute to run an application which is already locally installed, or embed a script in the ```script``` element to download and check the ```shasum``` of the file.
126+
127+
For additional security notes, view the [SECURITY.md](SECURITY.md)
128+
123129
## Running Hookz
124130

125131
![](img/hookz.png)
126132

127-
To generate the hooks as defined in your configuration simply execute the following command in the _root of your local repository_ where the .hookz.yaml file resides:
133+
To generate the hooks as defined in your configuration simply execute the following command in the _root of your local repository_ where the ```.hookz.yaml``` file resides:
128134

129135
``` bash
130136
hookz initialize # you can also use the init alias
@@ -143,26 +149,28 @@ hookz update
143149
```
144150

145151
### Applying changes to the .hookz.yaml
146-
If there is a modification to the .hookz.yaml file in your application, you'll need to apply the changes using the following:
152+
If there is a modification to the ```.hookz.yaml``` file in your application, you'll need to apply the changes using the following:
147153

148154
``` bash
149155
hookz reset
150156
```
151157

152158
### Verbose option
153159

154-
The initialize (init) and reset command optionally take a verbosity flag to indicate extended output should be displayed when a hook executes. This is handy for debugging or seeing errors that may be suppressed by hookz.
160+
The ```initialize``` (init) and ```reset``` command optionally take a verbosity flag to indicate extended output should be displayed when a hook executes. This is handy for debugging or seeing errors that may be suppressed by hookz.
155161

156162
```
157163
hookz init --verbose
158164
hookz reset --verbose
159165
```
166+
167+
160168
## Example Hooks
161169
162170
### Recursively tidy all go.mod files in subdirectories
163171
164172
```yaml
165-
version: 2.1.0
173+
version: 2.1.1
166174
hooks:
167175
- type: pre-commit
168176
actions:
@@ -176,7 +184,7 @@ hooks:
176184
### Update all go modules to the latest version before committing
177185

178186
```yaml
179-
version: 2.1.0
187+
version: 2.1.1
180188
hooks:
181189
- type: pre-commit
182190
actions:
@@ -188,14 +196,30 @@ hooks:
188196
### Pull from your remote branch before committing
189197
190198
``` yaml
191-
version: 2.1.0
199+
version: 2.1.1
192200
hooks:
193201
- type: pre-commit
194202
actions:
195203
- name: "Git Pre-Commit Pull"
196204
exec: git
197205
args: ["pull"]
198206
```
207+
### Check for open source component vulnerabilities
208+
Requires [Sonatype Nancy](https://ossindex.sonatype.org/integration/nancy)
209+
210+
__NOTE:__ The ```|| true``` on the end of the command makes the hook always return a success return code. If you want to break the commit on a failure, then remove this directive.
211+
212+
```yaml
213+
version: 2.1.1
214+
hooks:
215+
- type: pre-commit
216+
actions:
217+
- name: Sonatype Nancy
218+
script: "
219+
#!/bin/bash \n
220+
go list -json -m all | nancy sleuth || true \n
221+
"
222+
```
199223

200224
### Terraform Format and Terraform Docs
201225

cmd/init.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,13 @@ fi
112112
113113
# This file was generated by Hookz
114114
# For more information, check out https://github.com/devops-kung-fu/hookz
115-
# Built because Python sucks by The DevOps Kung Fu Masters (https://dkf.wtf)
116-
117115
118116
reset='\033[0m' # Text Reset
119117
red='\033[41m' # Red
120118
green='\033[42m' # Green
121119
122120
blackText='\033[0;30m'
123-
124-
125-
`
121+
`
126122

127123
filename, _ := filepath.Abs(fmt.Sprintf(".git/hooks/%s", hook.Type))
128124
hookzFile, _ := filepath.Abs(fmt.Sprintf(".git/hooks/%s.hookz", hook.Type))

cmd/root.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313
"time"
1414

1515
"github.com/cavaliercoder/grab"
16+
"github.com/gookit/color"
1617
"github.com/spf13/cobra"
1718
"gopkg.in/yaml.v2"
1819
)
1920

2021
var (
2122
//Verbose identifies if extended output should be configured during init and reset
22-
Version = "2.1.0"
23+
Version = "2.1.1"
2324
Verbose bool
2425
rootCmd = &cobra.Command{
2526
Use: "hookz",
@@ -56,17 +57,23 @@ func readConfig() (config Configuration, err error) {
5657
if err != nil {
5758
return
5859
}
60+
61+
if config.Version == "" {
62+
err = errors.New("no configuration version value found in .hookz.yaml")
63+
return
64+
}
65+
5966
// Check version
6067
ver := strings.Split(config.Version, ".")
6168
verMatch := strings.Split(Version, ".")
6269
if fmt.Sprintf("%v.%v", ver[0], ver[1]) != fmt.Sprintf("%v.%v", verMatch[0], verMatch[1]) {
63-
err = errors.New(fmt.Sprintf("Version Mismatch: Expected v%v.%v - Check your .hookz.yaml configuration\n", verMatch[0], verMatch[1]))
70+
err = fmt.Errorf("version mismatch: Expected v%v.%v - Check your .hookz.yaml configuration", verMatch[0], verMatch[1])
6471
}
6572
return
6673
}
6774

6875
func hookzHeader() {
69-
fmt.Println("Hookz")
76+
color.Style{color.FgWhite, color.OpBold}.Println("Hookz")
7077
fmt.Println("https://github.com/devops-kung-fu/hookz")
7178
fmt.Printf("Version: %s\n", Version)
7279
fmt.Println("")

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go 1.16
44

55
require (
66
github.com/cavaliercoder/grab v2.0.0+incompatible
7+
github.com/gookit/color v1.4.2
78
github.com/segmentio/ksuid v1.0.3
89
github.com/spf13/cobra v1.1.3
10+
golang.org/x/sys v0.0.0-20210426080607-c94f62235c83 // indirect
911
gopkg.in/yaml.v2 v2.4.0
1012
)

go.sum

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
3434
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
3535
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
3636
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
37+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3738
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3839
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
3940
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -65,6 +66,8 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
6566
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
6667
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
6768
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
69+
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
70+
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
6871
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
6972
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
7073
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
@@ -127,6 +130,7 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
127130
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
128131
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
129132
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
133+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
130134
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
131135
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
132136
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
@@ -164,9 +168,13 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
164168
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
165169
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
166170
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
171+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
172+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
167173
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
168174
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
169175
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
176+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
177+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
170178
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
171179
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
172180
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
@@ -231,6 +239,9 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
231239
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
232240
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
233241
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
242+
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
243+
golang.org/x/sys v0.0.0-20210426080607-c94f62235c83 h1:kHSDPqCtsHZOg0nVylfTo20DDhE9gG4Y0jn7hKQ0QAM=
244+
golang.org/x/sys v0.0.0-20210426080607-c94f62235c83/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
234245
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
235246
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
236247
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@@ -287,6 +298,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
287298
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
288299
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
289300
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
301+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
302+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
290303
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
291304
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
292305
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 commit comments

Comments
 (0)