Skip to content

Commit c740b3d

Browse files
authored
Merge pull request #10 from crowdsecurity/feature/packaging
Update doc and prepare composer.json to be published to packagist
2 parents 01c3f7b + 3781fc8 commit c740b3d

9 files changed

+121
-69
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Tests
1+
name: tests
22

33
on:
44
push:

README.md

+62-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,76 @@
1+
2+
<p align="center">
3+
<img src="https://raw.githubusercontent.com/crowdsecurity/crowdsec/master/docs/assets/images/crowdsec_logo.png" alt="CrowdSec" title="CrowdSec" width="200" height="120"/>
4+
</p>
5+
16
# PHP Bouncer Library
27

3-
The official PHP client for the CrowdSec APIs (LAPI or CAPI).
8+
> The official PHP bouncer library for the CrowdSec LAPI/CAPI
9+
10+
<p align="center">
11+
<img src="https://img.shields.io/github/workflow/status/crowdsecurity/php-cs-bouncer/tests/main">
12+
<img src="https://img.shields.io/github/license/crowdsecurity/php-cs-bouncer">
13+
<img src="https://img.shields.io/github/v/release/crowdsecurity/php-cs-bouncer?include_prereleases">
14+
</p>
15+
16+
<p align="center">
17+
:books: <a href="https://doc.crowdsec.net">Documentation</a>
18+
:diamond_shape_with_a_dot_inside: <a href="https://hub.crowdsec.net">Hub</a>
19+
:speech_balloon: <a href="https://discourse.crowdsec.net">Discourse Forum</a>
20+
:speech_balloon: <a href="https://gitter.im/crowdsec-project/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link">Gitter Chat</a>
21+
</p>
22+
23+
> This library allows you to create CrowdSec bouncers for PHP applications or frameworks like e-commerce, blog or other exposed applications.
424
5-
This client helps to create CrowdSec bouncers for PHP applications or frameworks (e-commerce, blog, other apps...).
25+
## Features
626

27+
- ✅ Fast API client
28+
- ✅ LAPI Support (CAPI not supported yet)
29+
- ✅ Built-in support for the most known cache systems like Redis, Memcached, PhpFiles
30+
-**Live mode** or **Stream mode**
31+
- ✅ Events logged using monolog
32+
- ✅ Large PHP matrix compatibility: 7.2.x, 7.3.x, 7.4.x and 8.0.x
33+
- ✅ Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
34+
- ✅ Clear and prune the cache
735
## Getting started
836

9-
View `docs/getting-started.md` to learn how to include this library in your project.
37+
### Installing CrowdSec Bouncer library
38+
39+
The recommended way to install CrowdSec Bouncer library is through [Composer](https://getcomposer.org/).
40+
41+
```bash
42+
composer require crowdsec/bouncer
43+
```
44+
45+
```php
46+
47+
/* To get a token: "cscli bouncers add <name-of-your-php-bouncer> */
48+
$apiToken = 'YOUR_TOKEN';
49+
50+
/* Select the best cache adapter for your needs (Memcached, Redis, PhpFiles, ...) */
51+
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter();
1052

11-
You will find the full documenation here: (...) TODO P2
53+
$bouncer = new CrowdSecBouncer\Bouncer();
54+
$bouncer->configure(['api_token'=> $apiToken], $cacheAdapter);
1255

13-
# Sources
56+
$remediation = $bouncer->getRemediationForIp($blockedIp);// Return "ban", "captcha" or "bypass"
57+
```
1458

15-
- https://thephp.website/en/issue/php-docker-quick-setup/
59+
View [`docs/getting-started.md`](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/docs/getting-started.rst) to learn how to include this library in your project in minutes.
1660

17-
# Licence
61+
## Future
62+
- Retrieve cache items with pagination
63+
- Release 1.0.0 version
64+
- Direct CAPI support
65+
- Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
66+
- Publish load tests (compare performances)
67+
- Report Code coverage
68+
- Setup Xdebug environment with Docker
1869

19-
MIT License. Details in the `./LICENSE` file.
70+
## Licence
2071

21-
# TODO
72+
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)
2273

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] Live mode
28-
- [x] Stream mode
29-
- [x] Log events using monolog
30-
- [x] PHP compatibility with 7.2.x, 7.3.x, 7.4.x and 8.0.x
31-
- [ ] Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
32-
- [ ] Retrieve cache items with pagination
33-
- [ ] Direct CAPI support
34-
- [ ] Release 1.0.0 version
35-
- [ ] Support more cache systems (Apcu, Couchbase, Doctrine, Pdo)
74+
## Licence
3675

37-
Code:
38-
- [x] Docker dev environment (Dockerized Crowdsec, Redis, Memcached, PHP)
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
76+
[MIT License](https://github.com/crowdsecurity/php-cs-bouncer/blob/main/LICENSE)

composer.json

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
{
2-
"name": "crowdsec/bouncer-php-library",
3-
"description": "The official PHP client for the CrowdSec LAPI/CAPI",
2+
"name": "crowdsec/bouncer",
3+
"description": "The official PHP bouncer library for the CrowdSec LAPI/CAPI",
44
"type": "library",
5-
"license": "MIT License",
5+
"license": "MIT",
66
"minimum-stability": "stable",
7+
"keywords": [
8+
"security",
9+
"crowdsec",
10+
"waf",
11+
"middleware",
12+
"http",
13+
"blocker",
14+
"bouncer",
15+
"captcha",
16+
"geoip",
17+
"ip",
18+
"ip range"
19+
],
720
"autoload": {
821
"psr-4": {
922
"CrowdSecBouncer\\": "src/"
1023
}
1124
},
25+
"authors": [
26+
{
27+
"name": "Lucas Cherifi",
28+
"email": "[email protected]"
29+
}
30+
],
1231
"require": {
13-
"php": ">=7.1",
32+
"php": "^7.2 || ^8.0",
1433
"symfony/config": "^5.2",
1534
"symfony/cache": "^5.2",
1635
"monolog/monolog": "^2.1"
17-
1836
},
1937
"require-dev": {
2038
"predis/predis": "^1.1",
2139
"bramus/monolog-colored-line-formatter": "^3.0",
2240
"symfony/var-dumper": "^5.2",
2341
"phpunit/phpunit": "8.5.13"
2442
}
25-
}
43+
}
File renamed without changes.

docs/core-development.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Contribute to this library
22
==========================
33

4+
### Dev environment
5+
6+
- ✅ Docker dev environment (Dockerized Crowdsec, Redis, Memcached, PHP)
7+
- ✅ Continuous Integration (CI, includes Integration Tests and Super Linter)
8+
- ✅ Integration tests (with TDD)
9+
- ✅ Documented (Static documentation, PHP Doc)
10+
- ✅ Continuous Delivery (CD)
11+
412
Guidelines
513
~~~~~~~~~~
614

docs/env.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Environment
22
-----------
33

4-
PHP compatibility matrix: ^5.5.9|>=7.0.8 (same as Symfony 3.4)
4+
PHP compatibility matrix: >=7.2 (same as Symfony 4.4)
55

6-
View the usage stats published by packagist (composer) here:
6+
PHP usage stats published by Packagist (composer) here:
77
https://blog.packagist.com/php-versions-stats-2020-1-edition/
88

99
Dependencies:

docs/technical-decisions.rst renamed to docs/faq.rst

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
1-
Technical decisions
2-
===================
1+
FAQ
2+
===
33

44
We explain here each important technical decision used to design this
55
libary.
66

7-
We use Symfony/Cache component
8-
------------------------------
9-
10-
This component is compatible with many cache systems.
7+
Why using *Symfony/Cache* and *Symfony/Config* component?
8+
---------------------------------------------------------
119

12-
This library is tested and maintained under LTS versions.
13-
14-
We use Symfony/Config component
15-
-------------------------------
10+
The Cache component is compatible with many cache systems.
1611

1712
The Config component provides several classes to help you find, load,
1813
combine, fill and validate configuration values of any kind, whatever
1914
their source may be (YAML, XML, INI files, or for instance a database).
2015
A great job done by this library, tested and maintained under LTS
2116
versions.
2217

23-
We don't use Guzzle
24-
-------------------
18+
This library is tested and maintained under LTS versions.
19+
20+
Why not using Guzzle?
21+
---------------------
2522

2623
The last Guzzle versions remove the User Agent to prevent risks. Since
2724
LAPI or CAPI need a valid User Agent, we can not use Guzzle to request
2825
CAPI/LAPI.
2926

30-
We don't use Swagger Codegen
31-
----------------------------
27+
Why not using Swagger Codegen?
28+
------------------------------
3229

3330
We were not able to use this client with easen ex: impossible to get
3431
JSON data, it's seemd there is a bug with unserialization, we received
3532
an empty array.
3633

37-
PHP 7.0+ compatibility
38-
----------------------
34+
Which PHP compatibility matrix?
35+
-------------------------------
3936

4037
Why not PHP 5.6?
4138

docs/getting-started.rst

+9-11
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ Use the bouncer library (live mode)
1515

1616
.. code-block:: php
1717
18+
/* To get a token: "cscli bouncers add <name-of-your-php-bouncer> */
19+
$apiToken = 'YOUR_TOKEN';
1820
19-
use CrowdSecBouncer\Bouncer;
20-
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
21+
/* Select the best cache adapter for your needs (Memcached, Redis, PhpFiles, ...) */
22+
$cacheAdapter = new Symfony\Component\Cache\Adapter\PhpFilesAdapter();
2123
22-
$apiToken = getenv(DEFINE_YOUR_TOKEN);// Good practice: define this secret data in environment variables.
23-
24-
// Select the best cache adapter for your needs (Memcached, Redis, PhpFiles)
25-
// Note: You can try more cache system but we did not test them for now (Apcu, Filesystem, Doctrine, Couchbase, Pdo).
26-
// The full list is here: https://symfony.com/doc/current/components/cache.html#available-cache-adapters
27-
$cacheAdapter = new PhpFilesAdapter();
28-
29-
$bouncer = new Bouncer();
24+
$bouncer = new CrowdSecBouncer\Bouncer();
3025
$bouncer->configure(['api_token'=> $apiToken], $cacheAdapter);
3126
32-
$remediation = $bouncer->getRemediationForIp($blockedIp);// Return "ban", "captcha" or "bypass"
27+
$remediation = $bouncer->getRemediationForIp($blockedIp);// Return "ban", "captcha" or "bypass".
28+
29+
Note: You can try more cache system but we did not test them for now (Apcu, Filesystem, Doctrine, Couchbase, Pdo).
30+
The full list is here: https://symfony.com/doc/current/components/cache.html#available-cache-adapters
3331

3432
Use the bouncer library (stream mode)
3533
------------------------------------

docs/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
getting-started
55
how-it-works
66
env
7-
configuration
7+
configuration-reference
88
tips
99
tests
1010
contribute
1111
core-development
12-
technical-decisions
12+
faq
1313

1414

1515

0 commit comments

Comments
 (0)