Commit graph

860 commits

Author SHA1 Message Date
mmetc
e859a751e9
lint: disable redundant linters, update revive configuration and code metrics (#3081) 2024-06-12 13:04:47 +02:00
mmetc
73792eacb6
refactor pkg/parser: extract processGrok (#3080)
* pkg/parser: extract method processGrok()

* early return

* early return/2
2024-06-12 11:49:19 +02:00
mmetc
fd433a7e73
cscli: refactor "cscli setup" to avoid global variable (#3075)
* cscli refactor: extract method cliSetup.detect()
* cscli refactor: extract method cliSetup.install()
* cscli refactor: extract method cliSetup.dataSources()
* cscli refactor: method ccliSetup.validate()
* skip redundant pre-loop checks
2024-06-12 11:07:10 +02:00
mmetc
bd4540b1bf
refactor context (cscli, pkg/database) (#3071)
* cscli: helper require.DBClient()

* refactor pkg/database: explicit context to dbclient constructor

* lint
2024-06-11 12:13:18 +02:00
mmetc
ae58b158a5
enable linter: revive (var-declaration) (#3069) 2024-06-11 09:26:50 +02:00
mmetc
31ed9fb5ee
enable linter: revive (indent-error-flow) (#3068)
* enable linter: revive (indent-error-flow)

* lint
2024-06-10 17:36:22 +02:00
mmetc
7fd01ae3fc
CI: update golangci-lint to 1.59; enforce canonical HTTP headers (#3074) 2024-06-10 16:13:49 +02:00
mmetc
13fb252571
lint: replace cyclop, gocyclo with revive; basic pkg/hubtest helper (#3065) 2024-06-07 19:03:23 +02:00
mmetc
dd6cf2b844
pkg/cwhub: use explicit context for item install, upgrade (#3067) 2024-06-07 17:32:52 +02:00
mmetc
cad760e605
pkg/cwhub: use explicit context for version check, index update (#3064)
* cscli refactor: explicit context for hub (version lookup)

* change order of version checks

* pkg/cwhub: split NewHub() + Update() + Load()

* cscli refactor: explicit context for hub (index update)

* updated pkg/cwhub docs

* lint
2024-06-07 16:56:02 +02:00
mmetc
72b6da9925
enable linter: revive (early-return) (#3051)
* enable linter: revive (early-return)

* lint
2024-06-07 16:53:23 +02:00
mmetc
6ef2396c91
enable linter: revive (blank-imports) (#3062)
* lint: revive (blank-imports) require a comment to justify blank imports

* typo
2024-06-06 16:03:32 +02:00
mmetc
b38b959f71
enable linter "stylecheck" (#3060)
* enable linter "stylecheck"

* stylecheck: omit redundant types
2024-06-06 14:51:49 +02:00
mmetc
9e859c0c8c
refactor pkg/database, pkg/models (#3022)
* pkg/models: Source.String()

* pkg/models: Alert.FormatAsStrings()

* cscli alerts list: sort remediation keys

avoid printing
"ban: ... captcha: ..."
in one line, and
"captcha: ... ban: ..."
in another

* remove unused methods; drop else branch

* lint
2024-06-05 12:01:13 +02:00
mmetc
73e03ef556
lint: enable revive/if-return, revive/error-strings (#3057)
* lint: enable revive/if-return, revive/error-strings

* lint
2024-06-05 11:37:57 +02:00
mmetc
3dd17b9081
tests: log.Fatal -> return err (#3056)
* tests: log.Fatal -> return err

* lint
2024-06-05 11:04:54 +02:00
mmetc
9101de95d8
pkg/database: refactor & rename "soft delete" to "expire" (#3025)
* pkg/database: replace parameter with explicit methods

* merge methods with recusion

* rename "soft delete" -> "expire"

* lint
2024-06-04 13:19:46 +02:00
mmetc
fba4237fbd
lint: revive/useless-break (#3050) 2024-06-04 09:48:21 +02:00
mmetc
7313d49145
enable linter: revive(bool-literal-in-expr) (#2983) 2024-06-04 09:47:25 +02:00
mmetc
89d02e9458
CI/lint: enable some "revive" rules (#3041)
argument-limit
Warns when a function receives more parameters than the maximum set by the rule's configuration.

bare-return
Warns on bare (a.k.a. naked) returns

context-as-argument
By convention, context.Context should be the first parameter of a function.

duplicated-imports
It is possible to unintentionally import the same package twice.

modifies-parameter
A function that modifies its parameters can be hard to understand. It can also be misleading if the arguments are passed by value by the caller.

redundant-import-alias
This rule warns on redundant import aliases.

unreachable-code
This rule spots and proposes to remove unreachable code.
2024-05-31 16:45:47 +02:00
mmetc
8501f459c3
db,lapi: round durations and timestamps to 1 second (#3015)
* cscli/lapi: round decision duration to 1 second

* db: round created, updated... timestamps to 1 second
2024-05-31 16:24:33 +02:00
mmetc
599a5a49a1
pkg/dumps.DumpTree: split to reduce complexity (#3001)
* pkg/dumps.DumpTree: split to reduce complexity

* lint
2024-05-31 16:08:06 +02:00
mmetc
b8ee31ade2
pkg/database: simplify flush agents/bouncers (#3026)
* pkg/database: simplify flush agents/bouncers

* lint
2024-05-31 15:44:30 +02:00
mmetc
6dbc5fd522
db: mark immutable columns / remove unused (#3024)
* db: mark immutable columns

* db: drop unused column

* lint
2024-05-31 15:19:48 +02:00
mmetc
02e2c8aed7
deps: use ent 0.13.1 (#3023) 2024-05-31 15:00:38 +02:00
blotus
16bfab86c8
check type assertion in geoip enrichers (#3040) 2024-05-31 09:38:43 +02:00
mmetc
7d6514c7cc
update user agent with version and platform information (#3035)
* update user agent with version and platform information

* remove unused import

* user agent: omit tag correctly if git is dirty
2024-05-30 09:45:43 +02:00
blotus
f3341c1382
Appsec: properly populate event (#2943) 2024-05-27 10:15:38 +02:00
Laurence Jones
9088f31b7d
enhance: container discovery via labels (#2959)
* wip: attempt to autodiscover via labels

* wip: remove labels dep on docker acquistion

* wip: remove labels dep on docker acquistion

* wip: add debug

* wip: try fix parser maps

* wip: remove redundant pointer

* wip: add debug

* wip: cant type assert

* wip: reinstate debug

* wip: reinstate debug

* wip: reinstate debug

* wip: oops

* wip: add a debug

* wip: fix labels

* wip: remove redundant paramter

* wip: rename config option to be more self declarative

* wip: update log wording

* wip: the if check was not correct

* wip: me lost

* fix: add checks to typecast and log useful information

* add tests for parseLabels

* return nil instead of pointer to empty struct

* simplify EvalContainer return value

---------

Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
2024-05-24 14:27:25 +01:00
blotus
f06e3e78ab
jwt transport: fix retry on unauthorized from CAPI(#3006) 2024-05-24 14:43:12 +02:00
blotus
09afcbe93a
appsec: respect on_success parameter in hooks (#3017) 2024-05-24 14:42:17 +02:00
blotus
20e44cd18a
appsec: add files and cookies related zones (#2956) 2024-05-17 16:16:04 +02:00
mmetc
1a4ac9d239
replace log.Fatal with error return (#2996)
* log.Fatal -> fmt.Errorf

* lint
2024-05-17 14:26:10 +02:00
mmetc
b6253d567b
simulation for local scenarios (#3010) 2024-05-16 11:13:39 +02:00
blotus
1b894a292b
GetActiveDecisionsCount()and GetActiveDecisionsTimeLeft()expr helpers (#3013) 2024-05-15 15:33:43 +02:00
mmetc
cc63729b2c
version: write to stdout, add missing newline (#3012)
* pkg/cwversion cleanup

 - add missing newline between version and codename
 - add more information to "support dump"
 - write "cscli version" and "crowdsec -version" to stdout, not stderr

* fix func test

* lint
2024-05-15 10:52:43 +02:00
Laurence Jones
b5e5078fc7
fix: add sslmode check and apend flag to conn string (#3009) 2024-05-14 17:31:15 +01:00
mmetc
e3c6a5ba70
LAPI: support CRL files with multiple PEM blocks (#3002) 2024-05-13 17:09:30 +02:00
mmetc
0d9e000543
use go-cs-lib/downloader for data files, hub index, item YAML (#2926) 2024-05-07 13:44:17 +02:00
mmetc
11da728b51
cscli support: collect profiling data and logs (#2987)
* extract methods, avoid globals
* collect logs to file dump.log
* include pprof data
* include latest logs
2024-05-07 12:59:38 +02:00
mmetc
a2dcc0ef9a
cscli: remove global dbClient (#2985)
* cscli: remove global dbClient

* lint (whitespace, errors)
2024-05-06 12:33:54 +02:00
mmetc
659feec496
cscli: don't print timestamps (#2984)
* cscli: don't print timestamps

* lint (whitespace, errors)
2024-05-06 10:43:54 +02:00
mmetc
3392e5e00f
enable linter "revive" (#2978)
* enable linter "revive"

* enable some revive checks

* pointer receiver for crzLogger

* fix "range-loop variables always have the same address"

* lint (whitespace)
2024-05-02 14:22:02 +02:00
mmetc
529d3b2079
minor lint/readability (#2976)
* simplify a couple loops

* if/else -> switch

* drop redundant else

* comment + drop var declaration + explicit zero return

* lint (whitespace/fmt.Errorf)
2024-05-02 13:42:47 +02:00
mmetc
91fbc63533
db: review update timestamps, immutable columns (#2981)
* orm: correct behavior of created_at, updated_at, define immutable fields

* remove updatedefault for last_push, last_heartbeat

* re-generate db schema

* update last_push in CreateAlert()

* lint
2024-05-02 12:56:41 +02:00
mmetc
87564ea462
pkg/dumps,hubtest: use yaml.v3 (#2972)
* pkg/dumps,hubtest: use yaml.v3

* lint (whitespace/fmt.Errorf)
2024-05-02 10:59:24 +02:00
mmetc
3788610aff
cscli: avoid global vars (#2977)
* cscli: avoid global usage

This is required to make it possible to split the package

* lint (fmt.Errorf)
2024-05-02 10:25:04 +02:00
mmetc
c4473839c4
Refact pkg/parser/node (#2953)
* extract method processFilter()

* extract method processWhitelist()

* lint (whitespace, errors)
2024-04-25 17:53:10 +02:00
blotus
ceb4479ec4
add zfs magic for GetFSType (#2950) 2024-04-25 15:05:11 +02:00
Thibault "bui" Koechlin
f4ed7b3520
Truncate meta data (#2966)
* truncate meta-data if they are too big
2024-04-25 13:43:38 +02:00