Skip to content

Commit

Permalink
chore(upgrade): Monolog
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolland Csatari committed Jun 19, 2024
1 parent 4ab9a5e commit 2c094db
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ CHANGELOG
master
------

* todo...

v3.0.0
------

* Bump PHP version from ^8.0 to ^8.1 and configure CI with 8.1 and 8.2
* Bump Monolog version from ^1.24 || ~2.0 to ^3.6.0
* Bump symfony/(config|console|dependency-injection|form|http-kernel|options-resolver|translation|validator) from ^4.4 || ^5.3 || ^6.0 to ^5.4 || ^6.4 || ^7.0
* Adapt `Monolog/Processor/GdprProcessor` to the new `Monolog\Processor\ProcessorInterface`
* Improve `Monolog/Processor/GdprProcessor` type hinting
* Update `Tests/Monolog/Processor/GdprProcessorTest.php`
* Update `Command/EncryptCommand.php`

v2.0.0
------
Expand Down
5 changes: 0 additions & 5 deletions Command/EncryptCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#[AsCommand(name: 'ekino-data-protection:encrypt')]
final class EncryptCommand extends Command
{
/**
* {@inheritdoc}
*/
protected static $defaultName = 'ekino-data-protection:encrypt';

/**
* @var string
*/
Expand Down
24 changes: 5 additions & 19 deletions Monolog/Processor/GdprProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,25 @@
namespace Ekino\DataProtectionBundle\Monolog\Processor;

use Ekino\DataProtectionBundle\Encryptor\EncryptorInterface;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;

/**
* Pseudonymize sensitive data inside log contexts.
*
* @author Rémi Marseille <[email protected]>
* @author Benoit Mazière <[email protected]>
* @author Rolland Csatari <[email protected]>
*/
class GdprProcessor implements ProcessorInterface
{
/**
* @var EncryptorInterface
*/
private $encryptor;

/**
* GdprProcessor constructor.
*
* @param EncryptorInterface $encryptor
*/
public function __construct(EncryptorInterface $encryptor)
public function __construct(private EncryptorInterface $encryptor)
{
$this->encryptor = $encryptor;
}

/**
* @param array<array-key,array> $record
*
* @return array<array-key,array>
*/
public function __invoke(array $record)
public function __invoke(LogRecord $record): LogRecord
{
foreach ($record['context'] as $key => &$val) {
foreach ($record->context as $key => &$val) {
if (preg_match('#^private_#', (string) $key)) {
$encoded = json_encode($val);
if (false === $encoded) {
Expand Down
25 changes: 16 additions & 9 deletions Tests/Monolog/Processor/GdprProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

use Ekino\DataProtectionBundle\Encryptor\EncryptorInterface;
use Ekino\DataProtectionBundle\Monolog\Processor\GdprProcessor;
use Monolog\Level;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;

/**
* Class GdprProcessorTest.
*
* @author Rémi Marseille <[email protected]>
* @author Benoit Mazière <[email protected]>
* @author Rolland Csatari <[email protected]>
*/
class GdprProcessorTest extends TestCase
{
Expand All @@ -33,20 +36,24 @@ public function testProcessor(): void
$encryptor = $this->createMock(EncryptorInterface::class);
$encryptor->expects($this->once())->method('encrypt')->willReturn('encrypted_data');

$processor = new GdprProcessor($encryptor);

$this->assertSame(['context' => [
0 => 'numeric index',
'foo' => 'bar',
'private_data' => 'encrypted_data',
]], $processor->__invoke([
'context' => [
$record = new LogRecord(
new \DateTimeImmutable(),
'main',
Level::Debug,
'The log context includes private data.',
[
0 => 'numeric index',
'foo' => 'bar',
'private_data' => [
'foo' => 'baz',
],
],
]));
);

$this->assertSame([
0 => 'numeric index',
'foo' => 'bar',
'private_data' => 'encrypted_data',
], ((new GdprProcessor($encryptor))($record))->context);
}
}
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"php": "^8.1",
"ext-json": "*",
"ext-openssl": "*",
"monolog/monolog": "^1.24 || ~2.0",
"symfony/config": "^4.4 || ^5.3 || ^6.0",
"symfony/console": "^4.4 || ^5.3 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0",
"symfony/form": "^4.4 || ^5.3 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.3 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.3 || ^6.0",
"symfony/translation": "^4.4 || ^5.3 || ^6.0",
"symfony/validator": "^4.4 || ^5.3 || ^6.0"
"monolog/monolog": "^3.6.0",
"symfony/config": "^5.4 || ^6.4 || ^7.0",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
"symfony/form": "^5.4 || ^6.4 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0",
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
"symfony/translation": "^5.4 || ^6.4 || ^7.0",
"symfony/validator": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"dg/bypass-finals": "^1.4",
Expand Down

0 comments on commit 2c094db

Please sign in to comment.