summaryrefslogtreecommitdiffstats
path: root/cmd/breachforum.go
blob: 229292a9956faa267f96daaea8fd3d5d029b143c (plain)
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
package cmd

import (
	"git.db.org.ai/dborg/internal/formatter"
	"git.db.org.ai/dborg/internal/models"
	"github.com/spf13/cobra"
)

var breachforumCmd = &cobra.Command{
	Use:     "breachforum [search]",
	Aliases: []string{"brf"},
	Short:   "Search BreachForum data",
	Long:    `Search breachdetect index for BreachForum messages and detections`,
	Args:    argsOrStdin(1),
	RunE:    runBreachForumSearch,
}

func init() {
	rootCmd.AddCommand(breachforumCmd)
	breachforumCmd.Flags().IntP("max_hits", "m", 10, "Maximum number of hits to return")
}

func runBreachForumSearch(cmd *cobra.Command, args []string) error {
	c, err := newUnauthenticatedClient()
	if err != nil {
		return err
	}

	maxHits, _ := cmd.Flags().GetInt("max_hits")

	return forEachQuery(args, func(query string) error {
		params := &models.BreachForumSearchParams{
			Search:  query,
			MaxHits: maxHits,
		}
		response, err := c.SearchBreachForum(params)
		if err != nil {
			return err
		}
		return formatter.FormatBreachForumResults(response, IsJSONOutput())
	})
}