Skip to content

Commit

Permalink
Merge pull request #3 from MacPaw/develop
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
serhiidonii authored May 29, 2024
2 parents 7d54272 + 751b591 commit 4c14008
Show file tree
Hide file tree
Showing 30 changed files with 884 additions and 26 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

on:
pull_request:
push:
branches: [ main, develop ]

jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '8.3'
coverage: ['none']
symfony-versions:
- '6.4.*'
- '7.0.*'

name: Test with PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }}
steps:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: ${{ matrix.php }}-${{ matrix.symfony-versions }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
extensions: xdebug

- name: Add PHPUnit matcher
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Set composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer
uses: actions/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
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
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 --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
- name: Install dependencies
run: composer install

- name: Run PHPUnit tests
run: XDEBUG_MODE=coverage vendor/bin/phpunit

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
pull_request:
push:
branches: [ main, develop ]

jobs:
security-checker:
name: Security checker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: Download local-php-security-checker
run: curl -s -L -o local-php-security-checker https://github.com/fabpot/local-php-security-checker/releases/download/v1.0.0/local-php-security-checker_1.0.0_linux_amd64

- name: Run local-php-security-checker
run: chmod +x local-php-security-checker && ./local-php-security-checker
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

/reports
/coverage
/tests/App/var
/var
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
"Macpaw\\DoctrineAwsIamRdsAuthBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Macpaw\\DoctrineAwsIamRdsAuthBundle\\Tests\\": "tests/"
}
},
"require": {
"php": ">=8.3",
"doctrine/orm": "^2.17",
"symfony/dependency-injection": "^6.4",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"aws/aws-sdk-php": "^3.303",
"symfony/cache": "^6.4",
"symfony/http-kernel": "^6.4"
"symfony/cache": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.9"
"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"
},
"config": {
"allow-plugins": {
Expand Down
7 changes: 7 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ services:
autoconfigure: true
public: false

Macpaw\DoctrineAwsIamRdsAuthBundle\Factory\AuthTokenGeneratorFactory: ~

rds.authTokenGenerator:
class: Aws\Rds\AuthTokenGenerator
factory: '@Macpaw\DoctrineAwsIamRdsAuthBundle\Factory\AuthTokenGeneratorFactory'

Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider:
arguments:
$lifetime: '%env(RDS_TOKEN_LIFETIME_MINUTES)%'
$generator: '@rds.authTokenGenerator'

Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProviderCacheDecorator:
decorates: Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider
Expand Down
50 changes: 50 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
cacheDirectory="var/cache/test/phpunit">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="APP_DEBUG" value="0" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="10"/>
<server name="RDS_TOKEN_LIFETIME_MINUTES" value="10"/>
<server name="RDS_TOKEN_CACHE_LIFETIME_SECONDS" value="3600"/>
<server name="APP_SECRET" value="someString!"/>
<server name="AWS_REGION" value="us-west-1"/>
<server name="USE_IAM" value="true"/>
<server name="KERNEL_CLASS" value="App\Kernel"/>
<!-- https://github.com/phpDocumentor/TypeResolver/issues/148#issuecomment-1005542099 -->
<server name="SYMFONY_PHPUNIT_REQUIRE" value="phpdocumentor/type-resolver:1.6"/>
</php>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="functional">
<directory>tests/Functional</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
<exclude>
</exclude>
</source>

<coverage cacheDirectory="/tmp/phpunit-cache"
includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
</phpunit>
14 changes: 8 additions & 6 deletions src/Aws/Token/RdsTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
use Aws\Credentials\CredentialProvider;
use Aws\Rds\AuthTokenGenerator;

class RdsTokenProvider implements TokenProviderInterface
final readonly class RdsTokenProvider implements TokenProviderInterface
{
private readonly int $lifetime;
private readonly AuthTokenGenerator $generator;
private int $lifetime;
private AuthTokenGenerator $generator;

public function __construct(int $lifetime)
{
public function __construct(
AuthTokenGenerator $generator,
int $lifetime,
) {
$this->lifetime = $lifetime;
$this->generator = new AuthTokenGenerator(CredentialProvider::defaultProvider());
$this->generator = $generator;
}

public function getToken(string $endpoint, string $region, string $username, bool $refresh = false): string
Expand Down
8 changes: 4 additions & 4 deletions src/Aws/Token/RdsTokenProviderCacheDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use Macpaw\DoctrineAwsIamRdsAuthBundle\Cache\CacheStorageInterface;

class RdsTokenProviderCacheDecorator implements TokenProviderInterface
final readonly class RdsTokenProviderCacheDecorator implements TokenProviderInterface
{
private const string CACHE_KEY_PREFIX = 'rds_token_';

public function __construct(
private readonly TokenProviderInterface $tokenProvider,
private readonly CacheStorageInterface $cacheStorage,
private readonly int $ttl
private TokenProviderInterface $tokenProvider,
private CacheStorageInterface $cacheStorage,
private int $ttl
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\Cache\Adapter\AdapterInterface;

class CacheStorage implements CacheStorageInterface
final readonly class CacheStorage implements CacheStorageInterface
{
public function __construct(private AdapterInterface $cacheAdapter)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/DoctrineAwsIamRdsAuthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class DoctrineAwsIamRdsAuthExtension extends Extension
final class DoctrineAwsIamRdsAuthExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Doctrine/Driver/IamDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\TokenProviderInterface;

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

Expand Down
8 changes: 4 additions & 4 deletions src/Doctrine/Driver/IamMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Middleware;

class IamMiddleware implements Middleware
readonly class IamMiddleware implements Middleware
{
public function __construct(
private readonly TokenProviderInterface $tokenProvider,
private readonly string $region,
private readonly bool $useIam,
private TokenProviderInterface $tokenProvider,
private string $region,
private bool $useIam,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/DoctrineAwsIamRdsAuthBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;

class DoctrineAwsIamRdsAuthBundle extends Bundle
final class DoctrineAwsIamRdsAuthBundle extends Bundle
{
}
18 changes: 18 additions & 0 deletions src/Factory/AuthTokenGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Factory;

use Aws\Credentials\CredentialProvider;
use Aws\Rds\AuthTokenGenerator;

final readonly class AuthTokenGeneratorFactory
{
public function __invoke(): AuthTokenGenerator
{
return new AuthTokenGenerator(
CredentialProvider::defaultProvider()
);
}
}
36 changes: 36 additions & 0 deletions tests/App/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App;

use Macpaw\DoctrineAwsIamRdsAuthBundle\DependencyInjection\DoctrineAwsIamRdsAuthExtension;
use Macpaw\DoctrineAwsIamRdsAuthBundle\DoctrineAwsIamRdsAuthBundle;
use Macpaw\DoctrineAwsIamRdsAuthBundle\Tests\App\dependencyInjection\PublicCompilerPass;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

final class Kernel extends BaseKernel
{
use MicroKernelTrait;

protected function build(ContainerBuilder $container): void
{
parent::build($container);
}

public function getProjectDir(): string
{
return __DIR__;
}

protected function getContainerBuilder(): ContainerBuilder
{
$builder = parent::getContainerBuilder();
$builder->addCompilerPass(new PublicCompilerPass());

return $builder;
}
}
11 changes: 11 additions & 0 deletions tests/App/config/bundles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Macpaw\DoctrineAwsIamRdsAuthBundle\DoctrineAwsIamRdsAuthBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return [
FrameworkBundle::class => ['all' => true],
DoctrineAwsIamRdsAuthBundle::class => ['all' => true],
];
4 changes: 4 additions & 0 deletions tests/App/config/package/cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
cache:
app: cache.adapter.filesystem
system: cache.adapter.filesystem
1 change: 1 addition & 0 deletions tests/App/config/package/doctrine_aws_iam_rds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doctrine_aws_iam_rds:
1 change: 1 addition & 0 deletions tests/App/config/package/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
framework:
7 changes: 7 additions & 0 deletions tests/App/config/package/test/doctrine_aws_iam_rds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
doctrine_aws_iam_rds:

services:
Macpaw\DoctrineAwsIamRdsAuthBundle\Aws\Token\RdsTokenProvider:
public: true
arguments:
[ '@rds.authTokenGenerator', '@?' ]
2 changes: 2 additions & 0 deletions tests/App/config/package/test/framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
test: true
Loading

0 comments on commit 4c14008

Please sign in to comment.