Skip to content

Commit

Permalink
Refactor butler-audit config
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrig committed Sep 30, 2021
1 parent 6713d6e commit 2be304e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Changed
- Refactor butler-audit config.
- Merge package and application "butler" config.

## [0.13.0] - 2021-09-28
Expand Down
4 changes: 0 additions & 4 deletions config/butler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

'driver' => env('BUTLER_AUDIT_DRIVER', 'log'),

'default_initiator_resolver' => false,

'extend_bus_dispatcher' => true,

],

'guru' => [
Expand Down
9 changes: 7 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function register()

$this->configureTimezone();

$this->configureAuditInitiator();
$this->configureAudit();

$this->configureHealth();

Expand Down Expand Up @@ -99,8 +99,13 @@ protected function configureTimezone()
date_default_timezone_set(config('app.timezone'));
}

protected function configureAuditInitiator()
protected function configureAudit()
{
if (! $this->app->configurationIsCached()) {
config(['butler.audit.default_initiator_resolver' => false]);
config(['butler.audit.extend_bus_dispatcher' => true]);
}

$resolver = $this->app->runningInConsole()
? fn () => ['console', ['hostname' => gethostname()]]
: function () {
Expand Down
12 changes: 9 additions & 3 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ public function test_can_override_timezone()
$this->assertEquals('Europe/Stockholm', Carbon::now()->getTimezone());
}

public function test_audit_initiator_resolver_resolves_console()
public function test_configureAudit_configures_audit()
{
$this->assertFalse(config('butler.audit.default_initiator_resolver'));
$this->assertTrue(config('butler.audit.extend_bus_dispatcher'));
}

public function test_configureAudit_sets_initiator_resolver_for_console()
{
Auditor::fake();

Expand All @@ -116,7 +122,7 @@ public function test_audit_initiator_resolver_resolves_console()
&& $data->hasInitiatorContext('hostname', gethostname()));
}

public function test_audit_initiator_resolver_resolves_authenticated_user()
public function test_configureAudit_sets_initiator_resolver_for_authenticated_user()
{
putenv('APP_RUNNING_IN_CONSOLE=false');

Expand All @@ -135,7 +141,7 @@ public function test_audit_initiator_resolver_resolves_authenticated_user()
&& $data->hasInitiatorContext('tokenName', 'my token'));
}

public function test_audit_initiator_resolver_resolves_unauthenticated_user()
public function test_configureAudit_sets_initiator_resolver_for_unauthenticated_user()
{
putenv('APP_RUNNING_IN_CONSOLE=false');

Expand Down

0 comments on commit 2be304e

Please sign in to comment.