-
Notifications
You must be signed in to change notification settings - Fork 22
/
hound.go
73 lines (65 loc) · 1.71 KB
/
hound.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
package hunter
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/brittonhayes/pillager/templates"
"github.com/ghodss/yaml"
"github.com/zricethezav/gitleaks/v7/scan"
)
var _ Hounder = &Hound{}
// The Hounder interface defines the available methods
// for instances of the Hound type
type Hounder interface {
Howl(findings scan.Report)
}
// A Hound performs the file inspection and returns the results
type Hound struct {
Config *Config
Findings scan.Report `json:"findings"`
}
// NewHound creates an instance of the Hound type
func NewHound(c *Config) *Hound {
if c == nil {
var config Config
return &Hound{config.Default(), scan.Report{}}
}
if c.System == nil {
log.Fatal("Missing filesystem in Hunter Config")
}
return &Hound{c, scan.Report{}}
}
// Howl prints out the Findings from the Hound in the preferred output format
func (h *Hound) Howl(findings scan.Report) {
if h.Config.Template != "" {
h.Config.Format = CustomFormat
}
switch h.Config.Format {
case JSONFormat:
b, err := json.Marshal(&findings.Leaks)
if err != nil {
log.Fatal("Failed to unmarshal findings")
}
fmt.Println(string(b))
case YAMLFormat:
b, err := yaml.Marshal(&findings.Leaks)
if err != nil {
fmt.Printf("err: %v\n", err)
return
}
fmt.Println(string(b))
case HTMLFormat:
RenderTemplate(os.Stdout, templates.HTML, findings)
case HTMLTableFormat:
RenderTemplate(os.Stdout, templates.HTMLTable, findings)
case MarkdownFormat:
RenderTemplate(os.Stdout, templates.Markdown, findings)
case TableFormat:
RenderTemplate(os.Stdout, templates.Table, findings)
case CustomFormat:
RenderTemplate(os.Stdout, h.Config.Template, findings)
default:
RenderTemplate(os.Stdout, templates.Simple, findings)
}
}