-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from netlogix/feature/logging-rules
- Loading branch information
Showing
13 changed files
with
406 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Sentry\LoggingRule; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Throwable; | ||
|
||
class AllowListRule implements LoggingRule | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration(path="loggingRules.allowList") | ||
* @var array | ||
*/ | ||
protected $allowList = []; | ||
|
||
public function decide(Throwable $throwable, bool $previousDecision): bool | ||
{ | ||
foreach ($this->allowList as $allowedThrowableClassName) { | ||
if ($throwable instanceof $allowedThrowableClassName) { | ||
return true; | ||
} | ||
} | ||
|
||
return $previousDecision; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Sentry\LoggingRule; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Throwable; | ||
|
||
class DenyListRule implements LoggingRule | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration(path="loggingRules.denyList") | ||
* @var array | ||
*/ | ||
protected $denyList = []; | ||
|
||
public function decide(Throwable $throwable, bool $previousDecision): bool | ||
{ | ||
foreach ($this->denyList as $deniedThrowableClassName) { | ||
if ($throwable instanceof $deniedThrowableClassName) { | ||
return false; | ||
} | ||
} | ||
|
||
return $previousDecision; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Classes/LoggingRule/ExceptionHandlerRenderingGroupsRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Sentry\LoggingRule; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Netlogix\Sentry\ExceptionHandler\ExceptionRenderingOptionsResolver; | ||
use Throwable; | ||
|
||
class ExceptionHandlerRenderingGroupsRule implements LoggingRule | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var ExceptionRenderingOptionsResolver | ||
*/ | ||
protected $optionsResolver; | ||
|
||
public function decide(Throwable $throwable, bool $previousDecision): bool | ||
{ | ||
$options = $this->optionsResolver->resolveRenderingOptionsForThrowable($throwable); | ||
return $options['logException'] ?? $previousDecision; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Sentry\LoggingRule; | ||
|
||
use Throwable; | ||
|
||
interface LoggingRule | ||
{ | ||
public function decide(Throwable $throwable, bool $previousDecision): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Netlogix: | ||
Sentry: | ||
loggingRules: | ||
rules: | ||
'Netlogix\Sentry\LoggingRule\ExceptionHandlerRenderingGroupsRule': '10' | ||
'Netlogix\Sentry\LoggingRule\AllowListRule': '20' | ||
'Netlogix\Sentry\LoggingRule\DenyListRule': '30' | ||
|
||
allowList: [] | ||
|
||
denyList: | ||
- 'Neos\Flow\Security\Exception\InvalidHashException' | ||
- 'Neos\Flow\Security\Exception\InvalidArgumentForHashGenerationException' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Sentry\Tests\Unit\LoggingRule; | ||
|
||
use Neos\Flow\Tests\UnitTestCase; | ||
use Netlogix\Sentry\Exception\Test; | ||
use Netlogix\Sentry\LoggingRule\AllowListRule; | ||
|
||
class AllowListRuleTest extends UnitTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function if_allow_list_contains_class_decision_should_be_true(): void | ||
{ | ||
$allowListRule = $this->getAccessibleMock(AllowListRule::class, ['dummy']); | ||
$allowListRule->_set('allowList', [ | ||
Test::class | ||
]); | ||
|
||
self::assertEquals(true, $allowListRule->decide(new Test(), false)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function if_allow_list_not_contains_class_decision_should_be_equal_to_previous_decision(): void | ||
{ | ||
$allowListRule = $this->getAccessibleMock(AllowListRule::class, ['dummy']); | ||
$allowListRule->_set('allowList', []); | ||
|
||
$previousDecision = false; | ||
|
||
self::assertEquals($previousDecision, $allowListRule->decide(new Test(), $previousDecision)); | ||
} | ||
} |
Oops, something went wrong.