summaryrefslogtreecommitdiffstats
path: root/cmd/breachforum.go
blob: 366092cfd9da4c3fc60400a53506284770053328 (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
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]",
	Short: "Search BreachForum data",
	Long:  `Search breachdetect index for BreachForum messages and detections`,
	Args:  cobra.ExactArgs(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
	}

	params := &models.BreachForumSearchParams{
		Search: args[0],
	}
	params.MaxHits, _ = cmd.Flags().GetInt("max_hits")

	response, err := c.SearchBreachForum(params)
	if err != nil {
		return err
	}

	return formatter.FormatBreachForumResults(response, IsJSONOutput())
}