fix cscti, leave only smokeip
This commit is contained in:
parent
764bef719b
commit
3cb4a4c8d1
4 changed files with 7 additions and 131 deletions
|
@ -1,65 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/cti"
|
||||
)
|
||||
|
||||
type cliFire struct {}
|
||||
|
||||
func NewCLIFire() *cliFire {
|
||||
return &cliFire{}
|
||||
}
|
||||
|
||||
var ErrorNoAPIKey = errors.New("CTI_API_KEY is not set")
|
||||
|
||||
func (cli *cliFire) fire() error {
|
||||
// check if CTI_API_KEY is set
|
||||
apiKey := os.Getenv("CTI_API_KEY")
|
||||
if apiKey == "" {
|
||||
return ErrorNoAPIKey
|
||||
}
|
||||
|
||||
// create a new CTI client
|
||||
client, err := cti.NewClientWithResponses("https://cti.api.crowdsec.net/v2/", cti.WithRequestEditorFn(cti.APIKeyInserter(apiKey)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
resp, err := client.GetFireWithResponse(ctx, &cti.GetFireParams{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.JSON200 != nil {
|
||||
out, err := json.MarshalIndent(resp.JSON200, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *cliFire) NewCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "fire",
|
||||
Short: "Query the fire data",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cli.fire()
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
|
@ -22,7 +22,7 @@ func main() {
|
|||
cmd := &cobra.Command{
|
||||
Use: "cscti",
|
||||
Short: "cscti is a tool to query the CrowdSec CTI",
|
||||
ValidArgs: []string{"fire", "smoke", "smoke-ip"},
|
||||
ValidArgs: []string{"smoke-ip"},
|
||||
DisableAutoGenTag: true,
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,6 @@ func main() {
|
|||
|
||||
pflags.StringVarP(&configPath, "config", "c", "", "Path to the configuration file")
|
||||
|
||||
cmd.AddCommand(NewCLIFire().NewCommand())
|
||||
cmd.AddCommand(NewCLISmoke().NewCommand())
|
||||
cmd.AddCommand(NewCLISmokeIP().NewCommand())
|
||||
|
||||
if err := cmd.Execute(); err != nil {
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/cti"
|
||||
)
|
||||
|
||||
type cliSmoke struct {}
|
||||
|
||||
func NewCLISmoke() *cliSmoke {
|
||||
return &cliSmoke{}
|
||||
}
|
||||
|
||||
func (cli *cliSmoke) smoke() error {
|
||||
// check if CTI_API_KEY is set
|
||||
apiKey := os.Getenv("CTI_API_KEY")
|
||||
if apiKey == "" {
|
||||
return ErrorNoAPIKey
|
||||
}
|
||||
|
||||
// create a new CTI client
|
||||
client, err := cti.NewClientWithResponses("https://cti.api.crowdsec.net/v2/", cti.WithRequestEditorFn(cti.APIKeyInserter(apiKey)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
resp, err := client.GetSmokeWithResponse(ctx, &cti.GetSmokeParams{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.JSON200 != nil {
|
||||
out, err := json.MarshalIndent(resp.JSON200, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *cliSmoke) NewCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "smoke",
|
||||
Short: "Query the smoke data",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cli.smoke()
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
|
@ -25,8 +25,13 @@ func (cli *cliSmokeIP) smokeip(ip string) error {
|
|||
return ErrorNoAPIKey
|
||||
}
|
||||
|
||||
provider, err := cti.NewAPIKeyProvider(apiKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create a new CTI client
|
||||
client, err := cti.NewClientWithResponses("https://cti.api.crowdsec.net/v2/", cti.WithRequestEditorFn(cti.APIKeyInserter(apiKey)))
|
||||
client, err := cti.NewClientWithResponses("https://cti.api.crowdsec.net/v2/", cti.WithRequestEditorFn(provider.Intercept))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue