Skip to content

Commit

Permalink
feat(*): Add timeout settings, encrypt bouncer key and remove events …
Browse files Browse the repository at this point in the history
…log feature (#22)

* feat(timeout): Add timeout settings

* ci(*): Update magento install action

* ci(endtoend): Fix relative path for playwright

* test(curl): Update message on success

* feat(cache): Add crowdsec/magento-symfony-cache 3.0.0 as possible dependency

* feat(security): Encrypt bouncer api key in database

* test(end to end): Modify the way to retrieve bouncer key

* feat(events): Remove all events feature

* ci(*): Add scheduled test

* style(*): Pass through coding standards

* feat(*): Prepare release 2.1.0

* style(*): Remove useless import
  • Loading branch information
julienloizelet authored Jan 4, 2024
1 parent a17c398 commit 5cecfff
Show file tree
Hide file tree
Showing 55 changed files with 640 additions and 2,338 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/end-to-end-auto-prepend-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
steps:

- name: Install Magento 2 with DDEV
uses: julienloizelet/[email protected].0
uses: julienloizelet/[email protected].1
with:
php_version: ${{ matrix.php-version }}
magento_version: ${{ matrix.m2-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/end-to-end-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
steps:

- name: Install Magento 2 with DDEV
uses: julienloizelet/[email protected].0
uses: julienloizelet/[email protected].1
with:
php_version: ${{ matrix.php-version }}
magento_version: ${{ matrix.m2-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/installation-and-varnish-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

steps:
- name: Install Magento 2 with DDEV
uses: julienloizelet/[email protected].0
uses: julienloizelet/[email protected].1
id: magento2-install
with:
php_version: ${{ matrix.php-version }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/keepalive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Keep Alive
on:

schedule:
- cron: '0 3 * * 4'

permissions:
contents: write

jobs:
keep-alive:

name: Keep Alive
runs-on: ubuntu-latest

steps:

- name: Clone project files
uses: actions/checkout@v3

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
- uses: gautamkrishnar/keepalive-workflow@v1
with:
commit_message: "chore(*): Automated commit to keep the repository active"
time_elapsed: 50
4 changes: 3 additions & 1 deletion .github/workflows/static-and-unit-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
- main
paths-ignore:
- '**.md'
schedule:
- cron: '25 02 * * THU'
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -39,7 +41,7 @@ jobs:

steps:
- name: Install Magento 2 with DDEV
uses: julienloizelet/[email protected].0
uses: julienloizelet/[email protected].1
with:
php_version: ${{ matrix.php-version }}
magento_version: ${{ matrix.m2-version }}
Expand Down
35 changes: 35 additions & 0 deletions Block/Adminhtml/System/Config/Connection/Ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ class Ping extends Button
*/
protected $_useCurlField = 'crowdsec_bouncer_general_connection_use_curl';

/**
* Api timeout field name
*
* @var string
*/
protected $_apiTimeoutField = 'crowdsec_bouncer_general_connection_api_timeout';

/**
* Api connect timeout field name
*
* @var string
*/
protected $_apiConnectTimeoutField = 'crowdsec_bouncer_general_connection_api_connect_timeout';

/** @var string */
protected $template = 'CrowdSec_Bouncer::system/config/connection/ping.phtml';
/** @var string */
Expand Down Expand Up @@ -174,11 +188,32 @@ public function getUseCurlField(): string
return $this->_useCurlField;
}

/**
* Get api timeout field Name
*
* @return string
*/
public function getApiTimeoutField(): string
{
return $this->_apiTimeoutField;
}

/**
* Get api connect timeout field Name
*
* @return string
*/
public function getApiConnectTimeoutField(): string
{
return $this->_apiConnectTimeoutField;
}

/**
* Get the button and scripts contents
*
* @param AbstractElement $element
* @return string
* @throws \InvalidArgumentException
*/
protected function _getElementHtml(AbstractElement $element): string
{
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ All notable changes to this project will be documented in this file.
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).

The [public API](https://semver.org/spec/v2.0.0.html#spec-item-1) for this project is defined by the set of
functions provided by the module.


## [2.1.0](https://github.com/crowdsecurity/cs-magento-bouncer/releases/tag/v2.1.0) - 2024-01-??
[_Compare with previous release_](https://github.com/crowdsecurity/cs-magento-bouncer/compare/v2.0.0...v2.1.0)


### Changed

- Encrypt bouncer key in database

### Removed

- Removed Events log feature

### Added

- Add `api_connect_timeout` configuration for `Curl` request handler
- Add `api_timeout` configuration

### Fixed

- Allow `crowdsec/symfony-cache:3.0.0` dependency to avoid composer conflict with some Magento 2.4.6 patch versions

---


## [2.0.0](https://github.com/crowdsecurity/cs-magento-bouncer/releases/tag/v2.0.0) - 2023-03-23
[_Compare with previous release_](https://github.com/crowdsecurity/cs-magento-bouncer/compare/v1.5.0...v2.0.0)

Expand Down
2 changes: 1 addition & 1 deletion Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Constants extends LibConstants
{

/** @var string The last version of this library */
public const VERSION = 'v2.0.0';
public const VERSION = 'v2.1.0';

/** @var string The user agent used to send request to Local API */
public const BASE_USER_AGENT = 'Magento 2 CrowdSec Bouncer/'.self::VERSION;
Expand Down
61 changes: 50 additions & 11 deletions Controller/Adminhtml/System/Config/Connection/Ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,47 @@ class Ping extends Action implements HttpPostActionInterface
protected $helper;

/**
* Constructor method.
*
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param RegistryBouncer $registryBouncer
* @param Helper $helper
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
Context $context,
JsonFactory $resultJsonFactory,
RegistryBouncer $registryBouncer,
Helper $helper
Helper $helper
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->registryBouncer = $registryBouncer;
$this->helper = $helper;
}

/**
* Create main suffixe message
*
* @param string $authType
* @param bool $useCurl
* @return string
*/
private function getMainSuffixeMessage(string $authType, bool $useCurl): string
{
$suffixMessageMain = ($authType === Constants::AUTH_TLS) ?
'Auth type: TLS <br>Url: %1 <br>Cert: %2 <br>Key: %3 <br>Verify peer: %4 <br>
CA cert: %5 <br>Use cURL: %6 <br>Api timeout: %7' :
'Auth type: Api key <br>Url: %1 <br>Api key: %2<br>Use cURL: %3 <br>Api timeout: %4';

if ($useCurl) {
$suffixMessageMain .= ($authType === Constants::AUTH_TLS) ? ' <br>
Api connection timeout: %8' : ' <br>Api connection timeout: %5';
}

return $suffixMessageMain;
}

/**
* Test connection
*
Expand All @@ -83,7 +107,9 @@ public function execute(): Json
{
$useCurl = "";
$tlsVerifyPeer = "";
$authType ="";
$authType = "";
$apiTimeout = "";
$apiConnectTimeout = "";
try {
$baseUri = $this->getRequest()->getParam('api_url');
$authType = $this->getRequest()->getParam('auth_type');
Expand All @@ -93,8 +119,13 @@ public function execute(): Json
$tlsCaCert =
($authType === Constants::AUTH_TLS) ? $this->getRequest()->getParam('tls_ca_cert_path', "") : "";
$userAgent = Constants::BASE_USER_AGENT;
$apiKey = ($authType === Constants::AUTH_KEY) ? $this->getRequest()->getParam('bouncer_key') : "";
$apiKey = ($authType === Constants::AUTH_KEY) ?
$this->getRequest()->getParam('bouncer_key')
: "";
$useCurl = (bool)$this->getRequest()->getParam('use_curl', false);
$apiTimeout = (int)$this->getRequest()->getParam('api_timeout', Constants::API_TIMEOUT);
$apiConnectTimeout =
(int)$this->getRequest()->getParam('api_connect_timeout', Constants::API_CONNECT_TIMEOUT);
$configs = $this->helper->getBouncerConfigs();
$currentConfigs = [
'api_url' => $baseUri,
Expand All @@ -105,10 +136,12 @@ public function execute(): Json
'tls_ca_cert_path' => $this->helper->getVarFullPath($tlsCaCert),
'api_user_agent' => $userAgent,
'api_key' => $apiKey,
'use_curl' => $useCurl
'use_curl' => $useCurl,
'api_timeout' => $apiTimeout,
'api_connect_timeout' => $apiConnectTimeout,
];

$useCurl = $useCurl ? __('true') : __('false');
$useCurlMessage = $useCurl ? __('true') : __('false');
$tlsVerifyPeer = $tlsVerifyPeer ? __('true') : __('false');
$finalConfigs = array_merge($configs, $currentConfigs);
$bouncer = $this->registryBouncer->create([
Expand All @@ -133,19 +166,25 @@ public function execute(): Json

$resultJson = $this->resultJsonFactory->create();

$suffixMessageMain = $this->getMainSuffixeMessage($authType, $useCurl);

$suffixMessage = ($authType === Constants::AUTH_TLS) ? '<br><br>' . __(
'Auth type: TLS <br>Url: %1<br>Cert: %2<br>Key: %3<br>Verify peer: %4<br>CA cert: %5<br>Use cURL: %6',
$suffixMessageMain,
$baseUri ?? "",
$tlsCert ?? "",
$tlsKey ?? "",
$tlsVerifyPeer,
$tlsCaCert ?? "",
$useCurl
$useCurlMessage ?? "",
$apiTimeout,
$apiConnectTimeout
) : '<br><br>' . __(
'Auth type: Api key <br>Url: %1 <br>Api key: %2<br>Use cURL: %3',
$suffixMessageMain,
$baseUri ?? "",
$apiKey ?? "",
$useCurl
$useCurlMessage ?? "",
$apiTimeout,
$apiConnectTimeout
);

return $resultJson->setData([
Expand Down
Loading

0 comments on commit 5cecfff

Please sign in to comment.