Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
13 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TelescopeServiceProvider | |
50.00% |
13 / 26 |
|
0.00% |
0 / 3 |
30.00 | |
0.00% |
0 / 1 |
| register | |
36.36% |
4 / 11 |
|
0.00% |
0 / 1 |
24.49 | |||
| hideSensitiveRequestDetails | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| gate | |
28.57% |
2 / 7 |
|
0.00% |
0 / 1 |
1.36 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Providers; |
| 4 | |
| 5 | use Illuminate\Http\Request; |
| 6 | use Illuminate\Support\Facades\App; |
| 7 | use Illuminate\Support\Facades\Gate; |
| 8 | use Illuminate\Support\Facades\Log; |
| 9 | use Laravel\Telescope\EntryType; |
| 10 | use Laravel\Telescope\IncomingEntry; |
| 11 | use Laravel\Telescope\Telescope; |
| 12 | use Laravel\Telescope\TelescopeApplicationServiceProvider; |
| 13 | |
| 14 | class TelescopeServiceProvider extends TelescopeApplicationServiceProvider |
| 15 | { |
| 16 | /** |
| 17 | * Register any application services. |
| 18 | */ |
| 19 | public function register(): void |
| 20 | { |
| 21 | // Telescope::night(); |
| 22 | |
| 23 | $this->hideSensitiveRequestDetails(); |
| 24 | |
| 25 | $isLocal = $this->app->environment('local') || $this->app->environment('staging'); |
| 26 | |
| 27 | Telescope::filter(function (IncomingEntry $entry) use ($isLocal) { |
| 28 | return $isLocal || |
| 29 | $entry->isReportableException() || |
| 30 | $entry->isFailedRequest() || |
| 31 | $entry->isFailedJob() || |
| 32 | $entry->isScheduledTask() || |
| 33 | $entry->hasMonitoredTag() || |
| 34 | $entry->type === EntryType::LOG; |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Prevent sensitive request details from being logged by Telescope. |
| 40 | */ |
| 41 | protected function hideSensitiveRequestDetails(): void |
| 42 | { |
| 43 | if ($this->app->environment('local') || $this->app->environment('staging')) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | Telescope::hideRequestParameters(['_token']); |
| 48 | |
| 49 | Telescope::hideRequestHeaders([ |
| 50 | 'cookie', |
| 51 | 'x-csrf-token', |
| 52 | 'x-xsrf-token', |
| 53 | ]); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Register the Telescope gate. |
| 58 | * |
| 59 | * This gate determines who can access Telescope in non-local environments. |
| 60 | */ |
| 61 | protected function gate(): void |
| 62 | { |
| 63 | Gate::define('viewTelescope', function ($user) { |
| 64 | return in_array($user->email, [ |
| 65 | 'jonatas.souza@vengreso.com', |
| 66 | 'mario@vengreso.com', |
| 67 | 'appdev@vengreso.com' |
| 68 | ]); |
| 69 | }); |
| 70 | } |
| 71 | } |