From f92ec2d469d8fa8d7a3f709c54693842508b1892 Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Tue, 14 Mar 2023 12:59:05 +0100 Subject: [PATCH 1/4] Tests: remove unused deps --- Pipfile | 3 -- Pipfile.lock | 126 +++++---------------------------------------------- 2 files changed, 11 insertions(+), 118 deletions(-) diff --git a/Pipfile b/Pipfile index 1d433e4..a13c7c5 100644 --- a/Pipfile +++ b/Pipfile @@ -1,8 +1,5 @@ [packages] pytest-dotenv = "*" -flask = "*" -pytimeparse = "*" -psutil = "*" pytest-cs = {ref = "0.4.0", git = "https://github.com/crowdsecurity/pytest-cs.git"} [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index ba80390..f242299 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "a3c66f654bd63e4783fe1d29cb43671bfc9c68aac6875e434a2cc08c70e8c034" + "sha256": "8c87805388996174fc304105c468ddfd5deb342e99ea3c1877c2947b6ab3af8e" }, "pipfile-spec": 6, "requires": { @@ -182,14 +182,6 @@ "markers": "python_full_version >= '3.7.0'", "version": "==3.1.0" }, - "click": { - "hashes": [ - "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e", - "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48" - ], - "markers": "python_version >= '3.7'", - "version": "==8.1.3" - }, "cryptography": { "hashes": [ "sha256:103e8f7155f3ce2ffa0049fe60169878d47a4364b277906386f8de21c9234aa1", @@ -229,19 +221,11 @@ }, "exceptiongroup": { "hashes": [ - "sha256:327cbda3da756e2de031a3107b81ab7b3770a602c4d16ca618298c526f4bec1e", - "sha256:bcb67d800a4497e1b404c2dd44fca47d3b7a5e5433dbab67f96c1a685cdfdf23" + "sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e", + "sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785" ], "markers": "python_version < '3.11'", - "version": "==1.1.0" - }, - "flask": { - "hashes": [ - "sha256:7eb373984bf1c770023fce9db164ed0c3353cd0b53f130f4693da0ca756a2e6d", - "sha256:c0bec9477df1cb867e5a67c9e1ab758de9cb4a3e52dd70681f59fa40a62b3f2d" - ], - "index": "pypi", - "version": "==2.2.3" + "version": "==1.1.1" }, "idna": { "hashes": [ @@ -259,78 +243,6 @@ "markers": "python_version >= '3.7'", "version": "==2.0.0" }, - "itsdangerous": { - "hashes": [ - "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44", - "sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a" - ], - "markers": "python_version >= '3.7'", - "version": "==2.1.2" - }, - "jinja2": { - "hashes": [ - "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852", - "sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61" - ], - "markers": "python_version >= '3.7'", - "version": "==3.1.2" - }, - "markupsafe": { - "hashes": [ - "sha256:0576fe974b40a400449768941d5d0858cc624e3249dfd1e0c33674e5c7ca7aed", - "sha256:085fd3201e7b12809f9e6e9bc1e5c96a368c8523fad5afb02afe3c051ae4afcc", - "sha256:090376d812fb6ac5f171e5938e82e7f2d7adc2b629101cec0db8b267815c85e2", - "sha256:0b462104ba25f1ac006fdab8b6a01ebbfbce9ed37fd37fd4acd70c67c973e460", - "sha256:137678c63c977754abe9086a3ec011e8fd985ab90631145dfb9294ad09c102a7", - "sha256:1bea30e9bf331f3fef67e0a3877b2288593c98a21ccb2cf29b74c581a4eb3af0", - "sha256:22152d00bf4a9c7c83960521fc558f55a1adbc0631fbb00a9471e097b19d72e1", - "sha256:22731d79ed2eb25059ae3df1dfc9cb1546691cc41f4e3130fe6bfbc3ecbbecfa", - "sha256:2298c859cfc5463f1b64bd55cb3e602528db6fa0f3cfd568d3605c50678f8f03", - "sha256:28057e985dace2f478e042eaa15606c7efccb700797660629da387eb289b9323", - "sha256:2e7821bffe00aa6bd07a23913b7f4e01328c3d5cc0b40b36c0bd81d362faeb65", - "sha256:2ec4f2d48ae59bbb9d1f9d7efb9236ab81429a764dedca114f5fdabbc3788013", - "sha256:340bea174e9761308703ae988e982005aedf427de816d1afe98147668cc03036", - "sha256:40627dcf047dadb22cd25ea7ecfe9cbf3bbbad0482ee5920b582f3809c97654f", - "sha256:40dfd3fefbef579ee058f139733ac336312663c6706d1163b82b3003fb1925c4", - "sha256:4cf06cdc1dda95223e9d2d3c58d3b178aa5dacb35ee7e3bbac10e4e1faacb419", - "sha256:50c42830a633fa0cf9e7d27664637532791bfc31c731a87b202d2d8ac40c3ea2", - "sha256:55f44b440d491028addb3b88f72207d71eeebfb7b5dbf0643f7c023ae1fba619", - "sha256:608e7073dfa9e38a85d38474c082d4281f4ce276ac0010224eaba11e929dd53a", - "sha256:63ba06c9941e46fa389d389644e2d8225e0e3e5ebcc4ff1ea8506dce646f8c8a", - "sha256:65608c35bfb8a76763f37036547f7adfd09270fbdbf96608be2bead319728fcd", - "sha256:665a36ae6f8f20a4676b53224e33d456a6f5a72657d9c83c2aa00765072f31f7", - "sha256:6d6607f98fcf17e534162f0709aaad3ab7a96032723d8ac8750ffe17ae5a0666", - "sha256:7313ce6a199651c4ed9d7e4cfb4aa56fe923b1adf9af3b420ee14e6d9a73df65", - "sha256:7668b52e102d0ed87cb082380a7e2e1e78737ddecdde129acadb0eccc5423859", - "sha256:7df70907e00c970c60b9ef2938d894a9381f38e6b9db73c5be35e59d92e06625", - "sha256:7e007132af78ea9df29495dbf7b5824cb71648d7133cf7848a2a5dd00d36f9ff", - "sha256:835fb5e38fd89328e9c81067fd642b3593c33e1e17e2fdbf77f5676abb14a156", - "sha256:8bca7e26c1dd751236cfb0c6c72d4ad61d986e9a41bbf76cb445f69488b2a2bd", - "sha256:8db032bf0ce9022a8e41a22598eefc802314e81b879ae093f36ce9ddf39ab1ba", - "sha256:99625a92da8229df6d44335e6fcc558a5037dd0a760e11d84be2260e6f37002f", - "sha256:9cad97ab29dfc3f0249b483412c85c8ef4766d96cdf9dcf5a1e3caa3f3661cf1", - "sha256:a4abaec6ca3ad8660690236d11bfe28dfd707778e2442b45addd2f086d6ef094", - "sha256:a6e40afa7f45939ca356f348c8e23048e02cb109ced1eb8420961b2f40fb373a", - "sha256:a6f2fcca746e8d5910e18782f976489939d54a91f9411c32051b4aab2bd7c513", - "sha256:a806db027852538d2ad7555b203300173dd1b77ba116de92da9afbc3a3be3eed", - "sha256:abcabc8c2b26036d62d4c746381a6f7cf60aafcc653198ad678306986b09450d", - "sha256:b8526c6d437855442cdd3d87eede9c425c4445ea011ca38d937db299382e6fa3", - "sha256:bb06feb762bade6bf3c8b844462274db0c76acc95c52abe8dbed28ae3d44a147", - "sha256:c0a33bc9f02c2b17c3ea382f91b4db0e6cde90b63b296422a939886a7a80de1c", - "sha256:c4a549890a45f57f1ebf99c067a4ad0cb423a05544accaf2b065246827ed9603", - "sha256:ca244fa73f50a800cf8c3ebf7fd93149ec37f5cb9596aa8873ae2c1d23498601", - "sha256:cf877ab4ed6e302ec1d04952ca358b381a882fbd9d1b07cccbfd61783561f98a", - "sha256:d9d971ec1e79906046aa3ca266de79eac42f1dbf3612a05dc9368125952bd1a1", - "sha256:da25303d91526aac3672ee6d49a2f3db2d9502a4a60b55519feb1a4c7714e07d", - "sha256:e55e40ff0cc8cc5c07996915ad367fa47da6b3fc091fdadca7f5403239c5fec3", - "sha256:f03a532d7dee1bed20bc4884194a16160a2de9ffc6354b3878ec9682bb623c54", - "sha256:f1cd098434e83e656abf198f103a8207a8187c0fc110306691a2e94a78d0abb2", - "sha256:f2bfb563d0211ce16b63c7cb9395d2c682a23187f54c3d79bfec33e6705473c6", - "sha256:f8ffb705ffcf5ddd0e80b65ddf7bed7ee4f5a441ea7d3419e861a12eaf41af58" - ], - "markers": "python_version >= '3.7'", - "version": "==2.1.2" - }, "packaging": { "hashes": [ "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2", @@ -364,7 +276,7 @@ "sha256:efeae04f9516907be44904cc7ce08defb6b665128992a56957abc9b61dca94b7", "sha256:fd8522436a6ada7b4aad6638662966de0d61d241cb821239b2ae7013d41a43d4" ], - "index": "pypi", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==5.9.4" }, "pycparser": { @@ -410,14 +322,6 @@ "markers": "python_version >= '3.8'", "version": "==1.0.0" }, - "pytimeparse": { - "hashes": [ - "sha256:04b7be6cc8bd9f5647a6325444926c3ac34ee6bc7e69da4367ba282f076036bd", - "sha256:e86136477be924d7e670646a98561957e8ca7308d44841e21f5ddea757556a0a" - ], - "index": "pypi", - "version": "==1.1.8" - }, "pyyaml": { "hashes": [ "sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf", @@ -489,11 +393,11 @@ }, "urllib3": { "hashes": [ - "sha256:076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72", - "sha256:75edcdc2f7d85b137124a6c3c9fc3933cdeaa12ecb9a6a959f22797a0feca7e1" + "sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305", + "sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.26.14" + "version": "==1.26.15" }, "websocket-client": { "hashes": [ @@ -502,14 +406,6 @@ ], "markers": "python_version >= '3.7'", "version": "==1.5.1" - }, - "werkzeug": { - "hashes": [ - "sha256:2e1ccc9417d4da358b9de6f174e3ac094391ea1d4fbef2d667865d819dfd0afe", - "sha256:56433961bc1f12533306c624f3be5e744389ac61d722175d543e1751285da612" - ], - "markers": "python_version >= '3.7'", - "version": "==2.2.3" } }, "develop": { @@ -577,11 +473,11 @@ }, "ipdb": { "hashes": [ - "sha256:c23b6736f01fd4586cc2ecbebdf79a5eb454796853e1cd8f2ed3b7b91d4a3e93", - "sha256:f74c2f741c18b909eaf89f19fde973f745ac721744aa1465888ce45813b63a9c" + "sha256:45529994741c4ab6d2388bfa5d7b725c2cf7fe9deffabdb8a6113aa5ed449ed4", + "sha256:e3ac6018ef05126d442af680aad863006ec19d02290561ac88b8b1c0b0cfc726" ], "index": "pypi", - "version": "==0.13.11" + "version": "==0.13.13" }, "ipython": { "hashes": [ From 4ab9acee30528557a01caebcec3c629f3f59b69c Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Tue, 14 Mar 2023 13:51:44 +0100 Subject: [PATCH 2/4] CI: disable golangci-lint action cache --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3c18098..95c6179 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -79,3 +79,7 @@ jobs: version: v1.51 args: --issues-exit-code=1 --timeout 10m only-new-issues: false + # the cache is already managed above, enabling it here + # gives errors when extracting + skip-pkg-cache: true + skip-build-cache: true From 7898398f76a1852770f46003b09929925d222e4e Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Wed, 15 Mar 2023 22:48:23 +0100 Subject: [PATCH 3/4] Lint --- config.go | 2 +- custom.go | 2 +- main.go | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index bcc3348..b7fbc9a 100644 --- a/config.go +++ b/config.go @@ -120,7 +120,7 @@ func newConfig(reader io.Reader) (*bouncerConfig, error) { if config.CacheRetentionDuration == 0 { log.Infof("cache_retention_duration defaults to 10 seconds") - config.CacheRetentionDuration = time.Duration(10 * time.Second) + config.CacheRetentionDuration = 10 * time.Second } return config, nil diff --git a/custom.go b/custom.go index 7c44202..556d434 100644 --- a/custom.go +++ b/custom.go @@ -124,7 +124,7 @@ func serializeDecision(decision *models.Decision, action string) (string, error) d := DecisionWithAction{Decision: *decision, Action: action, ID: decision.ID} serbyte, err := json.Marshal(d) if err != nil { - return "", fmt.Errorf("serialize error : %s", err) + return "", fmt.Errorf("serialize error : %w", err) } return string(serbyte), nil } diff --git a/main.go b/main.go index 171a24f..f99c14e 100644 --- a/main.go +++ b/main.go @@ -21,8 +21,9 @@ import ( "golang.org/x/sync/errgroup" "github.com/crowdsecurity/crowdsec/pkg/models" - "github.com/crowdsecurity/cs-custom-bouncer/pkg/version" csbouncer "github.com/crowdsecurity/go-cs-bouncer" + + "github.com/crowdsecurity/cs-custom-bouncer/pkg/version" ) const ( @@ -76,7 +77,6 @@ func deleteDecisions(custom *customBouncer, decisions []*models.Decision) { } } - func addDecisions(custom *customBouncer, decisions []*models.Decision) { if len(decisions) == 1 { log.Infof("adding 1 decision") @@ -92,7 +92,6 @@ func addDecisions(custom *customBouncer, decisions []*models.Decision) { } } - func main() { var err error var promServer *http.Server From b1b642adedc8808bd0da5c85202ae8fa8a173a19 Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Wed, 15 Mar 2023 22:48:38 +0100 Subject: [PATCH 4/4] Use pytest-cs 0.5.0 --- Pipfile | 2 +- Pipfile.lock | 4 ++-- test/conftest.py | 13 ------------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Pipfile b/Pipfile index a13c7c5..d408687 100644 --- a/Pipfile +++ b/Pipfile @@ -1,6 +1,6 @@ [packages] pytest-dotenv = "*" -pytest-cs = {ref = "0.4.0", git = "https://github.com/crowdsecurity/pytest-cs.git"} +pytest-cs = {ref = "0.5.0", git = "https://github.com/crowdsecurity/pytest-cs.git"} [dev-packages] gnureadline = "*" diff --git a/Pipfile.lock b/Pipfile.lock index f242299..c79bf7c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8c87805388996174fc304105c468ddfd5deb342e99ea3c1877c2947b6ab3af8e" + "sha256": "5078fd2793b45c8b9be5306586e0628617d096ae7a5bb3535f48fcd742029b69" }, "pipfile-spec": 6, "requires": { @@ -296,7 +296,7 @@ }, "pytest-cs": { "git": "https://github.com/crowdsecurity/pytest-cs.git", - "ref": "8c49bd8072672c49855a7991a5900858b3ebb777" + "ref": "33c5a611293311b1905983268a38db631fe30852" }, "pytest-datadir": { "hashes": [ diff --git a/test/conftest.py b/test/conftest.py index cd901b8..061cf34 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,12 +1,6 @@ -""" -Full integration test with a real Crowdsec running in Docker -""" - import contextlib import os import pathlib -import secrets -import string import pytest @@ -94,10 +88,3 @@ def closure(**kw): cfg |= cb_cfg_factory(**kw) return cfg yield closure - - -@pytest.fixture(scope='session') -def api_key_factory(): - def closure(alphabet=string.ascii_letters + string.digits): - return ''.join(secrets.choice(alphabet) for i in range(32)) - yield closure