Skip to content

Commit 1e248d6

Browse files
committed
feat: gitleaks as pre commit
1 parent 66dc791 commit 1e248d6

File tree

4 files changed

+83
-30
lines changed

4 files changed

+83
-30
lines changed

.githooks/pre-commit

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
os=$(uname -s | tr '[:upper:]' '[:lower:]')
4+
arch=$(uname -m)
5+
6+
# Keep if gitleaks is installed with curl (binary will be deleted)
7+
installed=false
8+
# Check if gitleaks is installed
9+
if ! command -v gitleaks &> /dev/null; then
10+
echo "Gitleaks not found. Installing..."
11+
12+
# Get latest release tag
13+
latest_version=$(curl -k -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest | grep '"tag_name":' | cut -d '"' -f 4)
14+
15+
# Construct download URL (for Linux x86_64)
16+
url="https://github.com/gitleaks/gitleaks/releases/download/$latest_version/gitleaks_${latest_version#v}_${os}_${arch}.tar.gz"
17+
18+
# Download and extract
19+
curl -k -L "$url" -o gitleaks.tar.gz
20+
tar -xzf gitleaks.tar.gz gitleaks
21+
chmod +x gitleaks
22+
rm gitleaks.tar.gz
23+
24+
echo "Gitleaks installed successfully."
25+
installed=true
26+
else
27+
echo "Gitleaks is already installed."
28+
fi
29+
30+
#Manually Gitleaks binary should be removed
31+
if $installed; then
32+
# Run gitleaks in the current directory
33+
echo "Running gitleaks in current directory..."
34+
./gitleaks detect --source . --report-path gitleaks_report.json --no-git
35+
36+
echo "Scan complete. Report saved to gitleaks_report.json"
37+
echo "Removing Gitleaks binary"
38+
rm ./gitleaks
39+
40+
else
41+
echo "Running gitleaks in current directory..."
42+
gitleaks detect --source . --report-path gitleaks_report.json --no-git
43+
44+
echo "Scan complete. Report saved to gitleaks_report.json"
45+
fi

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
# vendor/
1717

1818
.idea
19-
test/integration/hosts
19+
test/integration/hosts
20+
gitleaks_report.json

.gitleaksignore

Whitespace-only changes.

README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,42 @@ by looking at our [docs](docs/index.md).
2727
package main
2828

2929
import (
30-
"github.com/Trendyol/go-dcp"
31-
"github.com/Trendyol/go-dcp/logger"
32-
"github.com/Trendyol/go-dcp/models"
30+
"github.com/Trendyol/go-dcp"
31+
"github.com/Trendyol/go-dcp/logger"
32+
"github.com/Trendyol/go-dcp/models"
3333
)
3434

3535
func listener(ctx *models.ListenerContext) {
36-
switch event := ctx.Event.(type) {
37-
case models.DcpMutation:
38-
logger.Log.Info(
39-
"mutated(vb=%v,eventTime=%v) | id: %v, value: %v | isCreated: %v",
40-
event.VbID, event.EventTime, string(event.Key), string(event.Value), event.IsCreated(),
41-
)
42-
case models.DcpDeletion:
43-
logger.Log.Info(
44-
"deleted(vb=%v,eventTime=%v) | id: %v",
45-
event.VbID, event.EventTime, string(event.Key),
46-
)
47-
case models.DcpExpiration:
48-
logger.Log.Info(
49-
"expired(vb=%v,eventTime=%v) | id: %v",
50-
event.VbID, event.EventTime, string(event.Key),
51-
)
52-
}
53-
54-
ctx.Ack()
36+
switch event := ctx.Event.(type) {
37+
case models.DcpMutation:
38+
logger.Log.Info(
39+
"mutated(vb=%v,eventTime=%v) | id: %v, value: %v | isCreated: %v",
40+
event.VbID, event.EventTime, string(event.Key), string(event.Value), event.IsCreated(),
41+
)
42+
case models.DcpDeletion:
43+
logger.Log.Info(
44+
"deleted(vb=%v,eventTime=%v) | id: %v",
45+
event.VbID, event.EventTime, string(event.Key),
46+
)
47+
case models.DcpExpiration:
48+
logger.Log.Info(
49+
"expired(vb=%v,eventTime=%v) | id: %v",
50+
event.VbID, event.EventTime, string(event.Key),
51+
)
52+
}
53+
54+
ctx.Ack()
5555
}
5656

5757
func main() {
58-
connector, err := dcp.NewDcp("config.yml", listener)
59-
if err != nil {
60-
panic(err)
61-
}
58+
connector, err := dcp.NewDcp("config.yml", listener)
59+
if err != nil {
60+
panic(err)
61+
}
6262

63-
defer connector.Close()
63+
defer connector.Close()
6464

65-
connector.Start()
65+
connector.Start()
6666
}
6767
```
6868

@@ -205,4 +205,11 @@ In case you haven't configured a metric.path, the metrics will be exposed at the
205205

206206
## Distributed Tracing
207207

208-
[otel-go-dcp](https://github.com/Trendyol/otel-go-dcp)
208+
[otel-go-dcp](https://github.com/Trendyol/otel-go-dcp)
209+
210+
## Before Contribution
211+
212+
```
213+
# Make sure to use .githooks as hooks path of your git
214+
git config core.hooksPath .githooks
215+
```

0 commit comments

Comments
 (0)