Skip to content

Commit f21026f

Browse files
feat(*): Remove configurations that are used as settings and not configs
1 parent 801c5c6 commit f21026f

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

docs/configuration-reference.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Full configuration reference
22

33
```php
4+
use CrowdSecBouncer\StandAloneBounce;
45
$config = [
56
// Required. The bouncer api key to access LAPI or CAPI.
67
'api_key'=> 'YOUR_BOUNCER_API_KEY',
@@ -14,13 +15,13 @@
1415
// Optional. In seconds. The timeout when calling CAPI/LAPI. Defaults to 1 sec.
1516
'api_timeout'=> 1,
1617

17-
// Optional. Select from 'bouncing_disabled', 'normal_bouncing' or 'flex_bouncing'. Default to 'normal_bouncing'
18+
// Optional. Select from 'bouncing_disabled', 'normal_bouncing' or 'flex_bouncing'.
1819
'bouncing_level' => 'normal_bouncing',
1920

2021
// Optional. Absolute path to store log files.
2122
'log_directory_path' => __DIR__.'/.logs',
2223

23-
// Optional. Select from 'phpfs' (File system cache), 'redis' or 'memcached'. Default to 'phpcs'
24+
// Optional. Select from 'phpfs' (File system cache), 'redis' or 'memcached'.
2425
'cache_system' => 'phpfs',
2526

2627
// Optional. Will be used only if you choose File system as cache_system
@@ -34,19 +35,18 @@
3435

3536
// Optional. If you use a CDN, a reverse proxy or a load balancer, set an array of IPs.
3637
// For other IPs, the bouncer will not trust the X-Forwarded-For header.
37-
// Default to empty array
3838
'trust_ip_forward_array' => [],
3939

4040
// Optional. true to enable stream mode, true to enable the stream mode. Default to false.
4141
'stream_mode'=> false,
4242

43-
// Optional. true to enable verbose debug log. Default to false
43+
// Optional. true to enable verbose debug log.
4444
'debug_mode' => false,
4545

46-
// Optional. true to stop the process and display errors if any. Default to false.
46+
// Optional. true to stop the process and display errors if any.
4747
'display_errors' => false,
4848

49-
// Optional. true to hide CrowdSec mentions on ban and captcha walls. Default to false.
49+
// Optional. true to hide CrowdSec mentions on ban and captcha walls.
5050
'hide_mentions' => false,
5151

5252
// Optional. Only for test or debug purpose.
@@ -93,6 +93,7 @@
9393
]
9494
]
9595
]
96-
$bouncer = new Bouncer();
97-
$bouncer->configure($config);
96+
$bouncer = new StandAloneBounce();
97+
$bouncer->init($config);
98+
$bouncer->safelyBounce();
9899
```

src/Configuration.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder
3333
->scalarNode('api_user_agent')->defaultValue(Constants::BASE_USER_AGENT)->end()
3434
->integerNode('api_timeout')->defaultValue(Constants::API_TIMEOUT)->end()
3535
->booleanNode('stream_mode')->defaultValue(false)->end()
36-
->booleanNode('debug_mode')->defaultValue(false)->end()
37-
->booleanNode('display_errors')->defaultValue(false)->end()
38-
->booleanNode('hide_mentions')->defaultValue(false)->end()
3936
->scalarNode('forced_test_ip')->defaultValue('')->end()
40-
->scalarNode('log_directory_path')->end()
41-
->enumNode('bouncing_level')
42-
->values([Constants::BOUNCING_LEVEL_DISABLED, Constants::BOUNCING_LEVEL_NORMAL, Constants::BOUNCING_LEVEL_FLEX])
43-
->defaultValue(Constants::BOUNCING_LEVEL_NORMAL)
44-
->end()
45-
->enumNode('cache_system')
46-
->values([Constants::CACHE_SYSTEM_PHPFS, Constants::CACHE_SYSTEM_REDIS, Constants::CACHE_SYSTEM_MEMCACHED])
47-
->defaultValue(Constants::CACHE_SYSTEM_PHPFS)
48-
->end()
49-
->scalarNode('fs_cache_path')->end()
50-
->scalarNode('redis_dsn')->end()
51-
->scalarNode('memcached_dsn')->end()
52-
->arrayNode('trust_ip_forward_array')->defaultValue([])->end()
5337
->enumNode('max_remediation_level')
5438
->values(Constants::ORDERED_REMEDIATIONS)
5539
->defaultValue(Constants::REMEDIATION_BAN)

src/StandAloneBounce.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public function getBouncerInstance(): Bouncer
104104
}
105105

106106
// Parse options.
107-
108107
if (empty($this->getStringSettings('api_url'))) {
109108
throw new BouncerException('Bouncer enabled but no API URL provided');
110109
}
@@ -120,20 +119,19 @@ public function getBouncerInstance(): Bouncer
120119
$forcedTestIp = $this->getStringSettings('forced_test_ip');
121120

122121
// Init Bouncer instance
123-
124122
switch ($bouncingLevel) {
125-
case Constants::BOUNCING_LEVEL_DISABLED:
126-
$maxRemediationLevel = Constants::REMEDIATION_BYPASS;
127-
break;
128-
case Constants::BOUNCING_LEVEL_FLEX:
129-
$maxRemediationLevel = Constants::REMEDIATION_CAPTCHA;
130-
break;
131-
case Constants::BOUNCING_LEVEL_NORMAL:
132-
$maxRemediationLevel = Constants::REMEDIATION_BAN;
133-
break;
134-
default:
135-
throw new BouncerException("Unknown $bouncingLevel");
136-
}
123+
case Constants::BOUNCING_LEVEL_DISABLED:
124+
$maxRemediationLevel = Constants::REMEDIATION_BYPASS;
125+
break;
126+
case Constants::BOUNCING_LEVEL_FLEX:
127+
$maxRemediationLevel = Constants::REMEDIATION_CAPTCHA;
128+
break;
129+
case Constants::BOUNCING_LEVEL_NORMAL:
130+
$maxRemediationLevel = Constants::REMEDIATION_BAN;
131+
break;
132+
default:
133+
throw new BouncerException("Unknown $bouncingLevel");
134+
}
137135

138136
// Instantiate the bouncer
139137
try {

0 commit comments

Comments
 (0)