Passed
Pull Request — master (#53)
by
unknown
05:24
created

hideSensitiveRequestDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Providers;
4
5
use Laravel\Telescope\Telescope;
6
use Illuminate\Support\Facades\Gate;
7
use Laravel\Telescope\IncomingEntry;
8
use Laravel\Telescope\TelescopeApplicationServiceProvider;
9
10
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
11
{
12
    /**
13
     * Register any application services.
14
     *
15
     * @return void
16
     */
17
    public function register()
18
    {
19
        // Telescope::night();
20
21
        $this->hideSensitiveRequestDetails();
22
23
        Telescope::filter(function (IncomingEntry $entry) {
24
            if ($this->app->isLocal()) {
25
                return true;
26
            }
27
28
            return $entry->isReportableException() ||
29
                   $entry->isFailedJob() ||
30
                   $entry->isScheduledTask() ||
31
                   $entry->hasMonitoredTag();
32
        });
33
    }
34
35
    /**
36
     * Prevent sensitive request details from being logged by Telescope.
37
     *
38
     * @return void
39
     */
40
    protected function hideSensitiveRequestDetails()
41
    {
42
        if ($this->app->isLocal()) {
43
            return;
44
        }
45
46
        Telescope::hideRequestParameters(['_token']);
47
48
        Telescope::hideRequestHeaders([
49
            'cookie',
50
            'x-csrf-token',
51
            'x-xsrf-token',
52
        ]);
53
    }
54
55
    /**
56
     * Register the Telescope gate.
57
     *
58
     * This gate determines who can access Telescope in non-local environments.
59
     *
60
     * @return void
61
     */
62
    protected function gate()
63
    {
64
        Gate::define('viewTelescope', function ($user) {
65
            return in_array($user->email, [
66
                '[email protected]',
67
                '[email protected]',
68
                '[email protected]'
69
            ]);
70
        });
71
    }
72
}
73