-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.go
85 lines (73 loc) · 2.12 KB
/
whitelist.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
package main
import (
"net/url"
"github.com/fatih/color"
"github.com/rodaine/table"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
var whitelistCmd = &cobra.Command{
Use: "whitelist",
Short: "Manage the whitelist",
}
// https://docs.trustar.co/api/v13/indicators/get_whitelist.html
var whitelistListCmd = &cobra.Command{
Use: "list",
Short: "List items in the whitelist",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
query := url.Values{}
pageNumber := 0
headerFmt := color.New(color.FgCyan, color.Underline).SprintfFunc()
columnFmt := color.New(color.FgYellow).SprintfFunc()
tbl := table.New("type", "value")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
begin:
query.Add("pageNumber", string(pageNumber))
whitelist, err := c.GetWhitelist(nil)
if err != nil {
log.Fatal().Err(err).Msg("error while getting whitelist")
}
for _, e := range whitelist.Items {
tbl.AddRow(e.IndicatorType, e.Value)
}
if whitelist.HasNext {
pageNumber++
goto begin
}
tbl.Print()
},
}
// https://docs.trustar.co/api/v13/indicators/add_to_whitelist.html
var whitelistAddCmd = &cobra.Command{
Use: "add <indicator>...",
Short: "Add items to the whitelist",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
err := c.WhitelistIndicators(args)
if err != nil {
log.Fatal().Err(err).Msg("error while adding to whitelist")
}
},
}
// https://docs.trustar.co/api/v13/indicators/delete_from_whitelist.html
var whitelistDeleteCmd = &cobra.Command{
Use: "delete <indicator>...",
Short: "Delete items from the whitelist",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if config.whitelistDelete.indicatorType == "" {
log.Fatal().Msg("indicator type not specified")
}
for _, a := range args {
// delete indicator from the whitelist
query := url.Values{}
query.Add("indicatorType", config.whitelistDelete.indicatorType)
query.Add("value", a)
err := c.DeleteFromWhitelist(query)
if err != nil {
log.Fatal().Err(err).Msg("error while adding to whitelist")
}
}
},
}