This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
/
report.go
63 lines (51 loc) · 1.67 KB
/
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
60
61
62
63
package cmd
import (
"os"
"strconv"
"github.com/chanzuckerberg/reaper/pkg/runner"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
addCommonFlags(reportCmd)
rootCmd.AddCommand(reportCmd)
}
// reportCmd represents the report command
var reportCmd = &cobra.Command{
Use: "report",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := getConfig(cmd)
if err != nil {
return errors.Wrap(err, "could not read config")
}
valid := validateConfigVersion(conf.Version, validConfigVersions)
if !valid {
return errors.Errorf("invalid config version: %d. Valid options are %v", conf.Version, validConfigVersions)
}
only, err := cmd.Flags().GetStringArray(onlyFlag)
if err != nil {
return errors.Wrap(err, "error reading the `only` flag")
}
runner := runner.New(conf)
violations, err := runner.Run(only)
if err != nil {
return err
}
log.Info("VIOLATIONS")
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Entity", "Policy", "owner", "Account ID", "Account Name", "Region"})
for _, v := range violations {
table.Append([]string{v.Subject.GetID(), v.Policy.Name, v.Subject.GetOwner(), strconv.FormatInt(v.AccountID, 10), v.AccountName, v.Subject.GetRegion()})
}
table.Render()
return nil
},
}