Last active
April 30, 2021 19:35
-
-
Save joelharkes/79d7fd89f752fd186be92001c018a06d to your computer and use it in GitHub Desktop.
Sqreen implementation for laravel, SQREEN_ID configurable in environment variable
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
# only start screen when SQREEN_ID environment variable is provided | |
if [[ -n "$SQREEN_ID" ]]; then | |
echo "Enabling screen" 1>&2 | |
sqreen-installer config "$SQREEN_ID" "VAIGO_API" | |
fi | |
# from php-fpm entrypoint: | |
# first arg is `-f` or `--some-option` | |
if [ "${1#-}" != "$1" ]; then | |
set -- php-fpm "$@" | |
fi | |
exec "$@" |
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
FROM php:7.2-fpm as base | |
RUN apt-get -qq update \ | |
&& curl -s https://8dc0b36f0ea6f2f21b721765e10a7e02768cd1825b4551f4:@packagecloud.io/install/repositories/sqreen/sqreen/script.deb.sh | bash \ | |
&& apt-get -qq install --no-install-recommends sqreen-agent sqreen-php-extension \ | |
&& apt-get -qq -o=Dpkg::Use-Pty=0 clean \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
COPY ./scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint | |
RUN chmod +x /usr/local/bin/docker-entrypoint | |
ENTRYPOINT ["docker-entrypoint"] | |
CMD ["php-fpm"] |
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
<?php | |
namespace App\Providers; | |
use Illuminate\Support\Facades\Event; | |
class EventServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any events for your application. | |
*/ | |
public function boot() | |
{ | |
// Add to config/auth.php: 'sqreen_id' => env('SQREEN_ID', ''), | |
if (config('auth.sqreen_id')) { | |
# only log when SQREEN_ID env variable is defined. | |
Event::listen(SqreenEvents::$listensTo, SqreenEvents::class); | |
} | |
} | |
} |
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
<?php | |
namespace App\Lib; | |
use Illuminate\Auth\Events\Authenticated; | |
use Illuminate\Auth\Events\Login; | |
/** | |
* Notifies Sqreen about user events. | |
*/ | |
class SqreenEvents | |
{ | |
public static $listensTo = [ | |
Login::class, Authenticated::class, | |
]; | |
/** | |
* @param $event Login|Authenticated | |
*/ | |
public function handle($event) | |
{ | |
if ($event instanceof Login) { | |
\sqreen\auth_track(true, ['id' => $event->user->getAuthIdentifier()]); | |
} | |
if ($event instanceof Authenticated) { | |
\sqreen\identify(['id' => $event->user->getAuthIdentifier()]); | |
} | |
// add Illuminate\Auth\Events\Registered if your app allows user registrations | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment