Skip to content

Commit 5d30718

Browse files
Set maximum of goroutines
1 parent 8a18733 commit 5d30718

70 files changed

Lines changed: 7146 additions & 7161 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/check_new_rules.go

Lines changed: 127 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
1-
// Scripts to check if all the rules that exist in the latest version of "gitleaks" are included in our list of rules (in secret.go file)
2-
package main
3-
4-
import (
5-
"encoding/json"
6-
"fmt"
7-
"io"
8-
"net/http"
9-
"os"
10-
"regexp"
11-
)
12-
13-
var (
14-
regexGitleaksRules = regexp.MustCompile(`(?m)^[^/\n\r]\s*rules\.([a-zA-Z0-9_]+)\(`)
15-
regex2msRules = regexp.MustCompile(`(?m)^[^/\n\r]\s*(?:// )?{Rule:\s*\*(?:rules\.)?([a-zA-Z0-9_]+)\(\),`)
16-
)
17-
18-
func main() {
19-
20-
latestGitleaksRelease, err := fetchGitleaksLatestRelease()
21-
if err != nil {
22-
fmt.Printf("%s\n", err)
23-
os.Exit(1)
24-
}
25-
fmt.Printf("Latest Gitleaks release: %s\n", latestGitleaksRelease)
26-
27-
gitleaksRules, err := fetchGitleaksRules(latestGitleaksRelease)
28-
if err != nil {
29-
fmt.Printf("%s\n", err)
30-
os.Exit(1)
31-
}
32-
33-
matchesGitleaksRules := regexGitleaksRules.FindAllStringSubmatch(string(gitleaksRules), -1)
34-
if len(matchesGitleaksRules) == 0 {
35-
fmt.Println("No rules found in the latest version of Gitleaks.")
36-
os.Exit(1)
37-
}
38-
fmt.Printf("Total rules in the latest version of Gitleaks: %d\n", len(matchesGitleaksRules))
39-
40-
ourRules, err := fetchOurRules()
41-
if err != nil {
42-
fmt.Printf("%s\n", err)
43-
os.Exit(1)
44-
}
45-
match2msRules := regex2msRules.FindAllStringSubmatch(string(ourRules), -1)
46-
if len(match2msRules) == 0 {
47-
fmt.Println("No rules found in 2ms.")
48-
os.Exit(1)
49-
}
50-
fmt.Printf("Total rules in 2ms: %d\n", len(match2msRules))
51-
52-
map2msRules := make(map[string]bool)
53-
for _, match := range match2msRules {
54-
map2msRules[match[1]] = true
55-
}
56-
57-
missingRulesIn2ms := []string{}
58-
for _, rule := range matchesGitleaksRules {
59-
if _, found := map2msRules[rule[1]]; !found {
60-
missingRulesIn2ms = append(missingRulesIn2ms, rule[1])
61-
}
62-
}
63-
64-
if len(missingRulesIn2ms) > 0 {
65-
fmt.Printf("%d rules exist in the latest version of Gitleaks but missing on 2ms: \n\n", len(missingRulesIn2ms))
66-
for _, rule := range missingRulesIn2ms {
67-
fmt.Printf("%s \n", rule)
68-
}
69-
70-
fmt.Printf("\nLink to Gitleaks main.go file of version: %s:\n", latestGitleaksRelease)
71-
fmt.Println(getGitleaksRulesRawURL(latestGitleaksRelease))
72-
73-
os.Exit(1)
74-
} else {
75-
fmt.Println("No differences found.")
76-
os.Exit(0)
77-
}
78-
}
79-
80-
type Release struct {
81-
TagName string `json:"tag_name"`
82-
}
83-
84-
func fetchGitleaksLatestRelease() (string, error) {
85-
var release Release
86-
87-
response, err := http.Get("https://api.github.com/repos/zricethezav/gitleaks/releases/latest")
88-
if err != nil {
89-
return "", fmt.Errorf("failed to get latest release: %w", err)
90-
}
91-
defer response.Body.Close()
92-
93-
decoder := json.NewDecoder(response.Body)
94-
if err := decoder.Decode(&release); err != nil {
95-
return "", fmt.Errorf("failed to decode latest release JSON: %w", err)
96-
}
97-
98-
return release.TagName, nil
99-
}
100-
101-
func fetchGitleaksRules(version string) ([]byte, error) {
102-
rawURLGitleaksRules := getGitleaksRulesRawURL(version)
103-
response, err := http.Get(rawURLGitleaksRules)
104-
if err != nil {
105-
return nil, fmt.Errorf("failed to fetch remote file: %w", err)
106-
}
107-
defer response.Body.Close()
108-
109-
content, err := io.ReadAll(response.Body)
110-
if err != nil {
111-
return nil, fmt.Errorf("failed to read remote file content: %w", err)
112-
}
113-
114-
return content, nil
115-
}
116-
117-
func getGitleaksRulesRawURL(version string) string {
118-
return fmt.Sprintf("https://raw.githubusercontent.com/zricethezav/gitleaks/%s/cmd/generate/config/main.go", version)
119-
}
120-
121-
func fetchOurRules() ([]byte, error) {
122-
content, err := os.ReadFile("engine/rules/rules.go")
123-
if err != nil {
124-
return nil, fmt.Errorf("failed to read our file content: %w", err)
125-
}
126-
return content, nil
127-
}
1+
// Scripts to check if all the rules that exist in the latest version of "gitleaks" are included in our list of rules (in secret.go file)
2+
package main
3+
4+
import (
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
"os"
10+
"regexp"
11+
)
12+
13+
var (
14+
regexGitleaksRules = regexp.MustCompile(`(?m)^[^/\n\r]\s*rules\.([a-zA-Z0-9_]+)\(`)
15+
regex2msRules = regexp.MustCompile(`(?m)^[^/\n\r]\s*(?:// )?{Rule:\s*\*(?:rules\.)?([a-zA-Z0-9_]+)\(\),`)
16+
)
17+
18+
func main() {
19+
20+
latestGitleaksRelease, err := fetchGitleaksLatestRelease()
21+
if err != nil {
22+
fmt.Printf("%s\n", err)
23+
os.Exit(1)
24+
}
25+
fmt.Printf("Latest Gitleaks release: %s\n", latestGitleaksRelease)
26+
27+
gitleaksRules, err := fetchGitleaksRules(latestGitleaksRelease)
28+
if err != nil {
29+
fmt.Printf("%s\n", err)
30+
os.Exit(1)
31+
}
32+
33+
matchesGitleaksRules := regexGitleaksRules.FindAllStringSubmatch(string(gitleaksRules), -1)
34+
if len(matchesGitleaksRules) == 0 {
35+
fmt.Println("No rules found in the latest version of Gitleaks.")
36+
os.Exit(1)
37+
}
38+
fmt.Printf("Total rules in the latest version of Gitleaks: %d\n", len(matchesGitleaksRules))
39+
40+
ourRules, err := fetchOurRules()
41+
if err != nil {
42+
fmt.Printf("%s\n", err)
43+
os.Exit(1)
44+
}
45+
match2msRules := regex2msRules.FindAllStringSubmatch(string(ourRules), -1)
46+
if len(match2msRules) == 0 {
47+
fmt.Println("No rules found in 2ms.")
48+
os.Exit(1)
49+
}
50+
fmt.Printf("Total rules in 2ms: %d\n", len(match2msRules))
51+
52+
map2msRules := make(map[string]bool)
53+
for _, match := range match2msRules {
54+
map2msRules[match[1]] = true
55+
}
56+
57+
missingRulesIn2ms := []string{}
58+
for _, rule := range matchesGitleaksRules {
59+
if _, found := map2msRules[rule[1]]; !found {
60+
missingRulesIn2ms = append(missingRulesIn2ms, rule[1])
61+
}
62+
}
63+
64+
if len(missingRulesIn2ms) > 0 {
65+
fmt.Printf("%d rules exist in the latest version of Gitleaks but missing on 2ms: \n\n", len(missingRulesIn2ms))
66+
for _, rule := range missingRulesIn2ms {
67+
fmt.Printf("%s \n", rule)
68+
}
69+
70+
fmt.Printf("\nLink to Gitleaks main.go file of version: %s:\n", latestGitleaksRelease)
71+
fmt.Println(getGitleaksRulesRawURL(latestGitleaksRelease))
72+
73+
os.Exit(1)
74+
} else {
75+
fmt.Println("No differences found.")
76+
os.Exit(0)
77+
}
78+
}
79+
80+
type Release struct {
81+
TagName string `json:"tag_name"`
82+
}
83+
84+
func fetchGitleaksLatestRelease() (string, error) {
85+
var release Release
86+
87+
response, err := http.Get("https://api.github.com/repos/zricethezav/gitleaks/releases/latest")
88+
if err != nil {
89+
return "", fmt.Errorf("failed to get latest release: %w", err)
90+
}
91+
defer response.Body.Close()
92+
93+
decoder := json.NewDecoder(response.Body)
94+
if err := decoder.Decode(&release); err != nil {
95+
return "", fmt.Errorf("failed to decode latest release JSON: %w", err)
96+
}
97+
98+
return release.TagName, nil
99+
}
100+
101+
func fetchGitleaksRules(version string) ([]byte, error) {
102+
rawURLGitleaksRules := getGitleaksRulesRawURL(version)
103+
response, err := http.Get(rawURLGitleaksRules)
104+
if err != nil {
105+
return nil, fmt.Errorf("failed to fetch remote file: %w", err)
106+
}
107+
defer response.Body.Close()
108+
109+
content, err := io.ReadAll(response.Body)
110+
if err != nil {
111+
return nil, fmt.Errorf("failed to read remote file content: %w", err)
112+
}
113+
114+
return content, nil
115+
}
116+
117+
func getGitleaksRulesRawURL(version string) string {
118+
return fmt.Sprintf("https://raw.githubusercontent.com/zricethezav/gitleaks/%s/cmd/generate/config/main.go", version)
119+
}
120+
121+
func fetchOurRules() ([]byte, error) {
122+
content, err := os.ReadFile("engine/rules/rules.go")
123+
if err != nil {
124+
return nil, fmt.Errorf("failed to read our file content: %w", err)
125+
}
126+
return content, nil
127+
}

.ci/update-readme.sh

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
update_readme() {
2-
output_file=$1
3-
placeholder_name=$2
4-
target_file=$3
5-
6-
sed -i "/<!-- $placeholder_name:start -->/,/<!-- $placeholder_name:end -->/{
7-
/<!-- $placeholder_name:start -->/{
8-
p
9-
r $output_file
10-
}
11-
/<!-- $placeholder_name:end -->/!d
12-
}" $target_file
13-
}
14-
15-
# Update the README with the help message
16-
help_message=$(go run .)
17-
18-
echo "" >output.txt
19-
echo '```text' >>output.txt
20-
echo "$help_message" >>output.txt
21-
echo '```' >>output.txt
22-
echo "" >>output.txt
23-
update_readme "output.txt" "command-line" "README.md"
24-
rm output.txt
25-
26-
go run . rules | awk 'BEGIN{FS = " *"}{print "| " $1 " | " $2 " | " $3 " | " $4 " |";}' >output.txt
27-
update_readme "output.txt" "table" "./docs/list-of-rules.md"
28-
rm output.txt
29-
30-
git --no-pager diff README.md ./docs/list-of-rules.md
1+
update_readme() {
2+
output_file=$1
3+
placeholder_name=$2
4+
target_file=$3
5+
6+
sed -i "/<!-- $placeholder_name:start -->/,/<!-- $placeholder_name:end -->/{
7+
/<!-- $placeholder_name:start -->/{
8+
p
9+
r $output_file
10+
}
11+
/<!-- $placeholder_name:end -->/!d
12+
}" $target_file
13+
}
14+
15+
# Update the README with the help message
16+
help_message=$(go run .)
17+
18+
echo "" >output.txt
19+
echo '```text' >>output.txt
20+
echo "$help_message" >>output.txt
21+
echo '```' >>output.txt
22+
echo "" >>output.txt
23+
update_readme "output.txt" "command-line" "README.md"
24+
rm output.txt
25+
26+
go run . rules | awk 'BEGIN{FS = " *"}{print "| " $1 " | " $2 " | " $3 " | " $4 " |";}' >output.txt
27+
update_readme "output.txt" "table" "./docs/list-of-rules.md"
28+
rm output.txt
29+
30+
git --no-pager diff README.md ./docs/list-of-rules.md

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @Checkmarx/2ms-dev
1+
* @Checkmarx/2ms-dev

.github/pull_request_template.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<!--
2-
Thanks for contributing to 2ms by offering a pull request.
3-
-->
4-
5-
Closes #
6-
7-
**Proposed Changes**
8-
9-
<!--
10-
Please describe the big picture of your changes here. If it fixes a bug or resolves a feature request, be sure to link to that issue.
11-
-->
12-
13-
**Checklist**
14-
15-
- [ ] I covered my changes with tests.
16-
- [ ] I Updated the documentation that is affected by my changes:
17-
- [ ] Change in the CLI arguments
18-
- [ ] Change in the configuration file
19-
20-
I submit this contribution under the Apache-2.0 license.
1+
<!--
2+
Thanks for contributing to 2ms by offering a pull request.
3+
-->
4+
5+
Closes #
6+
7+
**Proposed Changes**
8+
9+
<!--
10+
Please describe the big picture of your changes here. If it fixes a bug or resolves a feature request, be sure to link to that issue.
11+
-->
12+
13+
**Checklist**
14+
15+
- [ ] I covered my changes with tests.
16+
- [ ] I Updated the documentation that is affected by my changes:
17+
- [ ] Change in the CLI arguments
18+
- [ ] Change in the configuration file
19+
20+
I submit this contribution under the Apache-2.0 license.

0 commit comments

Comments
 (0)