cf

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const CallsPerSecondLimit uint32 = 4

Variables

View Source
var CloudflareActionByDecisionType = map[string]string{
	"captcha":      "managed_challenge",
	"ban":          "block",
	"js_challenge": "js_challenge",
}
View Source
var ResponseTime prometheus.Histogram = promauto.NewHistogram(prometheus.HistogramOpts{
	Name:    "response_time",
	Help:    "response time by cloudflare",
	Buckets: prometheus.LinearBuckets(0, 100, 50),
},
)
View Source
var TotalAPICalls prometheus.Counter = promauto.NewCounter(prometheus.CounterOpts{
	Name: "cloudflare_api_calls",
	Help: "The total number of API calls to cloudflare made by CrowdSec bouncer",
},
)

Functions

func NewCloudflareClient

func NewCloudflareClient(token string, logger *log.Logger) (*cloudflare.API, error)

Types

type CloudflareState

type CloudflareState struct {
	Action              string
	AccountID           string
	FilterIDByZoneID    map[string]string // this contains all the zone ID -> filter ID which represent this state
	CurrExpr            string
	IPListState         IPListState
	CountrySet          map[string]struct{}
	AutonomousSystemSet map[string]struct{}
}

one firewall rule per state.

func (*CloudflareState) UpdateExpr

func (cfState *CloudflareState) UpdateExpr() bool

updates the expression for the state. Returns true if new rule is different than the previous rule.

type CloudflareWorker

type CloudflareWorker struct {
	Logger                  *log.Entry
	APILogger               *log.Logger
	Account                 cfg.AccountConfig
	ZoneLocks               []ZoneLock
	Zones                   []cloudflare.Zone
	FirewallRulesByZoneID   map[string]*[]cloudflare.FirewallRule
	CFStateByAction         map[string]*CloudflareState
	Ctx                     context.Context
	LAPIStream              chan *models.DecisionsStreamResponse
	UpdateFrequency         time.Duration
	NewIPDecisions          []*models.Decision
	ExpiredIPDecisions      []*models.Decision
	NewASDecisions          []*models.Decision
	ExpiredASDecisions      []*models.Decision
	NewCountryDecisions     []*models.Decision
	ExpiredCountryDecisions []*models.Decision
	API                     cloudflareAPI
	Count                   prometheus.Counter
	TokenCallCount          *uint32
}

func (*CloudflareWorker) CollectLAPIStream

func (worker *CloudflareWorker) CollectLAPIStream(streamDecision *models.DecisionsStreamResponse)

func (*CloudflareWorker) DeleteASBans

func (worker *CloudflareWorker) DeleteASBans() error

func (*CloudflareWorker) DeleteCountryBans

func (worker *CloudflareWorker) DeleteCountryBans() error

func (*CloudflareWorker) DeleteExistingIPList

func (worker *CloudflareWorker) DeleteExistingIPList() error

func (*CloudflareWorker) Init

func (worker *CloudflareWorker) Init() error

func (*CloudflareWorker) Run

func (worker *CloudflareWorker) Run() error

func (*CloudflareWorker) SendASBans

func (worker *CloudflareWorker) SendASBans() error

func (*CloudflareWorker) SendCountryBans

func (worker *CloudflareWorker) SendCountryBans() error

func (*CloudflareWorker) SetUpCloudflareResources

func (worker *CloudflareWorker) SetUpCloudflareResources() error

func (*CloudflareWorker) UpdateIPLists

func (worker *CloudflareWorker) UpdateIPLists() error

func (*CloudflareWorker) UpdateRules

func (worker *CloudflareWorker) UpdateRules() error

type IPListState

type IPListState struct {
	IPList *cloudflare.IPList
	IPSet  map[string]IPSetItem `json:"-"`
}

type IPSetItem

type IPSetItem struct {
	CreatedAt time.Time
}

type InterceptLogger

type InterceptLogger struct {
	Tripper http.RoundTripper
	// contains filtered or unexported fields
}

func (InterceptLogger) RoundTrip

func (lrt InterceptLogger) RoundTrip(req *http.Request) (*http.Response, error)

type ZoneLock

type ZoneLock struct {
	Lock   *sync.Mutex
	ZoneID string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL