better version of API login, and filtered api calls

This commit is contained in:
Oliver Gorwits
2019-03-20 16:38:17 +00:00
parent 9ef2407225
commit 7ee97d2637
4 changed files with 74 additions and 24 deletions

View File

@@ -1,14 +1,17 @@
package App::Netdisco::Util::Web;
use strict;
use warnings;
use Dancer ':syntax';
use base 'Exporter';
use Time::Piece;
use Time::Seconds;
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/
sort_port sort_modules interval_to_daterange sql_match
request_is_api
sort_port sort_modules
interval_to_daterange
sql_match
/;
our %EXPORT_TAGS = (all => \@EXPORT_OK);
@@ -25,6 +28,18 @@ subroutines.
=head1 EXPORT_OK
=head2 request_is_api
Whether the request should be interpreted as an API call.
=cut
sub request_is_api {
return (setting('api_token_lifetime')
and request->accept =~ m/(?:json|javascript)/
and index(request->path, uri_for('/api')->path) == 0);
}
=head2 sql_match( $value, $exact? )
Convert wildcard characters "C<*>" and "C<?>" to "C<%>" and "C<_>"