Documentation
¶
Index ¶
- Constants
- Variables
- func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error)
- func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error)
- func GetIpsFromIpRange(host string) (int64, int64, error)
- func IP2Int(ip net.IP) uint32
- func Int2ip(nn uint32) net.IP
- func IsIpv4(host string) bool
- func LastAddress(n *net.IPNet) net.IP
- type BouncerNotFoundError
- type Client
- func (c *Client) AcquireLock(ctx context.Context, name string) error
- func (c *Client) AcquirePullCAPILock(ctx context.Context) error
- func (c *Client) AddToAllowlist(ctx context.Context, list *ent.AllowList, items []*models.AllowlistItem) (int, error)
- func (c *Client) AlertsCountPerScenario(ctx context.Context, filters map[string][]string) (map[string]int, error)
- func (c *Client) ApplyAllowlistsToExistingDecisions(ctx context.Context) (int, error)
- func (c *Client) BouncerUpdateBaseMetrics(ctx context.Context, bouncerName string, bouncerType string, ...) error
- func (c *Client) BulkDeleteBouncers(ctx context.Context, bouncers []*ent.Bouncer) (int, error)
- func (c *Client) BulkDeleteWatchers(ctx context.Context, machines []*ent.Machine) (int, error)
- func (c *Client) CountDecisionsByValue(ctx context.Context, value string, since *time.Time, onlyActive bool) (int, error)
- func (c *Client) CreateAlert(ctx context.Context, machineID string, alertList []*models.Alert) ([]string, error)
- func (c *Client) CreateAllowList(ctx context.Context, name string, description string, allowlistID string, ...) (*ent.AllowList, error)
- func (c *Client) CreateBouncer(ctx context.Context, name string, ipAddr string, apiKey string, ...) (*ent.Bouncer, error)
- func (c *Client) CreateMachine(ctx context.Context, machineID *string, password *strfmt.Password, ...) (*ent.Machine, error)
- func (c *Client) CreateMetric(ctx context.Context, generatedType metric.GeneratedType, generatedBy string, ...) (*ent.Metric, error)
- func (c *Client) CreateOrUpdateAlert(ctx context.Context, machineID string, alertItem *models.Alert) (string, error)
- func (c *Client) DeleteAlertByID(ctx context.Context, id int) error
- func (c *Client) DeleteAlertGraph(ctx context.Context, alertItem *ent.Alert) error
- func (c *Client) DeleteAlertGraphBatch(ctx context.Context, alertItems []*ent.Alert) (int, error)
- func (c *Client) DeleteAlertWithFilter(ctx context.Context, filter map[string][]string) (int, error)
- func (c *Client) DeleteAllowList(ctx context.Context, name string, fromConsole bool) error
- func (c *Client) DeleteAllowListByID(ctx context.Context, name string, allowlistID string, fromConsole bool) error
- func (c *Client) DeleteBouncer(ctx context.Context, name string) error
- func (c *Client) DeleteDecisions(ctx context.Context, decisions []*ent.Decision) (int, error)
- func (c *Client) DeleteWatcher(ctx context.Context, name string) error
- func (c *Client) ExpireDecisionByID(ctx context.Context, decisionID int) (int, []*ent.Decision, error)
- func (c *Client) ExpireDecisions(ctx context.Context, decisions []*ent.Decision) (int, error)
- func (c *Client) ExpireDecisionsWithFilter(ctx context.Context, filter map[string][]string) (int, []*ent.Decision, error)
- func (c *Client) FlushAgentsAndBouncers(ctx context.Context, agentsCfg *csconfig.AuthGCCfg, ...) error
- func (c *Client) FlushAlerts(ctx context.Context, maxAge time.Duration, maxItems int) error
- func (c *Client) FlushOrphans(ctx context.Context)
- func (c *Client) GetActiveDecisionsTimeLeftByValue(ctx context.Context, decisionValue string) (time.Duration, error)
- func (c *Client) GetAlertByID(ctx context.Context, alertID int) (*ent.Alert, error)
- func (c *Client) GetAllowList(ctx context.Context, name string, withContent bool) (*ent.AllowList, error)
- func (c *Client) GetAllowListByID(ctx context.Context, allowlistID string, withContent bool) (*ent.AllowList, error)
- func (c *Client) GetAllowlistsContentForAPIC(ctx context.Context) ([]net.IP, []*net.IPNet, error)
- func (c *Client) GetBouncerUsageMetricsByName(ctx context.Context, bouncerName string) ([]*ent.Metric, error)
- func (c *Client) GetConfigItem(ctx context.Context, key string) (string, error)
- func (c *Client) GetLPUsageMetricsByMachineID(ctx context.Context, machineId string) ([]*ent.Metric, error)
- func (c *Client) IsAllowlisted(ctx context.Context, value string) (bool, string, error)
- func (c *Client) IsAllowlistedBy(ctx context.Context, value string) (reasons []string, err error)
- func (c *Client) IsLocked(err error) bool
- func (c *Client) IsMachineRegistered(ctx context.Context, machineID string) (bool, error)
- func (c *Client) ListAllowLists(ctx context.Context, withContent bool) ([]*ent.AllowList, error)
- func (c *Client) ListBouncers(ctx context.Context) ([]*ent.Bouncer, error)
- func (c *Client) ListMachines(ctx context.Context) ([]*ent.Machine, error)
- func (c *Client) LoadAPICToken(ctx context.Context, logger logrus.FieldLogger) (string, time.Time, bool)
- func (c *Client) MachineUpdateBaseMetrics(ctx context.Context, machineID string, baseMetrics models.BaseMetrics, ...) error
- func (c *Client) MarkUsageMetricsAsSent(ctx context.Context, ids []int) error
- func (c *Client) QueryAlertWithFilter(ctx context.Context, filter map[string][]string) ([]*ent.Alert, error)
- func (c *Client) QueryAllDecisionsWithFilters(ctx context.Context, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryBouncersInactiveSince(ctx context.Context, t time.Time) ([]*ent.Bouncer, error)
- func (c *Client) QueryDecisionCountByScenario(ctx context.Context) ([]*DecisionsByScenario, error)
- func (c *Client) QueryDecisionWithFilter(ctx context.Context, filter map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryExpiredDecisionsSinceWithFilters(ctx context.Context, since *time.Time, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryExpiredDecisionsWithFilters(ctx context.Context, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryMachineByID(ctx context.Context, machineID string) (*ent.Machine, error)
- func (c *Client) QueryMachinesInactiveSince(ctx context.Context, t time.Time) ([]*ent.Machine, error)
- func (c *Client) QueryNewDecisionsSinceWithFilters(ctx context.Context, since *time.Time, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryPendingMachine(ctx context.Context) ([]*ent.Machine, error)
- func (c *Client) ReleaseLock(ctx context.Context, name string) error
- func (c *Client) ReleaseLockWithTimeout(ctx context.Context, name string, timeout int) error
- func (c *Client) ReleasePullCAPILock(ctx context.Context) error
- func (c *Client) RemoveFromAllowlist(ctx context.Context, list *ent.AllowList, values ...string) (int, error)
- func (c *Client) ReplaceAllowlist(ctx context.Context, list *ent.AllowList, items []*models.AllowlistItem, ...) (int, error)
- func (c *Client) SaveAPICToken(ctx context.Context, tokenKey string, token string) error
- func (c *Client) SelectBouncerByName(ctx context.Context, bouncerName string) (*ent.Bouncer, error)
- func (c *Client) SelectBouncerWithIP(ctx context.Context, apiKeyHash string, clientIP string) (*ent.Bouncer, error)
- func (c *Client) SelectBouncers(ctx context.Context, apiKeyHash string, authType string) ([]*ent.Bouncer, error)
- func (c *Client) SetConfigItem(ctx context.Context, key string, value string) error
- func (c *Client) StartFlushScheduler(ctx context.Context, config *csconfig.FlushDBCfg) (*gocron.Scheduler, error)
- func (c *Client) TotalAlerts(ctx context.Context) (int, error)
- func (c *Client) UpdateAllowlistMeta(ctx context.Context, allowlistID string, name string, description string) error
- func (c *Client) UpdateBouncerIP(ctx context.Context, ipAddr string, id int) error
- func (c *Client) UpdateBouncerLastPull(ctx context.Context, lastPull time.Time, id int) error
- func (c *Client) UpdateBouncerTypeAndVersion(ctx context.Context, bType string, version string, id int) error
- func (c *Client) UpdateCommunityBlocklist(ctx context.Context, alertItem *models.Alert) (int, int, int, error)
- func (c *Client) UpdateMachineIP(ctx context.Context, ipAddr string, id int) error
- func (c *Client) UpdateMachineLastHeartBeat(ctx context.Context, machineID string) error
- func (c *Client) UpdateMachineScenarios(ctx context.Context, scenarios string, id int) error
- func (c *Client) UpdateMachineVersion(ctx context.Context, ipAddr string, id int) error
- func (c *Client) ValidateMachine(ctx context.Context, machineID string) error
- type DecisionsByScenario
- type MachineNotFoundError
Constants ¶
const ( CAPIPullLockTimeout = 10 CapiPullLockName = "pullCAPI" )
const ( CapiMachineID = types.CAPIOrigin CapiListsMachineID = types.ListOrigin )
Variables ¶
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 serialize") 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 BuildAlertRequestFromFilter ¶ added in v1.0.0
func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error)
func BuildDecisionRequestWithFilter ¶ added in v1.0.0
func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error)
func GetIpsFromIpRange ¶ added in v1.0.0
GetIpsFromIpRange takes a CIDR range and returns the start and end IP
func LastAddress ¶ added in v1.0.0
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 BouncerNotFoundError ¶ added in v1.6.3
type BouncerNotFoundError struct {
BouncerName string
}
func (*BouncerNotFoundError) Error ¶ added in v1.6.3
func (e *BouncerNotFoundError) Error() string
type Client ¶ added in v1.0.0
type Client struct { Ent *ent.Client Log *log.Logger CanFlush bool Type string WalMode *bool // contains filtered or unexported fields }
func (*Client) AcquireLock ¶ added in v1.6.1
func (*Client) AcquirePullCAPILock ¶ added in v1.6.1
func (*Client) AddToAllowlist ¶ added in v1.6.6
func (*Client) AlertsCountPerScenario ¶ added in v1.4.0
func (*Client) ApplyAllowlistsToExistingDecisions ¶ added in v1.6.9
func (*Client) BouncerUpdateBaseMetrics ¶ added in v1.6.3
func (*Client) BulkDeleteBouncers ¶ added in v1.5.3
func (*Client) BulkDeleteWatchers ¶ added in v1.5.3
func (*Client) CountDecisionsByValue ¶ added in v1.4.0
func (*Client) CreateAlert ¶ added in v1.0.0
func (*Client) CreateAllowList ¶ added in v1.6.6
func (*Client) CreateBouncer ¶ added in v1.0.0
func (*Client) CreateMachine ¶ added in v1.0.0
func (*Client) CreateMetric ¶ added in v1.6.3
func (*Client) CreateOrUpdateAlert ¶ added in v1.5.0
func (c *Client) CreateOrUpdateAlert(ctx context.Context, 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 ¶ added in v1.4.2
func (*Client) DeleteAlertGraph ¶ added in v1.0.0
func (*Client) DeleteAlertGraphBatch ¶ added in v1.2.1
func (*Client) DeleteAlertWithFilter ¶ added in v1.0.0
func (*Client) DeleteAllowList ¶ added in v1.6.6
func (*Client) DeleteAllowListByID ¶ added in v1.6.6
func (*Client) DeleteBouncer ¶ added in v1.0.0
func (*Client) DeleteDecisions ¶ added in v1.6.3
DeleteDecisions removes a list of decisions from the database It returns the number of impacted decisions for the CAPI/PAPI
func (*Client) DeleteWatcher ¶ added in v1.0.0
func (*Client) ExpireDecisionByID ¶ added in v1.6.3
func (c *Client) ExpireDecisionByID(ctx context.Context, decisionID int) (int, []*ent.Decision, error)
ExpireDecision set the expiration of a decision to now()
func (*Client) ExpireDecisions ¶ added in v1.6.3
ExpireDecisions sets the expiration of a list of decisions to now() It returns the number of impacted decisions for the CAPI/PAPI
func (*Client) ExpireDecisionsWithFilter ¶ added in v1.6.3
func (c *Client) ExpireDecisionsWithFilter(ctx context.Context, filter map[string][]string) (int, []*ent.Decision, error)
ExpireDecisionsWithFilter updates the expiration time to now() for the decisions matching the filter, and returns the updated items
func (*Client) FlushAgentsAndBouncers ¶ added in v1.4.0
func (*Client) FlushAlerts ¶ added in v1.0.0
func (*Client) FlushOrphans ¶ added in v1.1.0
func (*Client) GetActiveDecisionsTimeLeftByValue ¶ added in v1.6.2
func (*Client) GetAlertByID ¶ added in v1.0.0
func (*Client) GetAllowList ¶ added in v1.6.6
func (*Client) GetAllowListByID ¶ added in v1.6.6
func (*Client) GetAllowlistsContentForAPIC ¶ added in v1.6.6
func (*Client) GetBouncerUsageMetricsByName ¶ added in v1.6.3
func (*Client) GetConfigItem ¶ added in v1.5.0
func (*Client) GetLPUsageMetricsByMachineID ¶ added in v1.6.3
func (*Client) IsAllowlisted ¶ added in v1.6.6
func (*Client) IsAllowlistedBy ¶ added in v1.6.9
IsAllowlistedBy returns a list of human-readable reasons explaining which allowlists the given value (IP or CIDR) matches.
Few cases: - value is an IP/range directly is in allowlist - value is an IP/range in a range in allowlist - value is a range and an IP/range belonging to it is in allowlist
The result is sorted by the name of the associated allowlist for consistent presentation.
func (*Client) IsMachineRegistered ¶ added in v1.0.0
func (*Client) ListAllowLists ¶ added in v1.6.6
func (*Client) ListBouncers ¶ added in v1.0.0
func (*Client) ListMachines ¶ added in v1.0.0
func (*Client) LoadAPICToken ¶ added in v1.6.9
func (c *Client) LoadAPICToken(ctx context.Context, logger logrus.FieldLogger) (string, time.Time, bool)
LoadAPICToken attempts to retrieve and validate a JWT token from the local database. It returns the token string, its expiration time, and a boolean indicating whether the token is valid.
A token is considered valid if:
- it exists in the database,
- it is a properly formatted JWT with an "exp" claim,
- it is not expired or near expiry.
func (*Client) MachineUpdateBaseMetrics ¶ added in v1.6.3
func (*Client) MarkUsageMetricsAsSent ¶ added in v1.6.3
func (*Client) QueryAlertWithFilter ¶ added in v1.0.0
func (*Client) QueryAllDecisionsWithFilters ¶ added in v1.1.0
func (*Client) QueryBouncersInactiveSince ¶ added in v1.6.3
func (*Client) QueryDecisionCountByScenario ¶ added in v1.4.0
func (c *Client) QueryDecisionCountByScenario(ctx context.Context) ([]*DecisionsByScenario, error)
func (*Client) QueryDecisionWithFilter ¶ added in v1.0.0
func (*Client) QueryExpiredDecisionsSinceWithFilters ¶ added in v1.1.0
func (*Client) QueryExpiredDecisionsWithFilters ¶ added in v1.1.0
func (*Client) QueryMachineByID ¶ added in v1.0.0
func (*Client) QueryMachinesInactiveSince ¶ added in v1.6.3
func (*Client) QueryNewDecisionsSinceWithFilters ¶ added in v1.1.0
func (*Client) QueryPendingMachine ¶ added in v1.0.0
func (*Client) ReleaseLock ¶ added in v1.6.1
func (*Client) ReleaseLockWithTimeout ¶ added in v1.6.1
func (*Client) ReleasePullCAPILock ¶ added in v1.6.1
func (*Client) RemoveFromAllowlist ¶ added in v1.6.6
func (*Client) ReplaceAllowlist ¶ added in v1.6.6
func (*Client) SaveAPICToken ¶ added in v1.6.9
SaveAPICToken stores the given JWT token in the local database under the appropriate config item.
func (*Client) SelectBouncerByName ¶ added in v1.4.0
func (*Client) SelectBouncerWithIP ¶ added in v1.6.5
func (*Client) SelectBouncers ¶ added in v1.6.5
func (*Client) SetConfigItem ¶ added in v1.5.0
func (*Client) StartFlushScheduler ¶ added in v1.0.0
func (*Client) TotalAlerts ¶ added in v1.0.0
func (*Client) UpdateAllowlistMeta ¶ added in v1.6.6
func (*Client) UpdateBouncerIP ¶ added in v1.0.0
func (*Client) UpdateBouncerLastPull ¶ added in v1.0.0
func (*Client) UpdateBouncerTypeAndVersion ¶ added in v1.0.0
func (*Client) UpdateCommunityBlocklist ¶ added in v1.2.0
func (c *Client) UpdateCommunityBlocklist(ctx context.Context, 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 ¶ added in v1.0.0
func (*Client) UpdateMachineLastHeartBeat ¶ added in v1.4.0
func (*Client) UpdateMachineScenarios ¶ added in v1.0.0
func (*Client) UpdateMachineVersion ¶ added in v1.0.0
type DecisionsByScenario ¶ added in v1.4.0
type MachineNotFoundError ¶ added in v1.6.3
type MachineNotFoundError struct {
MachineID string
}
func (*MachineNotFoundError) Error ¶ added in v1.6.3
func (e *MachineNotFoundError) Error() string