-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (73 loc) · 1.69 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"flag"
"fmt"
"os"
"github.com/AvineshTripathi/cred/analyze"
"github.com/AvineshTripathi/cred/scan"
"github.com/AvineshTripathi/cred/utils"
"github.com/go-git/go-git/v5"
)
func main() {
var input1 string // to store inputs AKIA3XWNRUIJEF25GO7S
// convert this to struct
fmt.Println("Enter the repo Url: ")
fmt.Scanln(&input1)
nums := flag.Int("commits", 0, "Number of commits you want to check in")
flag.Parse()
// store results of the scan, convert this to struct
var idRepo [][][]string
var idCommit [][][]string
var keyRepo [][][]string
var keyCommit [][][]string
f, err := os.MkdirTemp(os.TempDir(), "cred")
if err != nil {
fmt.Println(err)
}
defer os.RemoveAll(f)
r, err := git.PlainClone(f, false, &git.CloneOptions{
URL: input1,
})
if err != nil {
fmt.Println(err)
}
fmt.Println("Do you want a latest repo scan(1) or commit scan(2)?")
fmt.Scanln(&input1)
// this will scan the entire commit history
if input1 == "2" {
commitIt, err := r.CommitObjects()
if err != nil {
fmt.Println(err)
}
fmt.Println(*nums)
idCommit, keyCommit, err = scan.ReadCommits(commitIt, *nums)
if err != nil {
fmt.Println(err)
}
for _, i := range idCommit {
for _, j := range keyCommit {
t, err := analyze.Validate(i, j)
if err != nil {
fmt.Println(err)
}
utils.Printer(t)
}
}
}
// this will scan the latest code cloned temp in local
if input1 == "1" {
idRepo, keyRepo, err = scan.ReadRepo(f)
if err != nil {
fmt.Println(err)
}
for _, i := range idRepo {
for _, j := range keyRepo {
t, err := analyze.Validate(i, j)
if err != nil {
fmt.Println(err)
}
utils.Printer(t)
}
}
}
}