Skip to content

Commit 4fdb9e8

Browse files
committed
Merge branch 'release/v0.0.1' into main
2 parents 709f28c + 6ce4661 commit 4fdb9e8

40 files changed

+6421
-2
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"

.github/workflows/superlinter.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Super-Linter
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
super-lint:
9+
name: Lint code base
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Get Composer Cache Directory
17+
id: composer-cache
18+
run: |
19+
echo "::set-output name=dir::$(composer config cache-files-dir)"
20+
21+
- name: Cache Composer Downloads
22+
uses: actions/cache@v2
23+
with:
24+
path: vendor/
25+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
28+
29+
- name: Cache PHP dependencies
30+
uses: actions/cache@v2
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
34+
35+
- name: Install PHP dependencies
36+
uses: php-actions/composer@v4
37+
38+
- name: Run Super-Linter
39+
uses: github/super-linter@v3
40+
env:
41+
FILTER_REGEX_INCLUDE: /tmp/lint/src/.*
42+
DEFAULT_BRANCH: main
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
# push: TODO P3 No tests on push because it causes an unresolved bug (no space left on device). This Smell a race condition.
6+
7+
jobs:
8+
9+
integration:
10+
name: Integration
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
php: ['7.2', '7.3', '7.4']
16+
# TODO P2 PHP 8 Compatibility: Fix: Error: Class "Memcached" not found (https://github.com/crowdsecurity/php-cs-bouncer/runs/1491476055?check_suite_focus=true)
17+
18+
services:
19+
redis:
20+
image: redis:6.0.0
21+
ports:
22+
- 6379:6379
23+
memcached:
24+
image: memcached:1.6.5
25+
ports:
26+
- 11211:11211
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
# In this step, this action saves a list of existing images,
33+
# the cache is created without them in the post run.
34+
# It also restores the cache if it exists.
35+
- uses: satackey/[email protected]
36+
# Ignore the failure of a step and avoid terminating the job.
37+
continue-on-error: true
38+
39+
- name: Checkout Crowdsec
40+
uses: actions/checkout@v2
41+
with:
42+
repository: crowdsecurity/crowdsec
43+
ref: v1.0.0-rc4
44+
path: ./var/.tmp-crowdsec
45+
46+
- name: Build Crowdsec 1.0.0 (RC4) Docker image
47+
run: docker build -t crowdsec:v1.0.0-rc4 ./var/.tmp-crowdsec
48+
49+
- name: Run the crowdsec container
50+
run: docker run -d --name crowdsec -p 8080:8080 -e "DISABLE_AGENT=true" crowdsec:v1.0.0-rc4
51+
52+
- name: Add a bouncer to run phpunit tests
53+
run: docker exec crowdsec cscli bouncers add bouncer-php-library -o raw > .bouncer-key
54+
55+
# TODO P2 Move values to env vars
56+
- name: Add a machine to pilot crowdsec state
57+
run: docker exec crowdsec cscli machines add PhpUnitTestMachine --password PhpUnitTestMachinePassword
58+
59+
- name: Setup PHP
60+
uses: shivammathur/setup-php@v2
61+
with:
62+
coverage: "none"
63+
extensions: "json,memcached,redis,xsl,ldap"
64+
ini-values: "memory_limit=-1"
65+
php-version: "${{ matrix.php }}"
66+
tools: pecl
67+
68+
- name: Display versions
69+
run: |
70+
php -r 'foreach (get_loaded_extensions() as $extension) echo $extension . " " . phpversion($extension) . PHP_EOL;'
71+
php -i
72+
73+
- name: Get Composer Cache Directory
74+
id: composer-cache
75+
run: |
76+
echo "::set-output name=dir::$(composer config cache-files-dir)"
77+
78+
- name: Cache Composer Downloads
79+
uses: actions/cache@v2
80+
with:
81+
path: vendor/
82+
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
83+
restore-keys: |
84+
${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
85+
86+
- name: Cache PHP dependencies
87+
uses: actions/cache@v2
88+
with:
89+
path: vendor
90+
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
91+
92+
- name: Install PHP dependencies
93+
uses: php-actions/composer@v4
94+
95+
- name: Run tests
96+
run: ./vendor/bin/phpunit --testdox --colors --exclude-group ignore --group integration -v tests/IpVerificationTest.php
97+
env:
98+
LAPI_URL: http://localhost:8080
99+
MEMCACHED_DSN: memcached://localhost:11211
100+
REDIS_DSN: redis://localhost:6379

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Composer
2+
/vendor/
3+
4+
# Systems
5+
.DS_Store
6+
7+
# App
8+
/var/
9+
.bouncer-key
10+
.phpdoc
11+
TODO.md
12+
.php_cs.cache

.php_cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
if (!file_exists(__DIR__.'/src')) {
4+
exit(0);
5+
}
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules([
9+
'@Symfony' => true,
10+
'@Symfony:risky' => true,
11+
'@PHPUnit75Migration:risky' => true,
12+
'php_unit_dedicate_assert' => ['target' => '5.6'],
13+
'array_syntax' => ['syntax' => 'short'],
14+
'fopen_flags' => false,
15+
'protected_to_private' => false,
16+
'native_constant_invocation' => true,
17+
'combine_nested_dirname' => true,
18+
'list_syntax' => ['syntax' => 'short'],
19+
])
20+
->setRiskyAllowed(true)
21+
->setFinder(
22+
PhpCsFixer\Finder::create()
23+
->in(__DIR__.'/src')
24+
)
25+
;

README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The official PHP client for the CrowdSec APIs (LAPI or CAPI).
44

55
This client helps to create CrowdSec bouncers for PHP applications or frameworks (e-commerce, blog, other apps...).
66

7-
## Getting started!
7+
## Getting started
88

99
View `docs/getting-started.md` to learn how to include this library in your project.
1010

@@ -16,4 +16,30 @@ You will find the full documenation here: (...) TODO P2
1616

1717
# Licence
1818

19-
MIT License. Details in the `./LICENSE` file.
19+
MIT License. Details in the `./LICENSE` file.
20+
21+
# TODO
22+
23+
Features:
24+
- [x] Fast API client
25+
- [x] LAPI Support
26+
- [x] Built-in support for the most known cache systems: Redis, Memcached, PhpFiles
27+
- [x] Rupture mode
28+
- [ ] Stream mode (alpha version)
29+
- [ ] Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
30+
- [ ] Direct CAPI support
31+
- [ ] Log events using monolog
32+
- [ ] PHP 5.6 retro compatibility (currenly PHP 7.2+)
33+
- [ ] Retrieve cache items with pagination
34+
- [ ] Release 1.0.0 version
35+
- [ ] Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
36+
37+
Code:
38+
- [x] Docker dev environment (Dockerized Crowdsec, Redis, Memcached, Composer, PHPUnit)
39+
- [x] Continuous Integration (CI, includes Integration Tests and Super Linter)
40+
- [x] Integration tests (with TDD)
41+
- [x] Documented (Static documentation, PHP Doc)
42+
- [ ] Continuous Delivery (CD)
43+
- [ ] Load tests (compare performances)
44+
- [ ] Report Code coverage
45+
- [ ] Setup Xdebug environment

composer.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "crowdsec/bouncer-php-library",
3+
"description": "The official PHP client for the CrowdSec LAPI/CAPI",
4+
"type": "library",
5+
"license": "MIT License",
6+
"minimum-stability": "stable",
7+
"autoload": {
8+
"psr-4": {
9+
"CrowdSecBouncer\\": "src/"
10+
}
11+
},
12+
"require-dev": {
13+
"symfony/var-dumper": "^5.1",
14+
"phpunit/phpunit": "^8.5",
15+
"predis/predis": "^1.1",
16+
"friendsofphp/php-cs-fixer": "^2.16",
17+
"phpstan/phpstan": "^0.12.58"
18+
},
19+
"require": {
20+
"symfony/config": "^5.1",
21+
"symfony/cache": "^5.1"
22+
},
23+
"scripts": {
24+
"lintfix":"vendor/bin/php-cs-fixer fix --verbose --show-progress=estimating --config=.php_cs ./src",
25+
"phpstan":"vendor/bin/phpstan analyse"
26+
}
27+
}

0 commit comments

Comments
 (0)