move it to constants

This commit is contained in:
bui 2023-09-20 10:22:20 +02:00
parent b4d553ee82
commit 5ccdaae9c7
8 changed files with 11 additions and 12 deletions

View file

@ -43,8 +43,6 @@ const (
metricsIntervalDelta = time.Minute * 15
)
var SCOPE_CAPI_ALIAS_ALIAS string = "crowdsecurity/community-blocklist" //we don't use "CAPI" directly, to make it less confusing for the user
type apic struct {
// when changing the intervals in tests, always set *First too
// or they can be negative
@ -776,14 +774,14 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
for _, blocklist := range links.Blocklists {
if err := a.updateBlocklist(defaultClient, blocklist, add_counters); err != nil {
return err
}
}
}
return nil
}
func setAlertScenario(alert *models.Alert, add_counters map[string]map[string]int, delete_counters map[string]map[string]int) {
if *alert.Source.Scope == types.CAPIOrigin {
*alert.Source.Scope = SCOPE_CAPI_ALIAS_ALIAS
*alert.Source.Scope = types.CommunityPullAlertsOrigin
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs", add_counters[types.CAPIOrigin]["all"], delete_counters[types.CAPIOrigin]["all"]))
} else if *alert.Source.Scope == types.ListOrigin {
*alert.Source.Scope = fmt.Sprintf("%s:%s", types.ListOrigin, *alert.Scenario)

View file

@ -689,7 +689,7 @@ func TestAPICWhitelists(t *testing.T) {
alertScenario[alert.SourceScope]++
}
assert.Equal(t, 3, len(alertScenario))
assert.Equal(t, 1, alertScenario[SCOPE_CAPI_ALIAS_ALIAS])
assert.Equal(t, 1, alertScenario[types.CommunityPullAlertsOrigin])
assert.Equal(t, 1, alertScenario["lists:blocklist1"])
assert.Equal(t, 1, alertScenario["lists:blocklist2"])
@ -818,7 +818,7 @@ func TestAPICPullTop(t *testing.T) {
alertScenario[alert.SourceScope]++
}
assert.Equal(t, 3, len(alertScenario))
assert.Equal(t, 1, alertScenario[SCOPE_CAPI_ALIAS_ALIAS])
assert.Equal(t, 1, alertScenario[types.CommunityPullAlertsOrigin])
assert.Equal(t, 1, alertScenario["lists:blocklist1"])
assert.Equal(t, 1, alertScenario["lists:blocklist2"])

View file

@ -870,8 +870,7 @@ func AlertPredicatesFromFilter(filter map[string][]string) ([]predicate.Alert, e
alert.Not(alert.HasDecisions()),
alert.Or(
alert.SourceScopeHasPrefix(types.ListOrigin+":"),
//see apiserver.SCOPE_CAPI_ALIAS_ALIAS
alert.SourceScopeEQ("crowdsecurity/community-blocklist"),
alert.SourceScopeEQ(types.CommunityPullAlertsOrigin),
),
),
),

View file

@ -18,6 +18,8 @@ const CscliImportOrigin = "cscli-import"
const ListOrigin = "lists"
const CAPIOrigin = "CAPI"
const CommunityPullAlertsOrigin = "crowdsecurity/community-blocklist"
const DecisionTypeBan = "ban"
func GetOrigins() []string {

@ -1 +1 @@
Subproject commit 78fa631d1370562d2cd4a1390989e706158e7bf0
Subproject commit 44913ffe6020d1561c4c4d1e26cda8e07a1f374f

@ -1 +1 @@
Subproject commit f7defb94362f2053a3e73d13086a167448ea9133
Subproject commit 6636e2c2ef5ffe361535cb45fc61682c5ef46b71

@ -1 +1 @@
Subproject commit cb914cdc176da00e321d3bc92f88383698c701d6
Subproject commit 17fa557f6fe28a327933e3fa32efef1d211caa5a

@ -1 +1 @@
Subproject commit 3c8fadc5097c9acfc96d836dced2bb598e48b009
Subproject commit d140a65044b2d6810381935ae7f0c94c7023c8c3