Skip to content

Commit a8c2187

Browse files
Merge pull request #118 from julienloizelet/feat/prepare-1-0-0
Feat/prepare 1 0 0
2 parents 71d10a8 + d6a3e9b commit a8c2187

19 files changed

+439
-222
lines changed

CHANGELOG.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
5-
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
6+
## Public API
7+
8+
The purpose of this section is to declare the public API of this library as required by [item 1 of semantic versioning specification](https://semver.org/spec/v2.0.0.html#spec-item-1).
9+
10+
The public API of this library consists of all public or protected methods, properties and constants belonging to the `src` folder.
11+
12+
---
13+
14+
## [1.0.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.0.0) - 2023-02-03
15+
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.36.0...v1.0.0)
16+
17+
### Changed
18+
- Change version to `1.0.0`: first stable release
19+
- Update `crowdsec/remediation-engine` to a new major version [2.0.0](https://github.com/crowdsecurity/php-remediation-engine/releases/tag/v2.0.0)
20+
- Use `crowdsec/common` [package](https://github.com/crowdsecurity/php-common) as a dependency for code factoring
21+
22+
### Added
23+
24+
- Add public API declaration
25+
26+
27+
---
628

729

830
## [0.36.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.36.0) - 2023-01-26

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
],
4141
"require": {
4242
"php": ">=7.2.5",
43-
"crowdsec/remediation-engine": "0.6.1",
43+
"crowdsec/remediation-engine": "^2.0.0",
44+
"crowdsec/common": "^1.2.0",
4445
"symfony/config": "^4.4.27 || ^5.2 || ^6.0",
4546
"twig/twig": "^3.4.2",
4647
"gregwar/captcha": "^1.1",

docs/DEVELOPER.md

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ cp .ddev/additional_docker_compose/docker-compose.crowdsec.yaml .ddev/docker-com
122122
cp .ddev/additional_docker_compose/docker-compose.playwright.yaml .ddev/docker-compose.playwright.yaml
123123
```
124124

125-
By default, ddev will launch a PHP 7.2 container. If you want to work with another PHP version, copy the
126-
corresponding config file. For example:
125+
By default, ddev will launch a PHP 7.2 container. If you want to work with another PHP version, copy the corresponding configuration file. For example:
127126

128127
```bash
129128
cd php-project-sources
@@ -142,7 +141,7 @@ This should take some times on the first launch as this will download all necess
142141

143142
#### Add CrowdSec bouncer and watcher
144143

145-
- To create a new bouncer in the crowdsec container, run:
144+
- To create a new bouncer in the CrowdSec container, run:
146145

147146
```bash
148147
ddev create-bouncer [name]
@@ -156,7 +155,7 @@ It will return the bouncer key.
156155
ddev create-watcher [name] [password]
157156
```
158157

159-
N.B : Since we are using TLS authentification for agent, you should avoid to create a watcher with this method.
158+
**N.B.** : Since we are using TLS authentication for agent, you should avoid to create a watcher with this method.
160159

161160

162161
#### Use composer to update or install the lib
@@ -177,8 +176,7 @@ To find it, just run:
177176
ddev find-ip
178177
```
179178

180-
You will have to know also the IP of the `ddev-router` container as it acts as a proxy, and you should set it in the
181-
`trust_ip_forward_array` setting.
179+
You will have to know also the IP of the `ddev-router` container as it acts as a proxy, and you should set it in the `trust_ip_forward_array` setting.
182180

183181
To find this IP, just run:
184182

@@ -191,7 +189,7 @@ ddev find-ip ddev-router
191189

192190

193191
```bash
194-
ddev php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit ./my-own-modules/crowdsec-php-lib/tests/Unit --testdox
192+
ddev php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit ./my-own-modules/crowdsec-php-lib/tests/Unit --testdox
195193
```
196194

197195
#### Integration test
@@ -203,7 +201,7 @@ ddev create-bouncer
203201
```
204202

205203
Then, as we use a TLS ready CrowdSec container, you have to copy some certificates and key:
206-
204+
207205
```bash
208206
cd php-project-sources
209207
mkdir cfssl
@@ -219,7 +217,7 @@ MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/
219217
```
220218

221219
For geolocation Unit Test, you should first put 2 free MaxMind databases in the `tests` folder : `GeoLite2-City.mmdb`
222-
and`GeoLite2-Country.mmdb`. You can download these databases by creating a maxmind account and browse to [the download page](https://www.maxmind.com/en/accounts/current/geoip/downloads).
220+
and `GeoLite2-Country.mmdb`. You can download these databases by creating a MaxMind account and browse to [the download page](https://www.maxmind.com/en/accounts/current/geoip/downloads).
223221

224222

225223
Then, you can run:
@@ -228,10 +226,10 @@ Then, you can run:
228226
ddev exec BOUNCER_KEY=your-bouncer-key AGENT_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 /usr/bin/php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib/tests/Integration/GeolocationTest.php
229227
```
230228

231-
**N.B**: If you want to test with `curl` instead of `file_get_contents` calls to LAPI, you have to add `USE_CURL=1` in
229+
**N.B.**: If you want to test with `curl` instead of `file_get_contents` calls to LAPI, you have to add `USE_CURL=1` in
232230
the previous commands.
233231

234-
**N.B**: If you want to test with `tls` authentification, you have to add `BOUNCER_TLS_PATH` environment variable
232+
**N.B**.: If you want to test with `tls` authentification, you have to add `BOUNCER_TLS_PATH` environment variable
235233
and specify the path where you store certificates and keys. For example:
236234

237235
```bash
@@ -241,21 +239,15 @@ ddev exec USE_CURL=1 AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/w
241239

242240
#### Auto-prepend mode (standalone mode)
243241

244-
Before using the bouncer in a standalone mode (i.e. with an auto-prepend directive), you should copy the
245-
[`scripts/auto-prepend/settings.example.php`](../scripts/auto-prepend/settings.example.php) file to a `scripts/auto-prepend/settings.
246-
php` and edit it depending on your needs.
247-
242+
Before using the bouncer in a standalone mode (i.e. with an auto-prepend directive), you should copy the [`scripts/auto-prepend/settings.example.php`](../scripts/auto-prepend/settings.example.php) file to a `scripts/auto-prepend/settings.php` and edit it depending on your needs.
248243

249-
Then, to configure the Nginx service in order that it uses an auto-prepend directive pointing to the
250-
[`scripts/auto-prepend/bounce.php`](../scripts/auto-prepend/bounce.php) script, please run the
251-
following command from the `.ddev` folder:
244+
Then, to configure the Nginx service in order that it uses an auto-prepend directive pointing to the [`scripts/auto-prepend/bounce.php`](../scripts/auto-prepend/bounce.php) script, please run the following command from the `.ddev` folder:
252245

253246
```bash
254247
ddev crowdsec-prepend-nginx
255248
```
256249

257-
With that done, every access to your ddev url (i.e. `https://phpXX.ddev.site` where `XX` is your php version) will
258-
be bounce.
250+
With that done, every access to your ddev url (i.e. `https://phpXX.ddev.site` where `XX` is your php version) will be bounce.
259251

260252
For example, you should try to browse the following url:
261253

@@ -269,14 +261,13 @@ In auto-prepend mode, you can run some end-to-end tests.
269261

270262
We are using a Jest/Playwright Node.js stack to launch a suite of end-to-end tests.
271263

272-
Tests code is in the `tests/end-to-end` folder. You should have to `chmod +x` the scripts you will find in
273-
`tests/end-to-end/__scripts__`.
264+
Tests code is in the `tests/end-to-end` folder. You should have to `chmod +x` the scripts you will find in `tests/end-to-end/__scripts__`.
274265

275266

276267
Then you can use the `run-test.sh` script to run the tests:
277268

278269
- the first parameter specifies if you want to run the test on your machine (`host`) or in the
279-
docker containers (`docker`). You can also use `ci` if you want to have the same behavior as in Github action.
270+
docker containers (`docker`). You can also use `ci` if you want to have the same behavior as in GitHub action.
280271
- the second parameter list the test files you want to execute. If empty, all the test suite will be launched.
281272

282273
For example:
@@ -285,8 +276,7 @@ For example:
285276
./run-tests.sh docker "./__tests__/1-live-mode.js"
286277
./run-tests.sh host
287278

288-
Before testing with the `docker` or `ci` parameter, you have to install all the required dependencies
289-
in the playwright container with this command :
279+
Before testing with the `docker` or `ci` parameter, you have to install all the required dependencies in the playwright container with this command :
290280

291281
./test-init.sh
292282

@@ -299,18 +289,15 @@ yarn global add cross-env
299289

300290
#### Coding standards
301291

302-
We set up some coding standards tools that you will find in the `tools/coding-standards` folder.
303-
In order to use these, you will need to work with a PHP version >= 7.4 and run first:
292+
We set up some coding standards tools that you will find in the `tools/coding-standards` folder. In order to use these, you will need to work with a PHP version >= 7.4 and run first:
304293

305294
```
306295
ddev composer update --working-dir=./my-own-modules/crowdsec-php-lib/tools/coding-standards
307296
```
308297

309298
##### PHPCS Fixer
310299

311-
We are using the [PHP Coding Standards Fixer](https://cs.symfony.com/)
312-
313-
With ddev, you can do the following:
300+
We are using the [PHP Coding Standards Fixer](https://cs.symfony.com/). With ddev, you can do the following:
314301

315302

316303
```bash
@@ -386,8 +373,6 @@ ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key LAPI_URL=https://cro
386373
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-own-modules/crowdsec-php-lib/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./my-own-modules/crowdsec-php-lib/tools/coding-standards/phpunit/code-coverage/report.txt
387374
```
388375

389-
390-
391376
#### Generate CrowdSec tools and settings on start
392377

393378
We use a post-start DDEV hook to:
@@ -400,7 +385,7 @@ Just copy the file and restart:
400385
```bash
401386
cp .ddev/config_overrides/config.crowdsec.yaml .ddev/config.crowdsec.yaml
402387
ddev restart
403-
```
388+
```
404389

405390
#### Redis debug
406391

@@ -452,7 +437,7 @@ the max number of keys to dump:
452437

453438
You will find some php scripts in the `scripts` folder.
454439

455-
**N.B** : If you are not using DDEV, you can replace all `ddev exec php ` by `php` and specify the right script paths.
440+
**N.B**. : If you are not using DDEV, you can replace all `ddev exec php ` by `php` and specify the right script paths.
456441

457442
### Clear cache script
458443

@@ -479,7 +464,7 @@ ddev start
479464
Then get a bouncer API key by copying the result of:
480465

481466
```bash
482-
ddev create-bouncer`
467+
ddev create-bouncer
483468
```
484469

485470
#### Get the remediation the clean IP "1.2.3.4"
@@ -527,7 +512,7 @@ through a certain URL (e.g. `https://crowdsec:8080`).
527512
Please refer to the [CrowdSec cscli documentation](https://docs.crowdsec.net/docs/cscli/cscli/) for an exhaustive
528513
list of commands.
529514

530-
**N.B**: If you are using DDEV, just replace `cscli` with `ddev exec -s crowdsec cscli`.
515+
**N.B**.: If you are using DDEV, just replace `cscli` with `ddev exec -s crowdsec cscli`.
531516

532517
Here is a list of command that we often use to test the PHP library:
533518

@@ -559,7 +544,7 @@ cscli decisions delete --all
559544
```
560545
- Delete a decision with an IP scope
561546
```bash
562-
cscli decisions delete -i <SOME_IP>>
547+
cscli decisions delete -i <SOME_IP>
563548
```
564549

565550
#### Create a bouncer
@@ -591,9 +576,7 @@ ddev create-watcher <SOME_LOGIN> <SOME_PASSWORD>
591576

592577
### Use the web container to call LAPI
593578

594-
Please see the [CrowdSec LAPI documentation](https://crowdsecurity.github.io/api_doc/index.html?urls.primaryName=LAPI)
595-
for an
596-
exhaustive list of available calls.
579+
Please see the [CrowdSec LAPI documentation](https://crowdsecurity.github.io/api_doc/index.html?urls.primaryName=LAPI) for an exhaustive list of available calls.
597580

598581
If you are using DDEV, you can enter the web by running:
599582

@@ -619,16 +602,18 @@ In order to have an explicit commit history, we are using some commits message c
619602
<type>(<scope>): <subject>
620603

621604
Allowed `type` are defined below.
605+
622606
`scope` value intends to clarify which part of the code has been modified. It can be empty or `*` if the change is a
623607
global or difficult to assign to a specific part.
608+
624609
`subject` describes what has been done using the imperative, present tense.
625610

626611
Example:
627612

628613
feat(admin): Add css for admin actions
629614

630615

631-
You can use the `commit-msg` git hook that you will find in the `.githooks` folder :
616+
You can use the `commit-msg` git hook that you will find in the `.githooks` folder:
632617

633618
```
634619
cp .githooks/commit-msg .git/hooks/commit-msg
@@ -678,6 +663,3 @@ gh workflow run release.yml -f tag_name=vx.y.z
678663
```
679664

680665
Note that the GitHub action will fail if the tag `tag_name` already exits.
681-
682-
683-

docs/INSTALLATION_GUIDE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
## Requirements
1919

2020
- PHP >= 7.2.5
21-
- required php extensions: `ext-json`, `ext-gd`
22-
- suggested php extension: `ext-curl`
21+
- required PHP extensions: `ext-json`, `ext-gd`
22+
- suggested PHP extension: `ext-curl`
2323

2424
## Installation
2525

2626
Use `Composer` by simply adding `crowdsec/bouncer` as a dependency:
2727

28-
composer require crowdsec/bouncer
29-
30-
28+
```shell
29+
composer require crowdsec/bouncer
30+
```

docs/TECHNICAL_NOTES.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,33 @@
1919
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2020

2121

22-
We explain here each important technical decision used to design this
23-
library.
22+
We explain here each important technical decision used to design this library.
2423

2524
## Why use *Symfony/Cache* and *Symfony/Config* component?
2625

2726
The Cache component is compatible with many cache systems.
2827

29-
The Config component provides several classes to help you find, load,
30-
combine, fill and validate configuration values of any kind, whatever
31-
their source may be (YAML, XML, INI files, or for instance a database).
32-
A great job done by this library, tested and maintained under LTS
33-
versions.
28+
The Config component provides several classes to help you find, load, combine, fill and validate configuration values of any kind, whatever their source may be (YAML, XML, INI files, or for instance a database). A great job done by this library, tested and maintained under LTS versions.
3429

3530
This library is tested and maintained under LTS versions.
3631

3732
## Why not using Guzzle?
3833

39-
The last Guzzle versions remove the User-Agent to prevent risks. Since
40-
LAPI or CAPI need a valid User-Agent, we can not use Guzzle to request
41-
CAPI/LAPI.
34+
The last Guzzle versions remove the User-Agent to prevent risks. Since LAPI or CAPI need a valid User-Agent, we can not use Guzzle to request CAPI/LAPI.
4235

4336
## Why not using Swagger Codegen?
4437

45-
We were not able to use this client with ease ex: impossible to get
46-
JSON data, it seems there is a bug with unserialization, we received
47-
an empty array.
38+
We were not able to use this client with ease ex: impossible to get JSON data, it seems there is a bug with unserialization, we received an empty array.
4839

4940
## Which PHP compatibility matrix?
5041

5142
### Why not PHP 5.6?
5243

53-
Because this PHP version is no more supported since December 2018 (not even a security fix).
54-
Also, a lot of libraries are no more compatible with this version.
55-
We don't want to use an older version of these libraries because Composer can only install one version of each extension/package.
56-
So, being compatible with this old PHP version means to be not compatible with projects using a new version of these libraries.
44+
Because this PHP version is no more supported since December 2018 (not even a security fix). Also, a lot of libraries are no more compatible with this version. We don't want to use an older version of these libraries because Composer can only install one version of each extension/package. So, being compatible with this old PHP version means to be not compatible with projects using a new version of these libraries.
5745

5846
### Why not 7.0.x nor 7.1.x ?
5947

60-
These PHP versions are not anymore maintained for security fixes since 2019. We encourage you a lot to upgrade your
61-
PHP version. You can view the [full list of PHP versions lifecycle](https://www.php.net/supported-versions.php).
48+
These PHP versions are not anymore maintained for security fixes since 2019. We encourage you a lot to upgrade your PHP version. You can view the [full list of PHP versions lifecycle](https://www.php.net/supported-versions.php).
6249

6350
To get a robust library and not provide security bug unmaintained, we use [components](https://packagist.org/packages/symfony/cache#v3.4.47) under [LTS versioning](https://symfony.com/releases/3.4).
6451

0 commit comments

Comments
 (0)