Skip to content

Commit

Permalink
style(*): Use constants for header names
Browse files Browse the repository at this point in the history
  • Loading branch information
julienloizelet committed Sep 6, 2024
1 parent b5ade8f commit a6c9c69
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ As far as possible, we try to adhere to [Symfony guidelines](https://symfony.com

### Added

- Add App Sec requests support
- Add AppSec requests support


---
Expand Down
14 changes: 8 additions & 6 deletions src/Client/HttpMessage/AppSecRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace CrowdSec\Common\Client\HttpMessage;

use CrowdSec\Common\Constants;

/**
* Request that will be sent to CrowdSec AppSec component.
*
Expand All @@ -24,12 +26,12 @@ class AppSecRequest extends Request
* @var string[]
*/
protected $requiredHeaders = [
'X-Crowdsec-Appsec-Ip',
'X-Crowdsec-Appsec-User-Agent',
'X-Crowdsec-Appsec-Verb',
'X-Crowdsec-Appsec-Uri',
'X-Crowdsec-Appsec-Host',
'X-Crowdsec-Appsec-Api-Key',
Constants::HEADER_APPSEC_IP,
Constants::HEADER_APPSEC_USER_AGENT,
Constants::HEADER_APPSEC_VERB,
Constants::HEADER_APPSEC_URI,
Constants::HEADER_APPSEC_HOST,
Constants::HEADER_APPSEC_API_KEY,
];
/**
* @var string
Expand Down
3 changes: 2 additions & 1 deletion src/Client/HttpMessage/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CrowdSec\Common\Client\HttpMessage;

use CrowdSec\Common\Client\ClientException;
use CrowdSec\Common\Constants;

/**
* Request that will be sent to CrowdSec.
Expand All @@ -29,7 +30,7 @@ class Request extends AbstractMessage
* @var string[]
*/
protected $requiredHeaders = [
'User-Agent',
Constants::HEADER_LAPI_USER_AGENT,
];
/**
* @var string
Expand Down
32 changes: 32 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,38 @@ class Constants
* @var int The CrowdSec TTL for decisions (in seconds)
*/
public const DURATION = 86400;
/**
* @var string The AppSec API key header name
*/
public const HEADER_APPSEC_API_KEY = 'X-Crowdsec-Appsec-Api-Key';
/**
* @var string The AppSec host header name
*/
public const HEADER_APPSEC_HOST = 'X-Crowdsec-Appsec-Host';
/**
* @var string The AppSec IP header name
*/
public const HEADER_APPSEC_IP = 'X-Crowdsec-Appsec-Ip';
/**
* @var string The AppSec URI header name
*/
public const HEADER_APPSEC_URI = 'X-Crowdsec-Appsec-Uri';
/**
* @var string The AppSec User-Agent header name
*/
public const HEADER_APPSEC_USER_AGENT = 'X-Crowdsec-Appsec-User-Agent';
/**
* @var string The AppSec verb header name
*/
public const HEADER_APPSEC_VERB = 'X-Crowdsec-Appsec-Verb';
/**
* @var string The LAPI API key header name
*/
public const HEADER_LAPI_API_KEY = 'X-Api-Key';
/**
* @var string The LAPI User-Agent header name
*/
public const HEADER_LAPI_USER_AGENT = 'User-Agent';
/**
* @var string The ISO8601 date regex
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/MockedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class MockedData
EOT;

public const APPSEC_ALLOWED = <<<EOT
{"action":"allow"}
{"action":"allow","http_status":200}
EOT;
}
2 changes: 1 addition & 1 deletion tests/Unit/AbstractClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testPrivateOrProtectedMethods()
$this->assertEquals(
Constants::APPSEC_URL . '/',
$appSecUrl,
'App Sec Url should be ok'
'AppSec Url should be ok'
);
// formatResponseBody
$jsonBody = json_encode(['message' => 'ok']);
Expand Down

0 comments on commit a6c9c69

Please sign in to comment.