database

package
v1.5.30 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const CapiListsMachineID = types.ListOrigin
View Source
const CapiMachineID = types.CAPIOrigin

Variables

View Source
var (
	UserExists        = errors.New("user already exist")
	UserNotExists     = errors.New("user doesn't exist")
	HashError         = errors.New("unable to hash")
	InsertFail        = errors.New("unable to insert row")
	QueryFail         = errors.New("unable to query")
	UpdateFail        = errors.New("unable to update")
	DeleteFail        = errors.New("unable to delete")
	ItemNotFound      = errors.New("object not found")
	ParseTimeFail     = errors.New("unable to parse time")
	ParseDurationFail = errors.New("unable to parse duration")
	MarshalFail       = errors.New("unable to marshal")
	UnmarshalFail     = errors.New("unable to unmarshal")
	BulkError         = errors.New("unable to insert bulk")
	ParseType         = errors.New("unable to parse type")
	InvalidIPOrRange  = errors.New("invalid ip address / range")
	InvalidFilter     = errors.New("invalid filter")
)

Functions

func AlertPredicatesFromFilter

func AlertPredicatesFromFilter(filter map[string][]string) ([]predicate.Alert, error)

func BuildAlertRequestFromFilter

func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error)

func BuildDecisionRequestWithFilter

func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error)

func GetIpsFromIpRange

func GetIpsFromIpRange(host string) (int64, int64, error)

func IP2Int

func IP2Int(ip net.IP) uint32

func Int2ip

func Int2ip(nn uint32) net.IP

func IsIpv4

func IsIpv4(host string) bool

func LastAddress

func LastAddress(n *net.IPNet) net.IP

Stolen from : https://github.com/llimllib/ipaddress/ Return the final address of a net range. Convert to IPv4 if possible, otherwise return an ipv6

Types

type Client

type Client struct {
	Ent      *ent.Client
	CTX      context.Context
	Log      *log.Logger
	CanFlush bool
	Type     string
	WalMode  *bool
}

func NewClient

func NewClient(config *csconfig.DatabaseCfg) (*Client, error)

func (*Client) AlertsCountPerScenario

func (c *Client) AlertsCountPerScenario(filters map[string][]string) (map[string]int, error)

func (*Client) BulkDeleteDecisions

func (c *Client) BulkDeleteDecisions(DecisionsToDelete []*ent.Decision, softDelete bool) (int, error)

BulkDeleteDecisions set the expiration of a bulk of decisions to now() or hard deletes them. We are doing it this way so we can return impacted decisions for sync with CAPI/PAPI

func (*Client) CountDecisionsByValue

func (c *Client) CountDecisionsByValue(decisionValue string) (int, error)

func (*Client) CountDecisionsSinceByValue

func (c *Client) CountDecisionsSinceByValue(decisionValue string, since time.Time) (int, error)

func (*Client) CreateAlert

func (c *Client) CreateAlert(machineID string, alertList []*models.Alert) ([]string, error)

func (*Client) CreateAlertBulk

func (c *Client) CreateAlertBulk(machineId string, alertList []*models.Alert) ([]string, error)

func (*Client) CreateBouncer

func (c *Client) CreateBouncer(name string, ipAddr string, apiKey string, authType string) (*ent.Bouncer, error)

func (*Client) CreateMachine

func (c *Client) CreateMachine(machineID *string, password *strfmt.Password, ipAddress string, isValidated bool, force bool, authType string) (*ent.Machine, error)

func (*Client) CreateOrUpdateAlert

func (c *Client) CreateOrUpdateAlert(machineID string, alertItem *models.Alert) (string, error)

CreateOrUpdateAlert is specific to PAPI : It checks if alert already exists, otherwise inserts it if alert already exists, it checks it associated decisions already exists if some associated decisions are missing (ie. previous insert ended up in error) it inserts them

func (*Client) DeleteAlertByID

func (c *Client) DeleteAlertByID(id int) error

func (*Client) DeleteAlertGraph

func (c *Client) DeleteAlertGraph(alertItem *ent.Alert) error

func (*Client) DeleteAlertGraphBatch

func (c *Client) DeleteAlertGraphBatch(alertItems []*ent.Alert) (int, error)

func (*Client) DeleteAlertWithFilter

func (c *Client) DeleteAlertWithFilter(filter map[string][]string) (int, error)

func (*Client) DeleteBouncer

func (c *Client) DeleteBouncer(name string) error

func (*Client) DeleteDecisionById

func (c *Client) DeleteDecisionById(decisionId int) ([]*ent.Decision, error)

func (*Client) DeleteDecisionsWithFilter

func (c *Client) DeleteDecisionsWithFilter(filter map[string][]string) (string, []*ent.Decision, error)

func (*Client) DeleteWatcher

func (c *Client) DeleteWatcher(name string) error

func (*Client) FlushAgentsAndBouncers

func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersCfg *csconfig.AuthGCCfg) error

func (*Client) FlushAlerts

func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error

func (*Client) FlushOrphans

func (c *Client) FlushOrphans()

func (*Client) GetAlertByID

func (c *Client) GetAlertByID(alertID int) (*ent.Alert, error)

func (*Client) GetConfigItem

func (c *Client) GetConfigItem(key string) (*string, error)

func (*Client) IsMachineRegistered

func (c *Client) IsMachineRegistered(machineID string) (bool, error)

func (*Client) ListBouncers

func (c *Client) ListBouncers() ([]*ent.Bouncer, error)

func (*Client) ListMachines

func (c *Client) ListMachines() ([]*ent.Machine, error)

func (*Client) QueryAlertWithFilter

func (c *Client) QueryAlertWithFilter(filter map[string][]string) ([]*ent.Alert, error)

func (*Client) QueryAllDecisionsWithFilters

func (c *Client) QueryAllDecisionsWithFilters(filters map[string][]string) ([]*ent.Decision, error)

func (*Client) QueryDecisionCountByScenario

func (c *Client) QueryDecisionCountByScenario(filters map[string][]string) ([]*DecisionsByScenario, error)

func (*Client) QueryDecisionWithFilter

func (c *Client) QueryDecisionWithFilter(filter map[string][]string) ([]*ent.Decision, error)

func (*Client) QueryExpiredDecisionsSinceWithFilters

func (c *Client) QueryExpiredDecisionsSinceWithFilters(since time.Time, filters map[string][]string) ([]*ent.Decision, error)

func (*Client) QueryExpiredDecisionsWithFilters

func (c *Client) QueryExpiredDecisionsWithFilters(filters map[string][]string) ([]*ent.Decision, error)

func (*Client) QueryMachineByID

func (c *Client) QueryMachineByID(machineID string) (*ent.Machine, error)

func (*Client) QueryNewDecisionsSinceWithFilters

func (c *Client) QueryNewDecisionsSinceWithFilters(since time.Time, filters map[string][]string) ([]*ent.Decision, error)

func (*Client) QueryPendingMachine

func (c *Client) QueryPendingMachine() ([]*ent.Machine, error)

func (*Client) SelectBouncer

func (c *Client) SelectBouncer(apiKeyHash string) (*ent.Bouncer, error)

func (*Client) SelectBouncerByName

func (c *Client) SelectBouncerByName(bouncerName string) (*ent.Bouncer, error)

func (*Client) SetConfigItem

func (c *Client) SetConfigItem(key string, value string) error

func (*Client) SoftDeleteDecisionByID

func (c *Client) SoftDeleteDecisionByID(decisionID int) (int, []*ent.Decision, error)

SoftDeleteDecisionByID set the expiration of a decision to now()

func (*Client) SoftDeleteDecisionsWithFilter

func (c *Client) SoftDeleteDecisionsWithFilter(filter map[string][]string) (string, []*ent.Decision, error)

SoftDeleteDecisionsWithFilter updates the expiration time to now() for the decisions matching the filter, and returns the updated items

func (*Client) StartFlushScheduler

func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Scheduler, error)

func (*Client) TotalAlerts

func (c *Client) TotalAlerts() (int, error)

func (*Client) UpdateBouncerIP

func (c *Client) UpdateBouncerIP(ipAddr string, ID int) error

func (*Client) UpdateBouncerLastPull

func (c *Client) UpdateBouncerLastPull(lastPull time.Time, ID int) error

func (*Client) UpdateBouncerTypeAndVersion

func (c *Client) UpdateBouncerTypeAndVersion(bType string, version string, ID int) error

func (*Client) UpdateCommunityBlocklist

func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, int, error)

UpdateCommunityBlocklist is called to update either the community blocklist (or other lists the user subscribed to) it takes care of creating the new alert with the associated decisions, and it will as well deleted the "older" overlapping decisions: 1st pull, you get decisions [1,2,3]. it inserts [1,2,3] 2nd pull, you get decisions [1,2,3,4]. it inserts [1,2,3,4] and will try to delete [1,2,3,4] with a different alert ID and same origin

func (*Client) UpdateMachineIP

func (c *Client) UpdateMachineIP(ipAddr string, ID int) error

func (*Client) UpdateMachineLastHeartBeat

func (c *Client) UpdateMachineLastHeartBeat(machineID string) error

func (*Client) UpdateMachineLastPush

func (c *Client) UpdateMachineLastPush(machineID string) error

func (*Client) UpdateMachineScenarios

func (c *Client) UpdateMachineScenarios(scenarios string, ID int) error

func (*Client) UpdateMachineVersion

func (c *Client) UpdateMachineVersion(ipAddr string, ID int) error

func (*Client) ValidateMachine

func (c *Client) ValidateMachine(machineID string) error

type DecisionsByScenario

type DecisionsByScenario struct {
	Scenario string
	Count    int
	Origin   string
	Type     string
}

Directories

Path Synopsis
ent

Jump to

Keyboard shortcuts

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