Alien-Build-Plugin-Fetch-HostBlockList
view release on metacpan or search on metacpan
DESCRIPTION
This is an Alien::Build plugin that will, when enabled, reject any
fetch requests made by an Alien::Build based Alien that are fetching
from a remote host that is on the block list.
Aliens that bundle packages are not affected, as this plugin does not
check file URLs.
If now block list is specified (either via the property or environment
variable, see below), then not hosts will be blocked.
PROPERTIES
block_hosts
plugin 'Fetch::HostBlockList', block_list => \@hosts;
The list of domains that will be blocked. Should be provided as an
array reference. If not provided, then ALIEN_BUILD_HOST_BLOCK will be
used (see below).
ENVIRONMENT
ALIEN_BUILD_HOST_BLOCK
Comma separated list of hosts to block. If not specified when the
plugin is applied then this list will be used.
lib/Alien/Build/Plugin/Fetch/HostBlockList.pm view on Meta::CPAN
has '+block_hosts' => sub { [
defined $ENV{ALIEN_BUILD_HOST_BLOCK}
? split /,/, $ENV{ALIEN_BUILD_HOST_BLOCK}
: ()
] };
sub init
{
my($self, $meta) = @_;
my %blocked = map { $_ => 1 } @{ $self->block_hosts };
$meta->around_hook( fetch => sub {
my $orig = shift;
my $build = shift;
my $url = $_[0] || $build->meta_prop->{start_url};
if($url =~ /:/)
{
my $url = URI->new($url);
if($url->scheme ne 'file')
{
my $host = eval { $url->host };
die "unable to determine host from $url: $@" if $@;
die "The host $host is in the block list" if $blocked{$host};
}
}
$orig->($build, @_);
});
}
1;
lib/Alien/Build/Plugin/Fetch/HostBlockList.pm view on Meta::CPAN
=head1 DESCRIPTION
This is an L<Alien::Build> plugin that will, when enabled, reject any fetch requests
made by an L<Alien::Build> based L<Alien> that are fetching from a remote host that
is on the block list.
L<Alien>s that bundle packages are not affected, as this plugin does not check
C<file> URLs.
If now block list is specified (either via the property or environment variable,
see below), then not hosts will be blocked.
=head1 PROPERTIES
=head2 block_hosts
plugin 'Fetch::HostBlockList', block_list => \@hosts;
The list of domains that will be blocked. Should be provided as an array reference.
If not provided, then C<ALIEN_BUILD_HOST_BLOCK> will be used (see below).
=head1 ENVIRONMENT
=over 4
=item C<ALIEN_BUILD_HOST_BLOCK>
Comma separated list of hosts to block. If not specified when the
plugin is applied then this list will be used.
t/alien_build_plugin_fetch_hostblocklist.t view on Meta::CPAN
alienfile_skip_if_missing_prereqs;
alien_install_type_is 'share';
is dies {
$build->fetch;
}, match qr/^The host foo.com is in the block list/, 'fails with start url';
try_ok {
$build->fetch("https://google.com");
} 'works with non-blocked host';
is dies {
$build->fetch('https://bar.com/foo.txt');
}, match qr/^The host bar.com is in the block list/, 'fails with explicitly blocked URL';
};
done_testing;
( run in 0.924 second using v1.01-cache-2.11-cpan-39bf76dae61 )