Skip to content

Commit 8bb6eaa

Browse files
feat(geolocation): Add config for geolocation
1 parent aeb9733 commit 8bb6eaa

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

src/Configuration.php

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Config\Definition\ConfigurationInterface;
88

99
/**
10-
* The Library configuration. You'll find here all configuration possible. Used when instanciating the library.
10+
* The Library configuration. You'll find here all configuration possible. Used when instantiating the library.
1111
*
1212
* @author CrowdSec team
1313
*
@@ -21,32 +21,54 @@ class Configuration implements ConfigurationInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function getConfigTreeBuilder()
24+
public function getConfigTreeBuilder(): TreeBuilder
2525
{
2626
$treeBuilder = new TreeBuilder('config');
2727
/** @var $rootNode ArrayNodeDefinition */
2828
$rootNode = $treeBuilder->getRootNode();
2929
$rootNode
3030
->children()
31-
->scalarNode('api_key')->isRequired()->end()
32-
->scalarNode('api_url')->defaultValue(Constants::CAPI_URL)->end()
33-
->scalarNode('api_user_agent')->defaultValue(Constants::BASE_USER_AGENT)->end()
34-
->integerNode('api_timeout')->defaultValue(Constants::API_TIMEOUT)->end()
35-
->booleanNode('live_mode')->defaultValue(true)->end()
36-
->enumNode('max_remediation_level')
37-
->values(Constants::ORDERED_REMEDIATIONS)
38-
->defaultValue(Constants::REMEDIATION_BAN)
39-
->end()
40-
->enumNode('fallback_remediation')
41-
->values(Constants::ORDERED_REMEDIATIONS)
42-
->defaultValue(Constants::REMEDIATION_CAPTCHA)
43-
->end()
44-
->integerNode('cache_expiration_for_clean_ip')
45-
->defaultValue(Constants::CACHE_EXPIRATION_FOR_CLEAN_IP)
46-
->end()
47-
->integerNode('cache_expiration_for_bad_ip')
48-
->defaultValue(Constants::CACHE_EXPIRATION_FOR_BAD_IP)
49-
->end()
31+
->scalarNode('api_key')->isRequired()->end()
32+
->scalarNode('api_url')->defaultValue(Constants::CAPI_URL)->end()
33+
->scalarNode('api_user_agent')->defaultValue(Constants::BASE_USER_AGENT)->end()
34+
->integerNode('api_timeout')->defaultValue(Constants::API_TIMEOUT)->end()
35+
->booleanNode('live_mode')->defaultValue(true)->end()
36+
->enumNode('max_remediation_level')
37+
->values(Constants::ORDERED_REMEDIATIONS)
38+
->defaultValue(Constants::REMEDIATION_BAN)
39+
->end()
40+
->enumNode('fallback_remediation')
41+
->values(Constants::ORDERED_REMEDIATIONS)
42+
->defaultValue(Constants::REMEDIATION_CAPTCHA)
43+
->end()
44+
->integerNode('cache_expiration_for_clean_ip')
45+
->defaultValue(Constants::CACHE_EXPIRATION_FOR_CLEAN_IP)
46+
->end()
47+
->integerNode('cache_expiration_for_bad_ip')
48+
->defaultValue(Constants::CACHE_EXPIRATION_FOR_BAD_IP)
49+
->end()
50+
->arrayNode('geolocation')
51+
->addDefaultsIfNotSet()
52+
->children()
53+
->booleanNode('enabled')
54+
->isRequired()
55+
->defaultFalse()
56+
->end()
57+
->enumNode('type')
58+
->isRequired()
59+
->defaultValue(Constants::GEOLOCATION_TYPE_MAXMIND)
60+
->values([Constants::GEOLOCATION_TYPE_MAXMIND])
61+
->end()
62+
->arrayNode(Constants::GEOLOCATION_TYPE_MAXMIND)
63+
->addDefaultsIfNotSet()
64+
->children()
65+
->scalarNode('database_path')
66+
->cannotBeEmpty()
67+
->end()
68+
->end()
69+
->end()
70+
->end()
71+
->end()
5072
->end();
5173

5274
return $treeBuilder;

src/Constants.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace CrowdSecBouncer;
66

77
/**
8-
* Every constants of the library are set here.
8+
* Every constant of the library are set here.
99
*
1010
* @author CrowdSec team
1111
*
@@ -63,4 +63,7 @@ class Constants
6363

6464
/** @var string The "MEMCACHED" cache system */
6565
public const CACHE_SYSTEM_MEMCACHED = 'memcached';
66+
67+
/** @var string The "MaxMind" geolocation type */
68+
public const GEOLOCATION_TYPE_MAXMIND = 'maxmind';
6669
}

0 commit comments

Comments
 (0)