File: main.go

package info (click to toggle)
golang-github-crowdsecurity-go-cs-bouncer 0.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 940 kB
  • sloc: makefile: 4
file content (40 lines) | stat: -rw-r--r-- 938 bytes parent folder | download
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
package main

import (
	"fmt"
	"log"

	csbouncer "github.com/crowdsecurity/go-cs-bouncer"
)

func boolPtr(x bool) *bool {
	return &x
}

func main() {

	bouncer := &csbouncer.LiveBouncer{
		APIUrl:             "https://localhost:8081/",
		CertPath:           "/home/seb/cfssl/bouncer.pem",
		KeyPath:            "/home/seb/cfssl/bouncer-key.pem",
		CAPath:             "/home/seb/cfssl/ca.pem",
		InsecureSkipVerify: boolPtr(true),
	}

	if err := bouncer.Init(); err != nil {
		log.Fatalf(err.Error())
	}

	ipToQuery := "1.2.3.4"
	response, err := bouncer.Get(ipToQuery)
	if err != nil {
		log.Fatalf("unable to get decision for ip '%s' : '%s'", ipToQuery, err)
	}
	if len(*response) == 0 {
		log.Printf("no decision for '%s'", ipToQuery)
	}

	for _, decision := range *response {
		fmt.Printf("decisions: IP: %s | Scenario: %s | Duration: %s | Scope : %v\n", *decision.Value, *decision.Scenario, *decision.Duration, *decision.Scope)
	}
}