Skip to content

Commit

Permalink
Merge pull request #6 from MacPaw/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
serhiidonii authored Jun 7, 2024
2 parents 4c14008 + 5fa6f21 commit 4c43e63
Show file tree
Hide file tree
Showing 24 changed files with 663 additions and 54 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ jobs:
php:
- '8.3'
coverage: ['none']
doctrine-dbal-versions:
- '^3.0'
- '^4.0'
symfony-versions:
- '6.4.*'
- '7.0.*'
include:
- description: 'Log Code Coverage'
php: '8.3'
symfony-versions: '^7.0'
doctrine-dbal-versions: '^3.0'
coverage: xdebug
- description: 'Log Code Coverage'
php: '8.3'
symfony-versions: '^7.0'
doctrine-dbal-versions: '^4.0'
coverage: xdebug

name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }}
name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} Doctrine DBAL ${{ matrix.doctrine-dbal-versions }} ${{ matrix.description }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -49,13 +63,14 @@ jobs:
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer

- name: Update Symfony version
- name: Update package versions
if: matrix.symfony-versions != ''
run: |
composer require symfony/config:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/cache:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require doctrine/dbal:${{ matrix.doctrine-dbal-versions }} --no-update --no-scripts -W
composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require --dev symfony/phpunit-bridge:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require --dev symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts
Expand All @@ -64,7 +79,9 @@ jobs:
run: composer install

- name: Run PHPUnit tests
run: XDEBUG_MODE=coverage vendor/bin/phpunit
run: |
XDEBUG_MODE=off php tools/prepare-configs.php
XDEBUG_MODE=coverage vendor/bin/phpunit
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down
23 changes: 21 additions & 2 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,43 @@ jobs:
- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: Update configs
run: php tools/prepare-configs.php

- name: Run script
run: vendor/bin/phpcs

phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '8.3'
coverage: [ 'none' ]
doctrine-dbal-versions:
- '^3.0'
- '^4.0'

name: Static analyse with PHP ${{ matrix.php }} Doctrine DBAL ${{ matrix.doctrine-dbal-versions }} ${{ matrix.description }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2

- name: Update package versions
run: |
composer require doctrine/dbal:${{ matrix.doctrine-dbal-versions }} --no-update --no-scripts -W
- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: Run script
run: vendor/bin/phpstan analyse
run: |
php tools/prepare-configs.php;
vendor/bin/phpstan analyse
composer-validate:
name: Composer validate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/coverage
/tests/App/var
/var
/clover.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# doctrine-aws-iam-rds-auth-bundle
# Doctrine AWS IAM RDS Auth Bundle
Doctrine AWS IAM RDS Auth Bundle provides a Doctrine DBAL driver decorator that supports AWS IAM RDS authentication.

## Installation
Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
},
"require": {
"php": ">=8.3",
"doctrine/orm": "^2.17",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/config": "^6.4 || ^7.0",
"aws/aws-sdk-php": "^3.303",
"symfony/cache": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0"
"symfony/cache": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"doctrine/dbal": "^3.0 || ^4.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.9",
"phpunit/phpunit": "^11.1",
"symfony/phpunit-bridge": "^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0"
"symfony/phpunit-bridge": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0",
"nette/neon": "^3.4",
"symfony/property-access": "^6.4 || ^7.0"
},
"config": {
"allow-plugins": {
Expand Down
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
checkGenericClassInNonGenericObjectType: false
level: max
paths:
- src
level: max
paths:
- src
36 changes: 20 additions & 16 deletions src/Doctrine/Driver/IamDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface;

readonly class IamDecorator implements Driver
readonly class IamDecorator implements IamDecoratorInterface
{
public function __construct(
private Driver $subject,
Expand Down Expand Up @@ -46,7 +47,7 @@ public function connect(array $params): DriverConnection
"$host:$port",
$this->region,
$user,
true
true,
);

return $this->subject->connect($params);
Expand All @@ -56,29 +57,32 @@ public function connect(array $params): DriverConnection
}
}

public function getDatabasePlatform(): AbstractPlatform
private function isConnectionException(\Throwable $e): bool
{
return $this->subject->getDatabasePlatform();
}
if ($e instanceof DriverException) {
$driverException = $this->getExceptionConverter()->convert($e, null);

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
return $this->subject->getSchemaManager($conn, $platform);
return $driverException instanceof ConnectionException;
}

return false;
}

public function getExceptionConverter(): ExceptionConverter
{
return $this->subject->getExceptionConverter();
}

private function isConnectionException(\Throwable $e): bool
public function getDatabasePlatform(): AbstractPlatform
{
if ($e instanceof DriverException) {
$driverException = $this->getExceptionConverter()->convert($e, null);

return $driverException instanceof ConnectionException;
}
return $this->subject->getDatabasePlatform();
}

return false;
/**
* @return AbstractSchemaManager<PostgreSQLPlatform>
*/
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
{
return $this->subject->getSchemaManager($conn, $platform);
}
}
78 changes: 78 additions & 0 deletions src/Doctrine/Driver/IamDecoratorDoctrine40.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver;

use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\ServerVersionProvider;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface;

readonly class IamDecoratorDoctrine40 implements IamDecoratorInterface
{
public function __construct(
private Driver $subject,
private TokenProviderInterface $tokenProvider,
private string $region,
) {
}

public function connect(array $params): DriverConnection
{
// @phpstan-ignore-next-line
$host = $params['host'];
// @phpstan-ignore-next-line
$user = $params['user'];
// @phpstan-ignore-next-line
$port = $params['port'];

$params['password'] = $this->tokenProvider->getToken(
"$host:$port",
$this->region,
$user,
);

try {
return $this->subject->connect($params);
} catch (\Throwable $e) {
if ($this->isConnectionException($e)) {
$params['password'] = $this->tokenProvider->getToken(
"$host:$port",
$this->region,
$user,
true
);

return $this->subject->connect($params);
}

throw $e;
}
}

public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
{
return $this->subject->getDatabasePlatform($versionProvider);
}

public function getExceptionConverter(): ExceptionConverter
{
return $this->subject->getExceptionConverter();
}

private function isConnectionException(\Throwable $e): bool
{
if ($e instanceof DriverException) {
$driverException = $this->getExceptionConverter()->convert($e, null);

return $driverException instanceof ConnectionException;
}

return false;
}
}
11 changes: 11 additions & 0 deletions src/Doctrine/Driver/IamDecoratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver;

use Doctrine\DBAL\Driver;

interface IamDecoratorInterface extends Driver
{
}
16 changes: 14 additions & 2 deletions src/Doctrine/Driver/IamMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Doctrine\Driver;

use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Middleware;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface;

readonly class IamMiddleware implements Middleware
{
Expand All @@ -20,7 +20,19 @@ public function __construct(
public function wrap(Driver $driver): Driver
{
if ($this->useIam) {
return new IamDecorator($driver, $this->tokenProvider, $this->region);
if (interface_exists('Doctrine\DBAL\ServerVersionProvider')) {
return new IamDecoratorDoctrine40(
$driver,
$this->tokenProvider,
$this->region,
);
}

return new IamDecorator(
$driver,
$this->tokenProvider,
$this->region,
);
}

return $driver;
Expand Down
19 changes: 19 additions & 0 deletions tests/AbstractDoctrineTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests;

use PHPUnit\Framework\TestCase;

abstract class AbstractDoctrineTestCase extends TestCase
{
protected function isDoctrine40(): bool
{
if (!function_exists('interface_exists')) {
return class_exists('Doctrine\DBAL\ServerVersionProvider');
}

return interface_exists('Doctrine\DBAL\ServerVersionProvider');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection;
namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
3 changes: 2 additions & 1 deletion tests/App/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Macpaw\DoctrineAwsIamRdsAuthBundle\DependencyInjection\DoctrineAwsIamRdsAuthExtension;
use Macpaw\DoctrineAwsIamRdsAuthBundle\DoctrineAwsIamRdsAuthBundle;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection\PublicCompilerPass;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\DependencyInjection\PublicCompilerPass;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -30,6 +30,7 @@ protected function getContainerBuilder(): ContainerBuilder
{
$builder = parent::getContainerBuilder();
$builder->addCompilerPass(new PublicCompilerPass());
// $builder->registerExtension(new DoctrineAwsIamRdsAuthExtension());

return $builder;
}
Expand Down
1 change: 0 additions & 1 deletion tests/App/config/package/doctrine_aws_iam_rds.yaml

This file was deleted.

1 change: 0 additions & 1 deletion tests/App/config/package/framework.yaml

This file was deleted.

Loading

0 comments on commit 4c43e63

Please sign in to comment.