-
Notifications
You must be signed in to change notification settings - Fork 2
/
auditreport.go
81 lines (71 loc) · 1.62 KB
/
auditreport.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
package gitsearch
import (
"bytes"
"encoding/json"
"fmt"
"log"
"sync"
)
//AuditReport contains reporting fields to be
type AuditReport struct {
RuleName string `json:"rulename"`
Rule string `json:"rule"`
Branch string `json:"branch"`
Hash string `json:"hash"`
Time string `json:"time"`
Committer string `json:"committer"`
FilePath string `json:"file"`
Match string `json:"match"`
}
// SafeCounter is safe to use concurrently.
type SafeCounter struct {
branch string
noOfViolations int
mux sync.Mutex
}
// Inc increments the number of Violations
func (c *SafeCounter) Inc() {
c.mux.Lock()
c.noOfViolations++
c.mux.Unlock()
}
// GetViolationCount returns the no of Violations
func (c *SafeCounter) GetViolationCount() int {
c.mux.Lock()
defer c.mux.Unlock()
return c.noOfViolations
}
// Reset resets the safe values
func (c *SafeCounter) Reset() {
c.mux.Lock()
defer c.mux.Unlock()
c.noOfViolations = 0
}
//print prints the output
func (report *AuditReport) print() {
if jsonOutput {
data, err := json.Marshal(*report)
if err != nil {
log.Println("JSON Marshal error: ", err)
return
}
var prettyJSON bytes.Buffer
error := json.Indent(&prettyJSON, data, "", "\t")
if error != nil {
log.Println("JSON parse error: ", error)
return
}
fmt.Println(prettyJSON.String())
} else {
fmt.Println(
"RuleName:", report.RuleName,
"\nRule\t:", report.Rule,
"\nBranch\t:", report.Branch,
"\nHash\t:", report.Hash,
"\nTime\t:", report.Time,
"\nCommiter:", report.Committer,
"\nFile\t:", report.FilePath,
"\nMatch\t:", report.Match,
"\n ")
}
}