Commit graph

1868 commits

Author SHA1 Message Date
mmetc
72b6da9925
enable linter: revive (early-return) (#3051)
* enable linter: revive (early-return)

* lint
2024-06-07 16:53:23 +02:00
MazzMa
d3974894fc
add: go reference badge (#3066) 2024-06-07 15:58:16 +02:00
mmetc
550d422d23
lint revive(deep-exit): refactor cmd/crowdsec (#3063)
* lint revive(deep-exit): refactor cmd/crowdsec

* lint
2024-06-07 12:01:08 +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
7d75290a0f
Use cmp.Or from go 1.22 (#3058) 2024-06-06 14:53:30 +02:00
mmetc
b38b959f71
enable linter "stylecheck" (#3060)
* enable linter "stylecheck"

* stylecheck: omit redundant types
2024-06-06 14:51:49 +02:00
Manuel Sabban
1378e16578
fix test 01_cscli by avoiding discrepancies in cscli explain (#3059)
* fix hub installed items in pacakge tests
2024-06-06 11:19:05 +02:00
mmetc
114a966129
refactor "cscli decisions" (#3061)
* cscli decisions: extract method add()

* cscli decisions: extract method delete()

* cscli lapi: avoid apiclient global

* cscli capi: avoid apiclient global

* cscli decisions: error cleanup, avoid global for api client

* update test

* cscli alerts: extract method delete()

* lint
2024-06-06 10:21:03 +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
Manuel Sabban
2865b69855
fix tests in 01_crowdsec.bats for packages testing (#3054) 2024-06-05 08:26:32 +02:00
Manuel Sabban
f0f27ee5cb
add decently new version of python for centos 7 and 8 for testing (#3053)
* add decently new version of python for centos 7 and 8
* update ansible requirements
2024-06-04 22:39:13 +02:00
mmetc
d614ecbdcf
CI/bats: test remediation api via socket (#3052) 2024-06-04 15:09:19 +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
9823ed61b6
cscli: log.Fatal -> return err (#3049)
* cscli: log.Fatal -> return err

* lint
2024-06-03 12:21:00 +02:00
mmetc
c1e858cbca
cscli: refactor alerts/console/decisions/setup (#3003)
* cscli alerts: extract list(), inspect()

* cscli console: extract enroll()

* cscli decisions: extract list()

* support dump: don't use global

* cscli setup: split command constructors

* lint
2024-05-31 19:15:05 +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
Manuel Sabban
95bc5880f4
update vagrant image for fc39, fc40 and ubuntu24.04 (#3042)
* update test distribution
* add skip file to avoid mysql tests
* add ubuntu 24.04
2024-05-31 15:56:13 +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
mmetc
45b403ecd7
fix nil deref w/ malformed cti config (#3028) 2024-05-24 14:37:46 +02:00
mmetc
816608daf4
cscli: faster table rendering (#3027)
* cscli: use go-pretty for tables

* lint
2024-05-24 11:17:52 +02:00
mmetc
572b387fce
CI: improve code coverage report (#3029) 2024-05-24 10:20:47 +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
0ba05acc03
tests: replace "docker-compose" -> "docker compose" (#3000)
* replace "docker-compose" -> "docker compose"

* obsolete doc note

* bats: clean up extra output
2024-05-17 10:07:28 +02:00
mmetc
b6253d567b
simulation for local scenarios (#3010) 2024-05-16 11:13:39 +02:00
mmetc
ccf08e56d9
bats: no need for openssl, netcat; allow to prevent tests from running with a lock (#3016)
* bats: lock/unlock instance data; replace openssl w/ cfssl; update dep list

* concat pem without openssl :-/

* unused/unreachable code

* lint

* redundant {} (shellharden)
2024-05-16 10:58:00 +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
mmetc
ccab6e9910
bats: clean up extra output (#3008) 2024-05-15 10:38:36 +02:00
mmetc
41ec90ae8c
make: remove unused targets (#2998) 2024-05-15 10:37:25 +02:00
Laurence Jones
ecd82ecfbd
feat: File notification plugin (#2932)
* wip: basic impl of file notification no log rotate but might now do it 🤷

* wip: ticker to 2 seconds and lower some log levels

* wip: remove redundant logrus formatter

* wip: the plugin should not handle it own data queue since the plugin process may timeout, so instead have a function that uses said context and loop whilst locking the filewriter this may not be the best way 🤷, however, I dont want multiple notifications to attempt to reopen the file if it has been rotated outside of the plugin context

* wip: impl log rotation which checks on check append, however, this may cause some issues in slow systems as the mutex lock doesnt give up until the file is rotated, however, the plugin looks for context and will give up if the plugin broker decides its timeout and will retry once the plugin has pushed again

* wip: update yaml dep

* wip: me no english great

* wip: even if the file has been rotated outside our control we should still compute the file size

* wip: improve context handling with creating a custom io writer struct which checks the context before attempting to write

* wip: used return byte count instead of calling a conversion again

* wip: actually check the enabled flag on log rotate

* wip: changed my mind, we check when we check file size

* wip: use io copy instead for memory alloc

* fix: add notification file to deb/rpm build
2024-05-15 09:21:45 +01:00
blotus
6b978b09b3
docker: conditionally update hub (#2948) 2024-05-15 10:04:42 +02:00
Laurence Jones
b5e5078fc7
fix: add sslmode check and apend flag to conn string (#3009) 2024-05-14 17:31:15 +01:00
Laurence Jones
11893b2915
[cscli] Add tab completion to notifications [test, inspect] (#2765)
* Add cscli notifications test ValidArgsFunction for tab completion

* Split function to reusable and pass to inspect since both rely on a valid plugin name, fix short/long of list command

* Short should be short

* Removed redundant prerune since Args with validate it for us

* Make english more english

* fix: bad merge now fixed

---------

Co-authored-by: Thibault "bui" Koechlin <thibault@crowdsec.net>
2024-05-14 14:55:08 +01:00
mmetc
e3c6a5ba70
LAPI: support CRL files with multiple PEM blocks (#3002) 2024-05-13 17:09:30 +02:00
mmetc
e4a8d3b99e
deb,rpm: include empty directory etc/crowdsec/acquis.d (#2997) 2024-05-13 12:01:17 +02:00