Beam-Runner
view release on metacpan or search on metacpan
lib/Beam/Runnable/AllowUsers.pm view on Meta::CPAN
#pod This role checks to ensure that only certain users can run a command. If
#pod an unauthorized user runs the command, it dies with an error instead.
#pod
#pod B<NOTE:> This is mostly a demonstration of a L<Beam::Runnable> role.
#pod Users that can write to the configuration file can edit who is allowed
#pod to run the command, and there are other ways to prevent access to
#pod a file/command.
#pod
#pod =head1 SEE ALSO
#pod
#pod L<Beam::Runnable>, L<perlfunc/getpwuid>, L<< perlvar/$> >>
#pod
#pod =cut
use strict;
use warnings;
use Moo::Role;
use List::Util qw( any );
use Types::Standard qw( ArrayRef Str );
#pod =attr allow_users
lib/Beam/Runnable/AllowUsers.pm view on Meta::CPAN
#pod =method run
#pod
#pod This role wraps the C<run> method of your runnable class to check that
#pod the user is authorized.
#pod
#pod =cut
before run => sub {
my ( $self, @args ) = @_;
my $user = getpwuid( $> );
die "Unauthorized user: $user\n"
unless any { $_ eq $user } @{ $self->allow_users };
};
1;
__END__
=pod
lib/Beam/Runnable/AllowUsers.pm view on Meta::CPAN
=head1 METHODS
=head2 run
This role wraps the C<run> method of your runnable class to check that
the user is authorized.
=head1 SEE ALSO
L<Beam::Runnable>, L<perlfunc/getpwuid>, L<< perlvar/$> >>
=head1 AUTHOR
Doug Bell <preaction@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Doug Bell.
This is free software; you can redistribute it and/or modify it under
lib/Beam/Runnable/DenyUsers.pm view on Meta::CPAN
#pod This role checks to ensure that certain users don't run a command. If an
#pod unauthorized user runs the command, it dies with an error instead.
#pod
#pod B<NOTE:> This is mostly a demonstration of a L<Beam::Runnable> role.
#pod Users that can write to the configuration file can edit who is denied
#pod to run the command, and there are other ways to prevent access to
#pod a file/command.
#pod
#pod =head1 SEE ALSO
#pod
#pod L<Beam::Runnable>, L<perlfunc/getpwuid>, L<< perlvar/$> >>
#pod
#pod =cut
use strict;
use warnings;
use Moo::Role;
use List::Util qw( any );
use Types::Standard qw( ArrayRef Str );
#pod =attr deny_users
lib/Beam/Runnable/DenyUsers.pm view on Meta::CPAN
#pod =method run
#pod
#pod This role wraps the C<run> method of your runnable class to check that
#pod the user isn't unauthorized.
#pod
#pod =cut
before run => sub {
my ( $self, @args ) = @_;
my $user = getpwuid( $> );
die "Unauthorized user: $user\n"
if any { $_ eq $user } @{ $self->deny_users };
};
1;
__END__
=pod
lib/Beam/Runnable/DenyUsers.pm view on Meta::CPAN
=head1 METHODS
=head2 run
This role wraps the C<run> method of your runnable class to check that
the user isn't unauthorized.
=head1 SEE ALSO
L<Beam::Runnable>, L<perlfunc/getpwuid>, L<< perlvar/$> >>
=head1 AUTHOR
Doug Bell <preaction@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by Doug Bell.
This is free software; you can redistribute it and/or modify it under
t/allow_users.t view on Meta::CPAN
L<Beam::Runnable::AllowUsers>
=cut
use strict;
use warnings;
use Test::More;
use Test::Fatal;
my $USER = getpwuid( $> );
{ package
t::AllowUsers;
use Moo;
with 'Beam::Runnable', 'Beam::Runnable::AllowUsers';
sub run { $t::AllowUsers::RAN++ }
}
subtest 'authorization failure' => sub {
my $foo = t::AllowUsers->new(
allow_users => [ ],
t/deny_users.t view on Meta::CPAN
L<Beam::Runnable::DenyUsers>
=cut
use strict;
use warnings;
use Test::More;
use Test::Fatal;
my $USER = getpwuid( $> );
{ package
t::DenyUsers;
use Moo;
with 'Beam::Runnable', 'Beam::Runnable::DenyUsers';
sub run { $t::DenyUsers::RAN++ }
}
subtest 'authorization success' => sub {
local $t::DenyUsers::RAN = 0;
my $foo = t::DenyUsers->new(
( run in 0.315 second using v1.01-cache-2.11-cpan-8d75d55dd25 )