Skip to content

Commit

Permalink
feat(config): Add api_connect_timeout setting (#13)
Browse files Browse the repository at this point in the history
* feat(config): Add api_connect_timeout setting

* feat(*): Prepare for v3.2.0
  • Loading branch information
julienloizelet authored Dec 7, 2023
1 parent ac15b04 commit 5d6f6fc
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ -z "$1" ]; then
exit 1
fi

commitTitle="$(cat $1 | head -n1)"
commitTitle="$(head -n 1 < "$1")"

# ignore merge
if echo "$commitTitle" | grep -qE "^Merge"; then
Expand All @@ -15,7 +15,7 @@ fi

# check commit message
REGEX='^(feat|fix|docs|style|refactor|ci|test|chore|comment)\(.*\)\:.*'
if ! echo "$commitTitle" | grep -qE ${REGEX}; then
if ! echo "$commitTitle" | grep -qE "${REGEX}"; then
echo "Your commit title '$commitTitle' did not follow conventional commit message rules:"
echo "Please comply with the regex ${REGEX}"
exit 1
Expand Down
44 changes: 19 additions & 25 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']

name: Coding standards test
runs-on: ubuntu-latest
Expand All @@ -29,35 +29,29 @@ jobs:
EXTENSION_PATH: "my-code/lapi-client"

steps:
- name: Clone DDEV files
uses: actions/checkout@v3
with:
path: .ddev
repository: julienloizelet/ddev-php
ref: "main"

- name: Install DDEV
env:
DDEV_VERSION: v1.21.4
run: |
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
sudo apt-get -qq update
sudo apt-get -qq -y install libnss3-tools
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
bash install_ddev.sh ${{env.DDEV_VERSION}}
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
rm install_ddev.sh
- name: Set PHP_VERSION_CODE env
# used in some directory path and conventional file naming
# Example : 7.4 => php74
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Create empty PHP DDEV project
run: ddev config --project-type=php --project-name=crowdsec-lapi-client --php-version=${{ matrix.php-version }}

- name: Add-ons install
run: ddev get julienloizelet/ddev-tools

- name: Add Redis, Memcached and X-Debug
if: ${{ matrix.php-version == '8.3' }}
run: |
echo "PHP_VERSION_CODE=$(echo php${{ matrix.php-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
cp .ddev/okaeli-add-on/common/custom_files/config.php83missing.yaml .ddev/config.php83missing.yaml
- name: Start DDEV with PHP ${{ matrix.php-version }}
run: |
cp .ddev/config_overrides/config.${{ env.PHP_VERSION_CODE }}.yaml .ddev/config.${{ env.PHP_VERSION_CODE }}.yaml
ddev start
run: ddev start

- name: Some DEBUG information
run: |
Expand Down Expand Up @@ -95,4 +89,4 @@ jobs:
run: |
ddev xdebug
ddev php -dxdebug.mode=coverage ./${{env.EXTENSION_PATH}}/tools/coding-standards/vendor/bin/phpunit --configuration ./${{env.EXTENSION_PATH}}/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt
cat ${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt
cat ${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt
52 changes: 25 additions & 27 deletions .github/workflows/unit-and-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.2','7.3','7.4','8.0','8.1', '8.2']
php-version: ['7.2','7.3','7.4','8.0','8.1', '8.2', '8.3']

name: Unit and integration test
runs-on: ubuntu-latest
Expand All @@ -33,38 +33,36 @@ jobs:
EXTENSION_PATH: "my-code/lapi-client"

steps:
- name: Clone DDEV files
uses: actions/checkout@v3
with:
path: .ddev
repository: julienloizelet/ddev-php
ref: "main"

- name: Install DDEV
env:
DDEV_VERSION: v1.21.4
run: |
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures
sudo apt-get -qq update
sudo apt-get -qq -y install libnss3-tools
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
bash install_ddev.sh ${{env.DDEV_VERSION}}
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
rm install_ddev.sh
- name: Set PHP_VERSION_CODE env
# used in some directory path and conventional file naming
# Example : 7.4 => 74
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Create empty PHP DDEV project
run: ddev config --project-type=php --project-name=crowdsec-lapi-client --php-version=${{ matrix.php-version }}

- name: Add-ons install
run: |
echo "PHP_VERSION_CODE=$(echo php${{ matrix.php-version }} | sed 's/\.//g' )" >> $GITHUB_ENV
ddev get julienloizelet/ddev-tools
ddev get julienloizelet/ddev-crowdsec-php
- name: Start DDEV with PHP ${{ matrix.php-version }}
- name: Add Redis, Memcached and X-Debug
if: ${{ matrix.php-version == '8.3' }}
run: |
cp .ddev/okaeli-add-on/common/custom_files/config.php83missing.yaml .ddev/config.php83missing.yaml
- name: Prepare for TLS tests
run: |
cp .ddev/config_overrides/config.${{ env.PHP_VERSION_CODE }}.yaml .ddev/config.${{ env.PHP_VERSION_CODE }}.yaml
cp .ddev/additional_docker_compose/docker-compose.crowdsec.yaml .ddev/docker-compose.crowdsec.yaml
mkdir ${{ github.workspace }}/cfssl
cp -r .ddev/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
ddev start
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
- name: Start DDEV with PHP ${{ matrix.php-version }}
run: ddev start

- name: Some DEBUG information
run: |
Expand Down Expand Up @@ -106,4 +104,4 @@ jobs:
if: |
github.event.inputs.integration_tests == 'true' ||
github.event_name == 'push'
run: ddev exec AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration
run: ddev exec AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The [public API](https://semver.org/spec/v2.0.0.html#spec-item-1) of this library consists of all public or protected methods, properties and constants belonging to the `src` folder.

---

## [3.2.0](https://github.com/crowdsecurity/php-lapi-client/releases/tag/v3.1.0) - 2023-12-07
[_Compare with previous release_](https://github.com/crowdsecurity/php-lapi-client/compare/v3.1.0...v3.2.0)

### Added


- Add `api_connect_timeout` configuration


---

## [3.1.0](https://github.com/crowdsecurity/php-lapi-client/releases/tag/v3.1.0) - 2023-04-27
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"require": {
"php": "^7.2.5 || ^8.0",
"crowdsec/common": "^2.0.0",
"crowdsec/common": "^2.2.0",
"ext-json": "*",
"symfony/config": "^4.4.44 || ^5.4.11 || ^6.0.11",
"monolog/monolog": "^1.17 || ^2.1"
Expand Down
16 changes: 16 additions & 0 deletions docs/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ ddev php ./my-code/lapi-client/vendor/bin/phpunit ./my-code/lapi-client/tests/U

#### Integration test

First, create a bouncer and keep the result key.

```bash
ddev create-bouncer
```

Then, as we use a TLS ready CrowdSec container, you have to copy some certificates and key:

```bash
cd crowdsec-lapi-dev-project
mkdir cfssl
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* cfssl
```

Finally, run

In order to launch integration tests, we have to set some environment variables:

```bash
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Configuration extends AbstractConfiguration
'tls_ca_cert_path',
'tls_verify_peer',
'api_timeout',
'api_connect_timeout',
];

/**
Expand Down Expand Up @@ -108,6 +109,7 @@ private function addConnectionNodes($rootNode)
->end()
->booleanNode('tls_verify_peer')->defaultValue(false)->end()
->integerNode('api_timeout')->defaultValue(Constants::API_TIMEOUT)->end()
->integerNode('api_connect_timeout')->defaultValue(Constants::API_CONNECT_TIMEOUT)->end()
->end();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ class Constants extends CommonConstants
/**
* @var string The current version of this library
*/
public const VERSION = 'v3.1.0';
public const VERSION = 'v3.2.0';
}
1 change: 0 additions & 1 deletion tests/Integration/BouncerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ final class BouncerTest extends TestCase
*/
protected $watcherClient;


private function addTlsConfig(&$bouncerConfigs, $tlsPath)
{
$bouncerConfigs['tls_cert_path'] = $tlsPath . '/bouncer.pem';
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/WatcherClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ protected function getFinalScope($scope, $value)
{
$scope = (Constants::SCOPE_IP === $scope && 2 === count(explode('/', $value))) ? Constants::SCOPE_RANGE :
$scope;

/**
* Must use capital first letter as the crowdsec agent seems to query with first capital letter
* during getStreamDecisions.
Expand Down

0 comments on commit 5d6f6fc

Please sign in to comment.