-
Notifications
You must be signed in to change notification settings - Fork 197
/
get_report.go
59 lines (51 loc) · 1.72 KB
/
get_report.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
package cmd
import (
"fmt"
"os"
vulnsCrd "github.com/aquasecurity/starboard/pkg/find/vulnerabilities/crd"
clientset "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
configAuditCrd "github.com/aquasecurity/starboard/pkg/polaris/crd"
"github.com/aquasecurity/starboard/pkg/report"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
func NewGetReportCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "report (NAME | TYPE/NAME)",
Short: "Get a full html security report for a specified workload",
Long: `Generates a report that contains vulnerabilities and config audits found for the specified workload
TYPE is a Kubernetes workload. Shortcuts and API groups will be resolved, e.g. 'po' or 'deployments.apps'.
NAME is the name of a particular Kubernetes workload.
`,
Example: fmt.Sprintf(` # Save report to a file
%[1]s get report deploy/nginx > report.html`, "starboard"),
RunE: func(cmd *cobra.Command, args []string) (err error) {
config, err := cf.ToRESTConfig()
if err != nil {
return
}
starboardClientset, err := clientset.NewForConfig(config)
if err != nil {
return
}
ns, _, err := cf.ToRawKubeConfigLoader().Namespace()
if err != nil {
return
}
mapper, err := cf.ToRESTMapper()
if err != nil {
return
}
workload, _, err := WorkloadFromArgs(mapper, ns, args)
if err != nil {
return
}
caReader := configAuditCrd.NewReadWriter(GetScheme(), starboardClientset)
vulnsReader := vulnsCrd.NewReadWriter(GetScheme(), starboardClientset)
reporter := report.NewHTMLReporter(caReader, vulnsReader, workload)
err = reporter.GenerateReport(os.Stdout)
return
},
}
return cmd
}