blib/lib/Lemonldap/NG/Portal/Plugins/WebCron.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 51 CC 4 SCAR 22.2
CC
4
Cov
0%
_do
20.0
init
2.0
purge
2.0
CRAP 9.2
1 package Lemonldap::NG::Portal::Plugins::WebCron;
2  
3 use strict;
4 use Mouse;
5 use Lemonldap::NG::Common::Session::Purge;
6  
7 our $VERSION = '2.22.0';
8  
9 extends 'Lemonldap::NG::Portal::Main::Plugin';
10  
11 sub init {
12 my ($self) = @_;
13  
14 # Useless for now, webCronSecret is required by ::Portal::Main::Plugins
15 # to enable this plugin
16  
17 #unless ( $self->conf->{webCronSecret} ) {
18 # $self->logger->warn(
19 # 'No secret for webconf, be sure that API is protected by webserver'
20 # );
21 #}
22 $self->addUnauthRoute(
23 webcron => {
24 localpurge => 'localPurge',
25 purge => 'purge'
26 },
27 [ 'GET', 'POST' ]
28 );
29 return 1;
30 }
31  
32 sub purge {
33 my ( $self, $req ) = @_;
34 return $self->_do( $req, 'purge' );
35 }
36  
37 sub localPurge {
38 my ( $self, $req ) = @_;
39 return $self->_do( $req, 'localPurge' );
40 }
41  
42 sub _do {
43 my ( $self, $req, $sub ) = @_;
44 return $self->p->sendError( $req, 'Bad secret' )
45 if $self->conf->{webCronSecret}
46 and $req->param('secret') ne $self->conf->{webCronSecret};
47 my $r = eval {
48 Lemonldap::NG::Common::Session::Purge->new( {
49 conf => $self->conf,
50 logger => $self->logger,
51 }
52 );
53 };
54 if ($@) {
55 $self->logger("Unable to clean session: $@");
56 $r = 0;
57 }
58 else {
59 $r = $r->$sub;
60 }
61 return $r
62 ? $self->p->sendJSONresponse( $req, { result => 1, err => 0 } )
63 : $self->p->sendError( $req, 'Error while purging sessions, check logs' );
64 }
65  
66 1;